'use client' import { Button } from '@/components/ui/button' import { Form } from './form' import { useState } from 'react' const STEPS = { INITIAL: 'INITIAL', LOADING: 'LOADING', PREVIEW: 'PREVIEW', ERROR: 'ERROR', } export default function Home() { const [result, setResult] = useState('') const [step, setStep] = useState(STEPS.INITIAL) const transformUrlToCode = async (url: string) => { setStep(STEPS.LOADING) const res = await fetch('/api/generate-code-from-image', { method: 'POST', body: JSON.stringify({ url }), headers: { 'Content-Type': 'application/json', }, }) if (!res.ok || res.body === null) { throw new Error('Error al generar el código') setStep(STEPS.ERROR) } setStep(STEPS.PREVIEW) const reader = res.body.getReader() const decoder = new TextDecoder('utf-8') while (true) { const { done, value } = await reader.read() const chunk = decoder.decode(value) setResult((prevResult) => prevResult + chunk) console.log(chunk) if (done) break } } return (
{step == STEPS.INITIAL && (
)} {step == STEPS.LOADING && (

Generando código...

)} {step == STEPS.PREVIEW && (