Open source CapCut alternative.
TypeScript
fix(cut): rest the exports dock while nothing renders
David Ledb8ea77c776d
diff --git a/site/src/cut/components/ExportsDock.tsx b/site/src/cut/components/ExportsDock.tsxindex 9e83891b..6834b428 100644--- a/site/src/cut/components/ExportsDock.tsx+++ b/site/src/cut/components/ExportsDock.tsx@@ -1,6 +1,6 @@"use client";-import { useEffect, useMemo, useState } from "react";+import { useEffect, useMemo, useRef, useState } from "react";import Link from "next/link";import {Check,@@ -27,6 +27,7 @@ import {import { framedHref } from "@/cut/lib/hostBridge";import { projectHref, useCutBase } from "@/cut/lib/nav";import { cn } from "@/lib/utils";+import { exportsDockOpen, inFlightCount, type DockChoice } from "@/cut/lib/exportsDockView";/*** The app-wide exports dock: one card pinned to the bottom-right that shows@@ -37,7 +38,7 @@ import { cn } from "@/lib/utils";* Cut app layout, above the per-project editor.*/export function ExportsDock() {- const [collapsed, setCollapsed] = useState(false);+ const [choice, setChoice] = useState<DockChoice>(null);// Poll the feed while the dock is mounted (i.e. the whole time the app is up).useEffect(() => {@@ -56,6 +57,19 @@ export function ExportsDock() {[all, dismissed]);+ // The dock opens while work is in flight and rests on its header once it+ // settles; a new export clears whatever was toggled for the last one.+ const statuses = items.map((i) => i.data.status);+ const inFlight = inFlightCount(statuses);+ const lastInFlight = useRef(inFlight);+ useEffect(() => {+ if (inFlight > lastInFlight.current) {+ setChoice(null);+ }+ lastInFlight.current = inFlight;+ }, [inFlight]);+ const open = exportsDockOpen(statuses, choice);+if (items.length === 0) return null;const running = items.filter(@@ -71,7 +85,7 @@ export function ExportsDock() {return (<div className="fixed right-4 bottom-4 z-50 max-h-[calc(100dvh-2rem)] w-72 max-w-[calc(100vw-2rem)] overflow-y-auto overscroll-contain rounded-xl border border-border bg-card shadow-lg">- {multi && (+ {(multi || !open || choice === "open") && (<div className="flex items-center gap-2 px-3 py-2"><span className="text-xs font-semibold">Exports</span><span className="flex-1 truncate text-[11px] text-muted-foreground tabular-nums">@@ -92,14 +106,14 @@ export function ExportsDock() {<Buttonvariant="ghost"size="icon-xs"- aria-label={collapsed ? "Expand exports" : "Collapse exports"}- onClick={() => setCollapsed((c) => !c)}+ aria-label={open ? "Collapse exports" : "Expand exports"}+ onClick={() => setChoice(open ? "closed" : "open")}>- <ChevronDown className={cn("transition-transform", !collapsed && "rotate-180")} />+ <ChevronDown className={cn("transition-transform", open && "rotate-180")} /></Button></div>)}- {!collapsed && (+ {open && (<div className="max-h-[min(60vh,22rem)] divide-y divide-border overflow-y-auto">{items.map((it) =>it.kind === "job" ? (diff --git a/site/src/cut/lib/exportsDockView.test.ts b/site/src/cut/lib/exportsDockView.test.tsnew file mode 100644index 00000000..e8f6158e--- /dev/null+++ b/site/src/cut/lib/exportsDockView.test.ts@@ -0,0 +1,12 @@+import { expect, test } from "bun:test";+import { exportsDockOpen } from "./exportsDockView";++test("the dock opens while work is in flight and rests closed once it settles", () => {+ // A dock full of finished files sits over the chat composer, so it opens+ // only while something renders or waits, unless the person chose otherwise.+ expect(exportsDockOpen(["done", "error"], null)).toBe(false);+ expect(exportsDockOpen(["done", "rendering"], null)).toBe(true);+ expect(exportsDockOpen(["queued"], null)).toBe(true);+ expect(exportsDockOpen(["done"], "open")).toBe(true);+ expect(exportsDockOpen(["running"], "closed")).toBe(false);+});diff --git a/site/src/cut/lib/exportsDockView.ts b/site/src/cut/lib/exportsDockView.tsnew file mode 100644index 00000000..de8d8bc1--- /dev/null+++ b/site/src/cut/lib/exportsDockView.ts@@ -0,0 +1,21 @@+/** What the person last chose for the dock; null until they toggle it. */+export type DockChoice = "open" | "closed" | null;++const IN_FLIGHT = new Set(["running", "rendering", "queued", "preparing"]);++/**+ * Whether the exports dock shows its rows. It sits over the chat composer, so+ * it opens while something renders or waits and rests on its header once+ * everything has settled. A toggle wins until the next export starts.+ */+export function exportsDockOpen(statuses: readonly string[], choice: DockChoice): boolean {+ if (choice !== null) {+ return choice === "open";+ }+ return inFlightCount(statuses) > 0;+}++/** How many exports are rendering or waiting their turn. */+export function inFlightCount(statuses: readonly string[]): number {+ return statuses.filter((s) => IN_FLIGHT.has(s)).length;+}