-
-
Notifications
You must be signed in to change notification settings - Fork 98
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
171 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/** @jsx jsx */ | ||
/** @jsxImportSource hono/jsx */ | ||
/** @jsxFrag */ | ||
|
||
import { Button, Farc, TextInput } from 'farc' | ||
|
||
type State = { | ||
index: number | ||
todos: { completed: boolean; name: string }[] | ||
} | ||
|
||
export const app = new Farc<State>({ | ||
initialState: { | ||
index: -1, | ||
todos: [], | ||
}, | ||
}) | ||
|
||
app.frame('/', ({ buttonValue, inputText, deriveState }) => { | ||
const { index, todos } = deriveState((state) => { | ||
if (inputText) state.todos.push({ completed: false, name: inputText }) | ||
if (buttonValue === 'up') state.index = Math.max(0, state.index - 1) | ||
if (buttonValue === 'down') | ||
state.index = Math.min(state.todos.length - 1, state.index + 1) | ||
if (buttonValue === 'completed') | ||
state.todos[state.index].completed = !state.todos[state.index].completed | ||
}) | ||
|
||
return { | ||
image: ( | ||
<div | ||
style={{ | ||
backgroundColor: 'black', | ||
display: 'flex', | ||
flexDirection: 'column', | ||
padding: 40, | ||
width: '100%', | ||
height: '100%', | ||
}} | ||
> | ||
<div style={{ color: 'white', fontSize: 60 }}>TODO List</div> | ||
{todos.map((todo, i) => ( | ||
<div | ||
style={{ | ||
color: 'white', | ||
display: 'flex', | ||
fontSize: 40, | ||
marginTop: 20, | ||
textDecoration: 'none', | ||
}} | ||
> | ||
{todo.completed ? '✅' : '◻️'} {todo.name} {i === index ? '👈' : ''} | ||
</div> | ||
))} | ||
</div> | ||
), | ||
intents: [ | ||
<TextInput placeholder="Enter a TODO..." />, | ||
<Button>Add</Button>, | ||
<Button value="down">⬇️</Button>, | ||
<Button value="up">⬆️</Button>, | ||
<Button value="completed">{todos[index]?.completed ? '◻️' : '✅'}</Button>, | ||
], | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import type { Context } from 'hono' | ||
import type { FrameContext } from '../types.js' | ||
|
||
type RequestToContextReturnType = Pick< | ||
FrameContext, | ||
'status' | 'trustedData' | 'untrustedData' | 'url' | ||
> | ||
|
||
export async function requestToContext( | ||
request: Context['req'], | ||
): Promise<RequestToContextReturnType> { | ||
const { trustedData, untrustedData } = | ||
(await request.json().catch(() => {})) || {} | ||
|
||
return { | ||
status: request.method === 'POST' ? 'response' : 'initial', | ||
trustedData, | ||
untrustedData, | ||
url: request.url, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters