Skip to content

update return type of generation endpoint and start rendering in iframe #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/api/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export async function POST(request: NextRequest) {
const validatedFiles = benchifyFileSchema.parse(generatedFiles);

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

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

Expand All @@ -39,7 +39,7 @@ export async function POST(request: NextRequest) {
return NextResponse.json({
originalFiles: generatedFiles,
repairedFiles: repairedFiles,
// buildOutput: '', // We don't get build output from Benchify in our current setup
buildOutput: buildOutput,
previewUrl: url,
});
} catch (error) {
Expand Down
27 changes: 21 additions & 6 deletions app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@
import { useEffect, useState } from 'react';
import { PromptForm } from '@/components/ui-builder/prompt-form';
import { Card, CardContent } from '@/components/ui/card';
import { benchifyFileSchema } from '@/lib/schemas';
import { z } from 'zod';

export default function Home() {
const [result, setResult] = useState<any>(null);
const [result, setResult] = useState<{
repairedFiles: z.infer<typeof benchifyFileSchema>;
buildOutput: string;
previewUrl: string;
} | null>(null);

useEffect(() => {
if (result) {
Expand All @@ -22,11 +29,19 @@ export default function Home() {
<p className="text-lg text-muted-foreground mb-8 text-center">
Generate UI components with AI and automatically repair issues with Benchify
</p>
<Card className="border-border bg-card">
<CardContent className="pt-6">
<PromptForm onGenerate={setResult} />
</CardContent>
</Card>
{!result ? (
<Card className="border-border bg-card">
<CardContent className="pt-6">
<PromptForm onGenerate={setResult} />
</CardContent>
</Card>
) : (
<Card className="border-border bg-card">
<CardContent className="pt-6">
<iframe title="Preview" src={result.previewUrl} className="w-full h-full" />
</CardContent>
</Card>
)}
</div>
</main>
);
Expand Down