Open source CapCut alternative.
TypeScript
feat(site): spin and badge every side-rail tab with long-running work
David Lecc45b68921e8
diff --git a/site/src/cut/components/AudioPanel.tsx b/site/src/cut/components/AudioPanel.tsxindex f46b1792..ac5d1672 100644--- a/site/src/cut/components/AudioPanel.tsx+++ b/site/src/cut/components/AudioPanel.tsx@@ -219,6 +219,8 @@ function MusicGenerator({ projectId }: { projectId: string }) {setPending((p) => p + n);await Promise.all(Array.from({ length: n }, async () => {+ // Spins the Audio rail tile for the take's whole flight.+ const settle = useGenNotify.getState().begin("audio");try {const asset = await synthesizeMusic(projectId, text, { variant, instrumental });// A render can outlast the open project — the user may switch away@@ -237,6 +239,7 @@ function MusicGenerator({ projectId }: { projectId: string }) {fail(e, "Music generation failed.");} finally {setPending((p) => p - 1);+ settle();}}));@@ -401,6 +404,9 @@ function VoiceGenerator({ projectId }: { projectId: string }) {const text = script.trim();if (!text) return;setPending((p) => p + 1);+ // The Audio rail tile spins while this runs — the tab is often closed+ // before the voice lands.+ const settle = useGenNotify.getState().begin("audio");setError(null);try {const playhead = useEditor.getState().currentTime;@@ -433,6 +439,7 @@ function VoiceGenerator({ projectId }: { projectId: string }) {fail(e, "Voice generation failed.");} finally {setPending((p) => p - 1);+ settle();}};diff --git a/site/src/cut/components/SidePanel.tsx b/site/src/cut/components/SidePanel.tsxindex a467eacf..7c4f6dbe 100644--- a/site/src/cut/components/SidePanel.tsx+++ b/site/src/cut/components/SidePanel.tsx@@ -68,6 +68,7 @@ import { retryUpload } from "@/cut/lib/importQueue";import { isMediaFile, revealMedia } from "@/cut/lib/media";import { mediaUrl, TRANSITION_MAX } from "@/cut/lib/types";import { genPulseOverlay, isGenTab, useGenNotify, useGenPulse, useWatchGenTab } from "@/cut/lib/genNotify";+import { useGenerate, type GenerateJob } from "@/cut/lib/generate";import { CAPTION_LIMIT, normalizeTags } from "@/cut/lib/publish";import { useEditor } from "@/cut/lib/store";import { formatTime } from "@/cut/lib/time";@@ -174,14 +175,32 @@ export function SidePanel({useWatchGenTab(tab, projectId);// Media badges too: its arrivals are exports finishing in the background.useWatchExportLands(projectId);- // While one of this project's exports renders, the Media tile spins — the- // export row lives in that panel, which is usually closed while it runs.+ // While a tab owns work in flight its rail tile spins — the work's own panel+ // is usually closed while it runs. Each tab's running state comes from the+ // store that owns that work: exports for Media, panel renders for+ // Video/Image, registered syntheses for Audio, the transcription pass for+ // Subtitles.const exporting = useExports((s) =>s.jobs.some((j) => j.projectId === projectId && (j.status === "queued" || j.status === "running")) || s.local.some((r) => r.projectId === projectId && r.status === "preparing"));+ const panelRendering = (s: { jobs: GenerateJob[] }, kind: GenerateJob["kind"]) =>+ s.jobs.some(+ (j) => j.projectId === projectId && j.kind === kind && j.status === "running" && !j.chatId+ );+ const videoBusy = useGenerate((s) => panelRendering(s, "video"));+ const imageBusy = useGenerate((s) => panelRendering(s, "image"));+ const audioBusy = useGenNotify((s) => s.active.audio.length > 0);+ const subtitlesBusy = useEditor((s) => s.subtitleStatus === "running");+ const busy: Partial<Record<Tab, boolean>> = {+ media: exporting,+ video: videoBusy,+ image: imageBusy,+ audio: audioBusy,+ subtitles: subtitlesBusy,+ };// Clicking a reference token anywhere jumps here: switch to the tab that// owns the asset; the matching card scrolls into view and flashes.@@ -238,15 +257,7 @@ export function SidePanel({)}><Icon className="size-4.5" />- {unseenCount > 0 ? (- <span className="absolute -top-1 -right-1 grid h-[15px] min-w-[15px] place-items-center rounded-full bg-[#0a84ff] px-1 text-[9px] leading-none font-semibold text-white tabular-nums ring-2 ring-card">- {unseenCount}- </span>- ) : id === "media" && exporting ? (- <span className="absolute -top-1 -right-1 grid size-[15px] place-items-center rounded-full bg-card ring-2 ring-card">- <Loader2 className="size-3 animate-spin text-primary" />- </span>- ) : null}+ <TileStatus count={unseenCount} busy={!!busy[id]} /></span><spanclassName={cn(@@ -435,6 +446,25 @@ function ClosePanelButton({ onClose }: { onClose: () => void }) {);}+/** The rail tile's corner status, one look for every tab: a blue count of+ * arrivals that finished while the tab was closed, else a spinner while the+ * tab owns work still in flight. */+function TileStatus({ count, busy }: { count: number; busy: boolean }) {+ if (count > 0)+ return (+ <span className="absolute -top-1 -right-1 grid h-[15px] min-w-[15px] place-items-center rounded-full bg-[#0a84ff] px-1 text-[9px] leading-none font-semibold text-white tabular-nums ring-2 ring-card">+ {count}+ </span>+ );+ if (busy)+ return (+ <span className="absolute -top-1 -right-1 grid size-[15px] place-items-center rounded-full bg-card ring-2 ring-card">+ <Loader2 className="size-3 animate-spin text-primary" />+ </span>+ );+ return null;+}+function PanelHead({ title }: { title: string }) {return (<div className="flex h-12 shrink-0 items-center pr-2.5 pl-4">diff --git a/site/src/cut/components/VoicePicker.tsx b/site/src/cut/components/VoicePicker.tsxindex e2b17524..bc495d78 100644--- a/site/src/cut/components/VoicePicker.tsx+++ b/site/src/cut/components/VoicePicker.tsx@@ -10,6 +10,7 @@ import {} from "@/components/ui/dropdown-menu";import { SectionTitle } from "@/cut/components/SectionTitle";import { creditsUrl, signInUrl, useSignedIn } from "@/cut/lib/generate";+import { useGenNotify } from "@/cut/lib/genNotify";import { useEditor, type EditorState } from "@/cut/lib/store";import { NoCreditsError, renderSpeechClip, resolveLanguage, resolveVoice } from "@/cut/lib/tts";import {@@ -304,6 +305,9 @@ export function GenerateSubtitlesAudio({const generate = async () => {setBusy(true);setError(null);+ // A voiceover like the Audio tab's own: its rail tile spins for the+ // flight, and the landed clip badges it if the user stepped away.+ const settle = useGenNotify.getState().begin("audio");try {if (scopedCueIds(useEditor.getState(), selectCueIds).length === 0) {// Nothing to read yet — transcribe first, then voice the fresh cues.@@ -323,10 +327,11 @@ export function GenerateSubtitlesAudio({throw new Error("No speech found to voice.");}}- await generateSubtitlesReadout(voice, {+ const { asset } = await generateSubtitlesReadout(voice, {cueIds: selectCueIds?.(useEditor.getState()),language,});+ useGenNotify.getState().landed("audio", asset.id);} catch (e) {setError(e instanceof Error@@ -335,6 +340,7 @@ export function GenerateSubtitlesAudio({);} finally {setBusy(false);+ settle();}};diff --git a/site/src/cut/lib/genNotify.ts b/site/src/cut/lib/genNotify.tsindex b3a2421a..acc9cdda 100644--- a/site/src/cut/lib/genNotify.ts+++ b/site/src/cut/lib/genNotify.ts@@ -7,17 +7,18 @@ import { create } from "zustand";// already imports, so the styles load exactly where the overlay is used.import "./genNotify.css";-// AI generations and exports outlive the panel that started them — several can-// render at once while the user edits elsewhere. This store notices the ones-// that finish unwatched: the side rail badges the owning tab with a blue count,-// and opening that tab clears the count and lets the freshly-arrived tiles-// pulse blue for a few seconds so the eye lands on them. Media's arrivals are-// finished exports, keyed by file name.+// Long-running work outlives the panel that started it — several renders,+// exports, or transcriptions can run at once while the user edits elsewhere.+// This store is the one place every tab reports that work: while a tab owns+// work in flight its rail tile spins, and a completion that lands unwatched+// badges the tile with a blue count. Opening the tab clears the count and lets+// the freshly-arrived tiles pulse blue for a few seconds so the eye lands on+// them. Media's arrivals are finished exports, keyed by file name.-export type GenTab = "video" | "image" | "audio" | "media";+export type GenTab = "video" | "image" | "audio" | "media" | "subtitles";export const isGenTab = (v: string): v is GenTab =>- v === "video" || v === "image" || v === "audio" || v === "media";+ v === "video" || v === "image" || v === "audio" || v === "media" || v === "subtitles";/** How long a tab's new tiles keep pulsing once it opens. */const PULSE_MS = 4500;@@ -28,17 +29,35 @@ const PULSE_MS = 4500;export const genPulseOverlay ="cut-gen-pulse pointer-events-none absolute inset-0 rounded-[inherit]";-const EMPTY: Record<GenTab, string[]> = { video: [], image: [], audio: [], media: [] };+const EMPTY: Record<GenTab, string[]> = {+ video: [],+ image: [],+ audio: [],+ media: [],+ subtitles: [],+};++/** Unique key per registered piece of in-flight work. */+let workSeq = 0;interface GenNotifyState {/** Finished-while-away asset ids per tab — the rail badge counts these. */unseen: Record<GenTab, string[]>;/** The just-opened tab's arrivals, pulsing until their timer clears them. */pulsing: Record<GenTab, string[]>;+ /** In-flight work registered per tab — the rail tile spins while a tab has+ * entries. For work whose running state lives in no store of its own (audio+ * syntheses); tabs with a job store (generate, exports, subtitles) are read+ * directly by the rail. */+ active: Record<GenTab, string[]>;/** The generate tab on screen; a completion here needs no badge or pulse —* the user watched the tile appear. */watching: GenTab | null;landed: (tab: GenTab, assetId: string) => void;+ /** Register a long task with its tab; call the returned function when it+ * settles. Settling after a project switch is a no-op — reset() already+ * dropped the entry. */+ begin: (tab: GenTab) => () => void;watch: (tab: GenTab | null) => void;endPulse: (tab: GenTab) => void;reset: () => void;@@ -47,11 +66,22 @@ interface GenNotifyState {export const useGenNotify = create<GenNotifyState>((set, get) => ({unseen: EMPTY,pulsing: EMPTY,+ active: EMPTY,watching: null,landed: (tab, assetId) => {if (get().watching === tab) return; // watched live — no badge, no pulseset((s) => ({ unseen: { ...s.unseen, [tab]: [...s.unseen[tab], assetId] } }));},+ begin: (tab) => {+ const key = `w${workSeq++}`;+ set((s) => ({ active: { ...s.active, [tab]: [...s.active[tab], key] } }));+ return () =>+ set((s) =>+ s.active[tab].includes(key)+ ? { active: { ...s.active, [tab]: s.active[tab].filter((k) => k !== key) } }+ : {}+ );+ },// Opening a tab clears its badge and hands its arrivals to the pulse set, so// leaving before the pulse ends never brings the count back — they're seen.watch: (tab) =>@@ -68,7 +98,7 @@ export const useGenNotify = create<GenNotifyState>((set, get) => ({}),endPulse: (tab) =>set((s) => (s.pulsing[tab].length === 0 ? {} : { pulsing: { ...s.pulsing, [tab]: [] } })),- reset: () => set({ unseen: EMPTY, pulsing: EMPTY }),+ reset: () => set({ unseen: EMPTY, pulsing: EMPTY, active: EMPTY }),}));/** Whether this finished tile is in its tab's fresh-arrival pulse. */diff --git a/site/src/cut/lib/store.ts b/site/src/cut/lib/store.tsindex a9c46958..bde884a0 100644--- a/site/src/cut/lib/store.ts+++ b/site/src/cut/lib/store.ts@@ -39,6 +39,7 @@ import {} from "./docCache";import { renderMix, transcribeSamples, type CloudTranscribeSpec } from "./cloudTranscribe";import { alignCues } from "./cueAlign";+import { useGenNotify } from "./genNotify";import { engineTranscribeSamples } from "./localStt";import { trackLocale } from "./subtitles";import { ANIM_STYLE_IDS, emptySubtitles, IMAGE_CLIP_SECONDS, LOOK_IDS, MAX_SUBTITLE_LANES, mediaUrl, migrateLegacyTransitions, normalizeAspect, SPEED_FLOOR, SPEED_MIN, TRANSITION_MAX } from "./types";@@ -3068,6 +3069,16 @@ useEditor.subscribe((s, prev) => {docSeq++;});+// Every subtitles pass — transcription, translation, AI captions — rides+// subtitleStatus, so this one watch badges the Subtitles rail tile whenever a+// pass settles while the tab is closed (landed() no-ops while it's watched).+// A project load also drops "running", inside the same set() that clears+// `loaded` — the guard keeps that reset off the badge.+useEditor.subscribe((s, prev) => {+ if (prev.subtitleStatus === "running" && s.subtitleStatus !== "running" && s.loaded)+ useGenNotify.getState().landed("subtitles", `subs-${Date.now()}`);+});+/** Ids of the assets still uploading, as a comparable key ("" when none). An* import is on screen before its bytes are stored, and nothing about it may* reach the document until they are. */