Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

Cinema Studio: keep the unsent draft per project, refresh after viewer actions, label tiles, test retry

Claudeec5d560a93b8
diff --git a/src/components/cinema/cinema-feed.tsx b/src/components/cinema/cinema-feed.tsx
index 581dff07..8f1b48f9 100644
--- a/src/components/cinema/cinema-feed.tsx
+++ b/src/components/cinema/cinema-feed.tsx
@@ -23,6 +23,7 @@ import {
Video,
X,
} from "lucide-react";
+import { useQueryClient } from "@tanstack/react-query";
import { useCallback, useEffect, useMemo, useState, useSyncExternalStore } from "react";
import { toast } from "sonner";
import {
@@ -335,6 +336,7 @@ function TileView({
<div
role={clickable ? "button" : undefined}
tabIndex={clickable ? 0 : undefined}
+ aria-label={clickable ? `${step ? `${step}: ` : ""}${promptOf(g)}` : undefined}
draggable={!u.tile}
onDragStart={(e) => e.dataTransfer.setData("application/x-cinema-takes", JSON.stringify(dragIds()))}
onClick={(e) => {
@@ -462,6 +464,7 @@ export function CinemaFeed({
}) {
const [prefs, setPrefs] = usePrefs();
const actions = useItemActions(projectId);
+ const qc = useQueryClient();
const [selected, setSelected] = useState<Set<string>>(new Set());
const [anchor, setAnchor] = useState<string | null>(null);
const [open, setOpen] = useState<string | null>(null);
@@ -658,7 +661,11 @@ export function CinemaFeed({
<Viewer
generation={{ ...viewable[pos].g, outputs: [viewable[pos].output!] }}
index={0}
- onClose={() => setOpen(null)}
+ onClose={() => {
+ setOpen(null);
+ // The viewer likes and deletes through /api/generations: pick those changes up.
+ void qc.invalidateQueries({ queryKey: ["cinema", projectId, "items"] });
+ }}
onPrev={pos > 0 ? () => setOpen(viewable[pos - 1].key) : undefined}
onNext={pos < viewable.length - 1 ? () => setOpen(viewable[pos + 1].key) : undefined}
onReuse={(g) => handlers.onLoad(g as CinemaGeneration)}
diff --git a/src/components/cinema/workspace.tsx b/src/components/cinema/workspace.tsx
index 21bc50df..6fbccd03 100644
--- a/src/components/cinema/workspace.tsx
+++ b/src/components/cinema/workspace.tsx
@@ -68,6 +68,28 @@ function nameFrom(prompt: string | undefined, fallback: string): string {
return words.slice(0, 3).map((w) => w[0].toUpperCase() + w.slice(1).toLowerCase()).join(" ") || fallback;
}
+const DRAFT_KEY = (id: string) => `fuobe.cinema.draft.${id}`;
+const KEPT = ["mode", "imageTool", "prompt", "moves", "models", "duration", "resolution", "aspect", "batch", "audio", "multiShot", "grid"] as const;
+
+function restoreDraft(id: string): CinemaDraft {
+ const base = initialDraft();
+ try {
+ const raw = localStorage.getItem(DRAFT_KEY(id));
+ if (!raw) return base;
+ const saved = JSON.parse(raw) as Partial<CinemaDraft>;
+ const kept = Object.fromEntries(KEPT.filter((k) => saved[k] !== undefined).map((k) => [k, saved[k]]));
+ return { ...base, ...kept };
+ } catch {
+ return base;
+ }
+}
+
+function saveDraft(id: string, d: CinemaDraft) {
+ try {
+ localStorage.setItem(DRAFT_KEY(id), JSON.stringify(Object.fromEntries(KEPT.map((k) => [k, d[k]]))));
+ } catch {}
+}
+
function folderPath(folders: CinemaFolder[], id: string): CinemaFolder[] {
const out: CinemaFolder[] = [];
let cur = folders.find((f) => f.id === id);
@@ -138,7 +160,12 @@ function Workspace({ data, items, loading }: { data: ProjectView; items: CinemaG
const [engine, setEngine] = useEngine();
const [view, setView] = useState<CinemaView>({ kind: "home" });
const [nested, setNested] = useState(true);
- const [draft, setDraftState] = useState<CinemaDraft>(initialDraft);
+ const [draft, setDraftState] = useState<CinemaDraft>(() => restoreDraft(id));
+ // The unsent prompt and its settings survive a reload (this browser only).
+ useEffect(() => {
+ const t = setTimeout(() => saveDraft(id, draft), 400);
+ return () => clearTimeout(t);
+ }, [id, draft]);
const setDraft = (patch: Partial<CinemaDraft> | ((d: CinemaDraft) => Partial<CinemaDraft>)) => setDraftState((d) => ({ ...d, ...(typeof patch === "function" ? patch(d) : patch) }));
const [settings, setSettings] = useState<DirectorSettings>(project.director);
const update = useUpdateProject(id);
diff --git a/tests/cinema-api.test.ts b/tests/cinema-api.test.ts
index 82115e58..050043b8 100644
--- a/tests/cinema-api.test.ts
+++ b/tests/cinema-api.test.ts
@@ -160,6 +160,19 @@ describe("Cinema API", () => {
expect(film.request.inputs?.images?.[0]).toBe(gens.getGeneration(items[1].id)!.outputs[0].url);
}, 90_000);
+ it("retries a canceled take in the same folder, with the same request", async () => {
+ const p = cinema.createProject({ name: "Retry" });
+ const folder = cinema.createFolder(p.id, { name: "Scene 9" });
+ const { items } = generateInProject(p.id, { ...VIDEO, engine: "open", moves: ["pan-left"], images: [] }, folder.id);
+ await gens.cancelGeneration(items[0].id);
+ const again = cinema.retryItem(p.id, items[0].id);
+ expect(again).toHaveLength(1);
+ expect(again[0].request.prompt).toBe(items[0].request.prompt);
+ expect(cinema.listItems(p.id, { folderId: folder.id }).map((g) => g.id)).toContain(again[0].id);
+ expect(cinema.listItems(p.id, { folderId: folder.id }).find((g) => g.id === again[0].id)?.take?.moves).toEqual(["pan-left"]);
+ expect(() => cinema.retryItem(p.id, "missing")).toThrow(/isn't in this project/);
+ });
+
it("stores the tiles cut from a grid sheet", async () => {
const p = cinema.createProject({ name: "Grid" });
const { items } = generateInProject(p.id, { ...VIDEO, mode: "image", action: "grid", grid: { size: "2x2", type: "shots" } });