diff --git a/src/index.tsx b/src/index.tsx index 2db2b0fd..730a6fb6 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -32,66 +32,38 @@ type FrameReturnType = { intents: JSX.Element } -const previewRenderer = jsxRenderer( - ({ children }) => { - return ( - - - 𝑭𝒂𝒓𝒄 Preview - - - {children} - - ) - }, - { docType: true }, -) - -const frameRenderer = jsxRenderer( - ({ context, intents }) => { - const serializedContext = encodeURIComponent(JSON.stringify(context)) - return ( - - - - - - - {parseIntents(intents)} - - - ) - }, - { docType: true }, -) - export class Framework extends Hono { frame( path: string, handler: (c: FrameContext) => FrameReturnType | Promise, ) { - // Frame Routes - this.use(frameRenderer) - .get(async (c) => { - const context = await getFrameContext(c) - const { intents } = await handler(context) - return c.render(null, { context, intents }) - }) - .post(async (c) => { - const context = await getFrameContext(c) - const { intents } = await handler(context) - return c.render(null, { context, intents }) - }) + // Frame Route (implements GET & POST). + this.use(async (c) => { + const context = await getFrameContext(c) + const { intents } = await handler(context) + const serializedContext = encodeURIComponent(JSON.stringify(context)) + return c.render( + + + + + + + {parseIntents(intents)} + + , + ) + }) // OG Image Route this.get('image', async (c) => { @@ -104,7 +76,23 @@ export class Framework extends Hono { }) // Frame Preview Routes - this.use('preview', previewRenderer) + this.use( + 'preview', + jsxRenderer( + ({ children }) => { + return ( + + + 𝑭𝒂𝒓𝒄 Preview + + + {children} + + ) + }, + { docType: true }, + ), + ) .get(async (c) => { const baseUrl = c.req.url.replace('/preview', '') const response = await fetch(baseUrl)