Skip to content

Commit 14d40a1

Browse files
benchifyjuancastano
authored andcommitted
update return type of generation endpoint and start rendering in iframe
1 parent 0a850d5 commit 14d40a1

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

app/api/generate/route.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export async function POST(request: NextRequest) {
2929
const validatedFiles = benchifyFileSchema.parse(generatedFiles);
3030

3131
// // Repair the generated code using Benchify's API
32-
const repairedFiles = await repairCode(validatedFiles);
32+
const { repairedFiles, buildOutput } = await repairCode(validatedFiles);
3333

3434
const { sbxId, template, url } = await createSandbox({ files: generatedFiles });
3535

@@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
3939
return NextResponse.json({
4040
originalFiles: generatedFiles,
4141
repairedFiles: repairedFiles,
42-
// buildOutput: '', // We don't get build output from Benchify in our current setup
42+
buildOutput: buildOutput,
4343
previewUrl: url,
4444
});
4545
} catch (error) {

app/page.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,15 @@
44
import { useEffect, useState } from 'react';
55
import { PromptForm } from '@/components/ui-builder/prompt-form';
66
import { Card, CardContent } from '@/components/ui/card';
7+
import { benchifyFileSchema } from '@/lib/schemas';
8+
import { z } from 'zod';
9+
710
export default function Home() {
8-
const [result, setResult] = useState<any>(null);
11+
const [result, setResult] = useState<{
12+
repairedFiles: z.infer<typeof benchifyFileSchema>;
13+
buildOutput: string;
14+
previewUrl: string;
15+
} | null>(null);
916

1017
useEffect(() => {
1118
if (result) {
@@ -22,11 +29,19 @@ export default function Home() {
2229
<p className="text-lg text-muted-foreground mb-8 text-center">
2330
Generate UI components with AI and automatically repair issues with Benchify
2431
</p>
25-
<Card className="border-border bg-card">
26-
<CardContent className="pt-6">
27-
<PromptForm onGenerate={setResult} />
28-
</CardContent>
29-
</Card>
32+
{!result ? (
33+
<Card className="border-border bg-card">
34+
<CardContent className="pt-6">
35+
<PromptForm onGenerate={setResult} />
36+
</CardContent>
37+
</Card>
38+
) : (
39+
<Card className="border-border bg-card">
40+
<CardContent className="pt-6">
41+
<iframe title="Preview" src={result.previewUrl} className="w-full h-full" />
42+
</CardContent>
43+
</Card>
44+
)}
3045
</div>
3146
</main>
3247
);

0 commit comments

Comments
 (0)