diff --git a/src/app/page.tsx b/src/app/page.tsx index 92c3eab..61cc1ff 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -12,6 +12,32 @@ export default function ClipToolPage() { const [captions, setCaptions] = useState(true); const [layout, setLayout] = useState("vertical"); const [timeframe, setTimeframe] = useState("30s"); + const [loading, setLoading] = useState(false); + const [error, setError] = useState(""); + const [clips, setClips] = useState([]); + + const handleGenerate = async () => { + if (!videoUrl) { + setError("Please enter a valid YouTube URL."); + return; + } + setLoading(true); + setError(""); + try { + const response = await fetch('/api/generate-clips', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ videoUrl, captions, layout, timeframe }) + }); + const data = await response.json(); + if (data.error) throw new Error(data.error); + setClips(data.clips || []); + } catch (err: any) { + setError(err.message || "Something went wrong. Please try again."); + } finally { + setLoading(false); + } + }; return ( alert(`Generating ${timeframe} ${layout} clips for: ${videoUrl} (Captions: ${captions ? "On" : "Off"})`)} + text={loading ? "Processing..." : "Generate Clips Now"} + onClick={handleGenerate} + disabled={loading} className="w-full" /> + + {error &&

{error}

} + + {clips.length > 0 && ( +
+

Generated Clips

+ {clips.map((clip, i) => ( +
+ )}