Open source CapCut alternative.
TypeScript
feat(cut): badge the Media tab when a background export finishes
David Le55c70e46d5cc
diff --git a/site/src/cut/components/SidePanel.tsx b/site/src/cut/components/SidePanel.tsxindex 41017f03..bad48ece 100644--- a/site/src/cut/components/SidePanel.tsx+++ b/site/src/cut/components/SidePanel.tsx@@ -29,7 +29,7 @@ import {import type { AssetRef } from "@/cut/lib/assetRef";import { RefDropZone } from "./RefDropZone";import { deleteExport, revealExport } from "@/cut/lib/exportClient";-import { useExports } from "@/cut/lib/exportStore";+import { useExports, useWatchExportLands } from "@/cut/lib/exportStore";import {addAssetToLibraryTemplate,addLibraryAssetToProject,@@ -51,7 +51,7 @@ import {type LibraryFolder,} from "@/cut/lib/library";import { mediaUrl, type LibraryTemplate } from "@/cut/lib/types";-import { isGenTab, useGenNotify, useWatchGenTab } from "@/cut/lib/genNotify";+import { genPulseOverlay, isGenTab, useGenNotify, useGenPulse, useWatchGenTab } from "@/cut/lib/genNotify";import { CAPTION_LIMIT, normalizeTags } from "@/cut/lib/publish";import { useEditor } from "@/cut/lib/store";import { formatTime } from "@/cut/lib/time";@@ -138,6 +138,8 @@ export function SidePanel({// the rail icon, and opening the tab lets the new tiles pulse for a beat.const unseen = useGenNotify((s) => s.unseen);useWatchGenTab(tab, projectId);+ // Media badges too: its arrivals are exports finishing in the background.+ useWatchExportLands(projectId);// Clicking a reference token anywhere jumps here: switch to the tab that// owns the asset; the matching card scrolls into view and flashes.@@ -317,6 +319,12 @@ function PanelHead({ title, action }: { title: string; action?: React.ReactNode);}+/** Fresh-arrival ring for an export row that landed while the tab was closed. */+function ExportPulse({ file }: { file: string }) {+ const pulse = useGenPulse("media", file);+ return pulse ? <div aria-hidden className={genPulseOverlay} /> : null;+}+function MediaPanel({projectId,onImport,@@ -456,8 +464,9 @@ function MediaPanel({{exports.map((it) => (<divkey={it.file}- className="export-row group flex w-full items-center gap-2.5 rounded-lg border border-border p-1.5 transition-colors hover:border-input hover:bg-muted/50"+ className="export-row group relative flex w-full items-center gap-2.5 overflow-hidden rounded-lg border border-border p-1.5 transition-colors hover:border-input hover:bg-muted/50">+ <ExportPulse file={it.file} /><buttontype="button"className="flex min-w-0 flex-1 items-center gap-2.5 text-left"diff --git a/site/src/cut/lib/exportStore.ts b/site/src/cut/lib/exportStore.tsindex 57f793e6..cc06c97b 100644--- a/site/src/cut/lib/exportStore.ts+++ b/site/src/cut/lib/exportStore.ts@@ -1,5 +1,6 @@"use client";+import { useEffect, useRef } from "react";import { create } from "zustand";import { apiFetch } from "./api";import {@@ -8,6 +9,7 @@ import {type ExportDoc,type ExportSettings,} from "./exportClient";+import { useGenNotify } from "./genNotify";// Exports are tracked app-wide, not per-open-project. The engine holds every// export job in one process-global registry, so this store is a thin reflection@@ -137,6 +139,31 @@ export const useExports = create<ExportsState>((set, get) => ({},}));+/** Badge the Media tab when one of this project's exports finishes in the+ * background: watch the engine feed for jobs newly turned done and report each+ * to the gen-notify store, keyed by file name so the export row can pulse.+ * The first sight of the feed only seeds the baseline — exports that were+ * already done when the editor opened aren't news. */+export function useWatchExportLands(projectId: string) {+ const jobs = useExports((s) => s.jobs);+ const seen = useRef<Set<string> | null>(null);+ useEffect(() => {+ seen.current = null;+ }, [projectId]);+ useEffect(() => {+ const done = jobs.filter((j) => j.projectId === projectId && j.status === "done");+ if (seen.current === null) {+ seen.current = new Set(done.map((j) => j.id));+ return;+ }+ for (const j of done) {+ if (seen.current.has(j.id)) continue;+ seen.current.add(j.id);+ if (j.outName) useGenNotify.getState().landed("media", j.outName);+ }+ }, [jobs, projectId]);+}+// The dock is mounted app-wide, so polling runs the whole time the Cut app is// open. It quickens while work is in flight and idles between exports.let pollTimer: ReturnType<typeof setTimeout> | null = null;diff --git a/site/src/cut/lib/genNotify.ts b/site/src/cut/lib/genNotify.tsindex 6a27453d..b3a2421a 100644--- a/site/src/cut/lib/genNotify.ts+++ b/site/src/cut/lib/genNotify.ts@@ -7,16 +7,17 @@ import { create } from "zustand";// already imports, so the styles load exactly where the overlay is used.import "./genNotify.css";-// AI generations 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 each generate 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.+// 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.-export type GenTab = "video" | "image" | "audio";+export type GenTab = "video" | "image" | "audio" | "media";export const isGenTab = (v: string): v is GenTab =>- v === "video" || v === "image" || v === "audio";+ v === "video" || v === "image" || v === "audio" || v === "media";/** How long a tab's new tiles keep pulsing once it opens. */const PULSE_MS = 4500;@@ -27,7 +28,7 @@ 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: [] };+const EMPTY: Record<GenTab, string[]> = { video: [], image: [], audio: [], media: [] };interface GenNotifyState {/** Finished-while-away asset ids per tab — the rail badge counts these. */