// SceneForm.tsx // Form for adding a new scene to a session. import { useState } from "react"; import type { CampaignId, Scene } from "@/lib/types"; import { pb } from "@/lib/pocketbase"; /** * Renders a form to add a new scene. Calls onCreate with the new scene document. */ export const SceneForm = ({ campaign, onCreate, }: { campaign: CampaignId; onCreate: (scene: Scene) => Promise; }) => { const [text, setText] = useState(""); const [adding, setAdding] = useState(false); const [error, setError] = useState(null); async function handleSubmit(e: React.FormEvent) { e.preventDefault(); if (!text.trim()) return; setAdding(true); setError(null); try { const sceneDoc: Scene = await pb.collection("documents").create({ campaign, data: { scene: { text, }, }, }); setText(""); await onCreate(sceneDoc); } catch (e: any) { setError(e?.message || "Failed to add scene."); } finally { setAdding(false); } } return (

Create new scene

setText(e.target.value)} disabled={adding} aria-label="Add new scene" /> {error &&
{error}
}
); };