"use client" import React, { useEffect, useRef, useState, useTransition } from 'react' import { ClapProject } from '@aitube/clap' import { Card, CardContent, CardHeader } from '@/components/ui/card' import { Button } from '@/components/ui/button' import { Toaster } from '@/components/ui/sonner' import { cn } from '@/lib/utils/cn' import { useStore } from './store' import { TextareaField } from '@/components/form/textarea-field' import { DeviceFrameset } from 'react-device-frameset' import 'react-device-frameset/styles/marvel-devices.min.css' import { generateClap } from './server/aitube/generateClap' import { extendClap } from './server/aitube/extendClap' import { exportClap } from './server/aitube/exportClap' export function Main() { const [_isPending, startTransition] = useTransition() const storyPromptDraft = useStore(s => s.storyPromptDraft) const storyPrompt = useStore(s => s.storyPrompt) const status = useStore(s => s.status) const storyGenerationStatus = useStore(s => s.storyGenerationStatus) const voiceGenerationStatus = useStore(s => s.voiceGenerationStatus) const imageGenerationStatus = useStore(s => s.imageGenerationStatus) const videoGenerationStatus = useStore(s => s.videoGenerationStatus) const setStoryPromptDraft = useStore(s => s.setStoryPromptDraft) const setStoryPrompt = useStore(s => s.setStoryPrompt) const setStatus = useStore(s => s.setStatus) const setStoryGenerationStatus = useStore(s => s.setStoryGenerationStatus) const setVoiceGenerationStatus = useStore(s => s.setVoiceGenerationStatus) const setImageGenerationStatus = useStore(s => s.setImageGenerationStatus) const setVideoGenerationStatus = useStore(s => s.setVideoGenerationStatus) const hasPendingTasks = storyGenerationStatus === "generating" && voiceGenerationStatus === "generating" && imageGenerationStatus === "generating" && videoGenerationStatus === "generating" const isBusy = status === "generating" || hasPendingTasks const handleSubmit = async () => { const prompt = storyPromptDraft setStatus("generating") setStoryGenerationStatus("generating") setStoryPrompt(prompt) startTransition(async () => { console.log(`handleSubmit(): generating a clap using prompt = "${prompt}" `) let clap: ClapProject | undefined = undefined try { clap = await generateClap({ prompt }) console.log(`handleSubmit(): received a clap = `, clap) setStoryGenerationStatus("finished") } catch (err) { setStoryGenerationStatus("error") setStatus("error") return } if (!clap) { return } try { setImageGenerationStatus("generating") clap = await extendClap({ clap }) console.log(`handleSubmit(): received a clap with images = `, clap) setImageGenerationStatus("finished") } catch (err) { setImageGenerationStatus("error") setStatus("error") return } if (!clap) { return } let assetUrl = "" try { setVideoGenerationStatus("generating") assetUrl = await exportClap({ clap }) console.log(`handleSubmit(): received a video:`, assetUrl) setVideoGenerationStatus("finished") } catch (err) { setVideoGenerationStatus("error") setStatus("error") return } if (!assetUrl) { return } setStatus("finished") }) } return (
Generate video stories using AI ✨