Skip to content

Commit

Permalink
feat(preview): tools
Browse files Browse the repository at this point in the history
  • Loading branch information
tmm committed Feb 8, 2024
1 parent 88deef0 commit 6091676
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
Binary file modified bun.lockb
Binary file not shown.
47 changes: 34 additions & 13 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,7 @@ export class Framework extends Hono {
const response = await fetch(baseUrl)
const text = await response.text()
const frame = htmlToFrame(text)
return c.render(
<>
<FramePreview baseUrl={baseUrl} frame={frame} />
</>,
)
return c.render(<Content baseUrl={baseUrl} frame={frame} />)
})
.post(async (c) => {
const baseUrl = c.req.url.replace('/preview', '')
Expand Down Expand Up @@ -217,11 +213,7 @@ export class Framework extends Hono {
// TODO: handle redirects
const frame = htmlToFrame(text)

return c.render(
<>
<FramePreview baseUrl={baseUrl} frame={frame} />
</>,
)
return c.render(<Content baseUrl={baseUrl} frame={frame} />)
})

// TODO: fix this – does it work?
Expand Down Expand Up @@ -254,20 +246,33 @@ export function TextInput({ placeholder }: TextInputProps) {
return <meta property="fc:frame:input:text" content={placeholder} />
}

type FramePreviewProps = {
type ContentProps = {
baseUrl: string
frame: Frame
}

function FramePreview({ baseUrl, frame }: FramePreviewProps) {
function Content({ baseUrl, frame }: ContentProps) {
return (
<div style={{ display: 'flex', flexDirection: 'column', gap: '1rem' }}>
<Preview baseUrl={baseUrl} frame={frame} />
<Devtools frame={frame} />
</div>
)
}

type PreviewProps = {
baseUrl: string
frame: Frame
}

function Preview({ baseUrl, frame }: PreviewProps) {
return (
<div style={{ maxWidth: '512px', width: '100%' }}>
<form
action="/preview"
method="post"
style={{
borderRadius: '0.5rem',
display: 'flex-column',
position: 'relative',
width: '100%',
}}
Expand Down Expand Up @@ -356,6 +361,22 @@ function FramePreview({ baseUrl, frame }: FramePreviewProps) {
)
}

type DevtoolsProps = {
frame: Frame
}

async function Devtools({ frame }: DevtoolsProps) {
return (
<div>
<pre style={{ fontFamily: 'monospace' }}>
{frame.debug?.htmlTags.map((x) => (
<code style={{ display: 'grid' }}>{x}</code>
))}
</pre>
</div>
)
}

////////////////////////////////////////////////////////////////////////
// Utilities
////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 6091676

Please sign in to comment.