Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: confirm before clearing the video gallery (#8354)

oobaboogaa4c77ed8c7e7
diff --git a/studio/frontend/src/features/video/video-page.tsx b/studio/frontend/src/features/video/video-page.tsx
index d97e977da48..7dd2456fa0e 100644
--- a/studio/frontend/src/features/video/video-page.tsx
+++ b/studio/frontend/src/features/video/video-page.tsx
@@ -32,6 +32,16 @@ import {
} from "@/lib/gallery-flags";
import { useHardwareInfo } from "@/hooks/use-hardware-info";
import { usePersistedToggle } from "@/hooks/use-persisted-toggle";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import {
Dialog,
@@ -862,6 +872,12 @@ function VideoGenerator({ active = true }: { active?: boolean }) {
const [videos, setVideos] = useState<GalleryVideo[]>(() => galleryCache.videos);
const [hasMore, setHasMore] = useState(() => galleryCache.hasMore);
const [selectedId, setSelectedId] = useState<string | null>(() => galleryCache.selectedId);
+ const [clearConfirmOpen, setClearConfirmOpen] = useState(false);
+ const [clearingGallery, setClearingGallery] = useState(false);
+ // The `active` gate below only HIDES the confirm, and Radix does not call onOpenChange for
+ // a parent-forced close, so on this persistently mounted page the state would outlive the
+ // route change and the confirm would be back on return. Reset it during render.
+ if (!active && clearConfirmOpen) setClearConfirmOpen(false);
// Autoplay replays per selected clip (3 total plays, then pause). Reset on every selection change.
const playCountRef = useRef(0);
useEffect(() => {
@@ -1533,24 +1549,27 @@ function VideoGenerator({ active = true }: { active?: boolean }) {
);
const handleClearAll = useCallback(async () => {
+ setClearingGallery(true);
try {
await clearVideoGallery();
+ galleryCache.srcById.clear();
+ galleryCache.refreshed.clear();
+ // Every mint in flight now belongs to a cleared gallery, so their links are discarded on arrival. The epoch covers unlisted ids too.
+ galleryCache.epoch += 1;
+ stripEpoch.current += 1;
+ galleryCache.videos = [];
+ galleryCache.hasMore = false;
+ galleryCache.selectedId = null;
+ setSrcById({});
+ setVideos([]);
+ setHasMore(false);
+ setSelectedId(null);
+ setClearConfirmOpen(false);
} catch (err) {
toast.error(err instanceof Error ? err.message : "Failed to clear gallery");
- return;
+ } finally {
+ setClearingGallery(false);
}
- galleryCache.srcById.clear();
- galleryCache.refreshed.clear();
- // Every mint in flight now belongs to a cleared gallery, so their links are discarded on arrival. The epoch covers unlisted ids too.
- galleryCache.epoch += 1;
- stripEpoch.current += 1;
- galleryCache.videos = [];
- galleryCache.hasMore = false;
- galleryCache.selectedId = null;
- setSrcById({});
- setVideos([]);
- setHasMore(false);
- setSelectedId(null);
}, []);
// Load a clip's recipe back into the form inputs.
@@ -2845,6 +2864,35 @@ function VideoGenerator({ active = true }: { active?: boolean }) {
// The chat-style layout gives this page no outer top inset, so clear the custom
// titlebar here (34px on win/linux, 0 under macOS's native one) as chat does.
<div className="diffusion-surface flex h-full min-h-0 min-w-0 flex-1 flex-col overflow-hidden pt-[var(--studio-content-top-inset,0px)]">
+ <AlertDialog
+ open={active && clearConfirmOpen}
+ onOpenChange={(open) => {
+ if (!clearingGallery) setClearConfirmOpen(open);
+ }}
+ >
+ <AlertDialogContent size="sm">
+ <AlertDialogHeader>
+ <AlertDialogTitle>Clear all videos?</AlertDialogTitle>
+ <AlertDialogDescription>
+ This permanently deletes every generated video from the gallery. This action cannot
+ be undone.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel disabled={clearingGallery}>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ variant="destructive"
+ disabled={clearingGallery}
+ onClick={(event) => {
+ event.preventDefault();
+ void handleClearAll();
+ }}
+ >
+ {clearingGallery ? "Clearing…" : "Clear all"}
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
<Dialog
open={pendingH3Load !== null}
onOpenChange={(open) => {
@@ -3552,7 +3600,7 @@ function VideoGenerator({ active = true }: { active?: boolean }) {
<TooltipTrigger asChild={true}>
<button
type="button"
- onClick={() => void handleClearAll()}
+ onClick={() => setClearConfirmOpen(true)}
className="flex h-16 w-16 shrink-0 flex-col items-center justify-center gap-1 rounded-[10px] text-muted-foreground ring-1 ring-border transition-colors hover:text-destructive hover:ring-destructive/40"
>
<HugeiconsIcon icon={Delete02Icon} className="size-4" />
diff --git a/studio/frontend/tests/video-gallery-clear-confirmation.test.ts b/studio/frontend/tests/video-gallery-clear-confirmation.test.ts
new file mode 100644
index 00000000000..17ad466fe1e
--- /dev/null
+++ b/studio/frontend/tests/video-gallery-clear-confirmation.test.ts
@@ -0,0 +1,97 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+import assert from "node:assert/strict";
+import { readFileSync } from "node:fs";
+import test from "node:test";
+import { fileURLToPath } from "node:url";
+
+// Normalized: the assertions below span lines, and while .gitattributes keeps this tree at
+// LF, a source archive or a stray core.autocrlf would make every multi-line marker miss.
+const source = readFileSync(
+ fileURLToPath(
+ new URL("../src/features/video/video-page.tsx", import.meta.url),
+ ),
+ "utf8",
+).replace(/\r\n/g, "\n");
+
+/** The source between two markers. Throws if either moved: a silent empty slice would let
+ * the negative assertion below ("no longer calls handleClearAll") pass over nothing. */
+function between(start: string, end: string): string {
+ const from = source.indexOf(start);
+ const to = source.indexOf(end);
+ if (from === -1) {
+ throw new Error(`marker not found in video-page.tsx: ${start}`);
+ }
+ if (to <= from) {
+ throw new Error(`marker not found after ${JSON.stringify(start)}: ${end}`);
+ }
+ return source.slice(from, to);
+}
+
+test("video gallery bulk deletion requires an explicit confirmation", () => {
+ const clearButton = between(
+ "{/* Clear-all, tucked at the end",
+ "<TooltipContent>Clear all videos</TooltipContent>",
+ );
+ assert.ok(clearButton.includes("onClick={() => setClearConfirmOpen(true)}"));
+ assert.ok(!clearButton.includes("handleClearAll"));
+
+ const dialog = between(
+ "<AlertDialog\n open={active && clearConfirmOpen}",
+ "<Dialog\n open={pendingH3Load",
+ );
+ assert.ok(
+ dialog.includes("<AlertDialogTitle>Clear all videos?</AlertDialogTitle>"),
+ );
+ assert.ok(
+ dialog.includes(
+ "This permanently deletes every generated video from the gallery.",
+ ),
+ );
+ assert.ok(dialog.includes("be undone."));
+ assert.ok(
+ dialog.includes(
+ "<AlertDialogCancel disabled={clearingGallery}>Cancel</AlertDialogCancel>",
+ ),
+ );
+ assert.ok(dialog.includes('variant="destructive"'));
+ assert.ok(dialog.includes("event.preventDefault();"));
+ assert.ok(dialog.includes("void handleClearAll();"));
+});
+
+test("video gallery confirmation stays controlled while clearing and off-route", () => {
+ const handler = between(
+ "const handleClearAll = useCallback(",
+ "// Load a clip's recipe back into the form inputs.",
+ );
+ assert.ok(handler.includes("setClearingGallery(true);"));
+ assert.ok(handler.includes("await clearVideoGallery();"));
+ assert.ok(handler.includes("setClearConfirmOpen(false);"));
+ assert.ok(handler.includes("finally {\n setClearingGallery(false);"));
+ assert.ok(
+ handler.indexOf("await clearVideoGallery();") <
+ handler.indexOf("setClearConfirmOpen(false);"),
+ );
+
+ const root = between(
+ "<AlertDialog\n open={active && clearConfirmOpen}",
+ '<AlertDialogContent size="sm">',
+ );
+ assert.ok(root.includes("open={active && clearConfirmOpen}"));
+ assert.ok(root.includes("if (!clearingGallery) setClearConfirmOpen(open);"));
+});
+
+test("leaving the video route closes the confirmation rather than hiding it", () => {
+ // `active` going false only hides the dialog, and Radix does not call onOpenChange for a
+ // parent-forced close, so without this reset the confirm returns with the route.
+ const reset = between(
+ "const [clearingGallery, setClearingGallery] = useState(false);",
+ "const playCountRef = useRef(0);",
+ );
+ assert.ok(
+ reset.includes(
+ "if (!active && clearConfirmOpen) setClearConfirmOpen(false);",
+ ),
+ );
+});