Skip to content

Commit

Permalink
feat: add status to context
Browse files Browse the repository at this point in the history
  • Loading branch information
jxom committed Feb 8, 2024
1 parent 54676a9 commit 9383408
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
7 changes: 2 additions & 5 deletions example/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ import { Button, Framework } from 'farc'

const app = new Framework()

app.frame('/', ({ untrustedData = {} }) => {
const { buttonIndex } = untrustedData
app.frame('/', ({ status }) => {
return {
image: (
<div
Expand Down Expand Up @@ -36,9 +35,7 @@ app.frame('/', ({ untrustedData = {} }) => {
whiteSpace: 'pre-wrap',
}}
>
{typeof buttonIndex === 'number'
? `Button Index: ${buttonIndex}`
: 'Welcome!'}
{status === 'response' ? 'Nice choice.' : 'Welcome!'}
</div>
</div>
),
Expand Down
13 changes: 12 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ import {
} from './types.js'

type FrameContext = {
/**
* Status of the frame in the frame lifecycle.
* - `initial` - The frame has not yet been interacted with.
* - `response` - The frame has been interacted with (user presses button).
*/
status: 'initial' | 'response'
trustedData?: TrustedData
untrustedData?: UntrustedData
url: Context['req']['url']
Expand Down Expand Up @@ -348,7 +354,12 @@ async function getFrameContext(ctx: Context): Promise<FrameContext> {
const { req } = ctx
const { trustedData, untrustedData } =
(await req.json().catch(() => {})) || {}
return { trustedData, untrustedData, url: req.url }
return {
status: req.method === 'POST' ? 'response' : 'initial',
trustedData,
untrustedData,
url: req.url,
}
}

function parseIntents(intents_: JSX.Element) {
Expand Down

0 comments on commit 9383408

Please sign in to comment.