"use client" import { useEffect, useState, useTransition } from "react" import { cn } from "@/lib/utils" import { TopMenu } from "./interface/top-menu" import { fonts } from "@/lib/fonts" import { getRandomLayoutName } from "./layouts" import { useStore } from "./store" import { Zoom } from "./interface/zoom" import { getStory } from "./queries/getStory" import { BottomBar } from "./interface/bottom-bar" import { Page } from "./interface/page" export default function Main() { const [_isPending, startTransition] = useTransition() const isGeneratingStory = useStore(state => state.isGeneratingStory) const setGeneratingStory = useStore(state => state.setGeneratingStory) const font = useStore(state => state.font) const preset = useStore(state => state.preset) const prompt = useStore(state => state.prompt) const setLayouts = useStore(state => state.setLayouts) const setPanels = useStore(state => state.setPanels) const setCaptions = useStore(state => state.setCaptions) const zoomLevel = useStore(state => state.zoomLevel) const [waitABitMore, setWaitABitMore] = useState(false) // react to prompt changes useEffect(() => { if (!prompt) { return } startTransition(async () => { setWaitABitMore(false) setGeneratingStory(true) try { const llmResponse = await getStory({ preset, prompt }) console.log("response:", llmResponse) const panelPromptPrefix = preset.imagePrompt(prompt).join(", ") console.log("panel prompt prefix:", panelPromptPrefix) const nbPanels = 4 const newPanels: string[] = [] const newCaptions: string[] = [] setWaitABitMore(true) for (let p = 0; p < nbPanels; p++) { newCaptions.push(llmResponse[p]?.caption || "...") const newPanel = [panelPromptPrefix, llmResponse[p]?.instructions || ""] newPanels.push(newPanel.map(chunk => chunk).join(", ")) } console.log("newPanels:", newPanels) setCaptions(newCaptions) setPanels(newPanels) } catch (err) { console.error(err) } finally { setTimeout(() => { setGeneratingStory(false) setWaitABitMore(false) }, 12000) } }) }, [prompt, preset?.label]) // important: we need to react to preset changes too return (