Skip to content

Open source CapCut alternative.

TypeScript

feat(site): confirm generated-asset deletes that empty timeline spots

David Le22edd776f21d
diff --git a/site/src/cut/components/GeneratePanel.tsx b/site/src/cut/components/GeneratePanel.tsx
index 9d95b4ef..9e4f0b53 100644
--- a/site/src/cut/components/GeneratePanel.tsx
+++ b/site/src/cut/components/GeneratePanel.tsx
@@ -1,7 +1,7 @@
"use client";
import { useEffect, useRef } from "react";
-import { Copy, Film, Loader2, Maximize2, Plus, RotateCw, Sparkles, Trash2, X } from "lucide-react";
+import { Copy, Film, Loader2, Maximize2, Plus, RotateCw, Sparkles, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
import { MEDIA_CORS } from "@/cut/lib/mediaCors";
@@ -422,20 +422,13 @@ function JobRow({ job, handle }: { job: GenerateJob; handle?: string }) {
<Copy /> Copy reference
</DropdownMenuItem>
}
- after={
- <DropdownMenuItem
- variant="destructive"
- onClick={() => {
- // The render dies for real: the tile goes with its job row,
- // and the asset takes its media file (and any clips playing
- // it) along — same delete the image tiles offer.
- useGenerate.getState().dismiss(job.id);
- useEditor.getState().removeAsset(asset.id);
- }}
- >
- <Trash2 /> Delete
- </DropdownMenuItem>
- }
+ onDelete={() => {
+ // The render dies for real: the tile goes with its job row, and
+ // the asset takes its media file (and any clips playing it)
+ // along — same delete the image tiles offer.
+ useGenerate.getState().dismiss(job.id);
+ useEditor.getState().removeAsset(asset.id);
+ }}
/>
</div>
{pulse && <div aria-hidden className={genPulseOverlay} />}
diff --git a/site/src/cut/components/GeneratedAssetMenu.tsx b/site/src/cut/components/GeneratedAssetMenu.tsx
index b0721d06..f8d80297 100644
--- a/site/src/cut/components/GeneratedAssetMenu.tsx
+++ b/site/src/cut/components/GeneratedAssetMenu.tsx
@@ -1,7 +1,17 @@
"use client";
-import type { ReactNode } from "react";
-import { Clapperboard, Ellipsis, FolderPlus } from "lucide-react";
+import { useState, type ReactNode } from "react";
+import { Clapperboard, Ellipsis, FolderPlus, Trash2 } from "lucide-react";
+import {
+ AlertDialog,
+ AlertDialogAction,
+ AlertDialogCancel,
+ AlertDialogContent,
+ AlertDialogDescription,
+ AlertDialogFooter,
+ AlertDialogHeader,
+ AlertDialogTitle,
+} from "@/components/ui/alert-dialog";
import {
DropdownMenu,
DropdownMenuContent,
@@ -16,21 +26,44 @@ import type { MediaAsset } from "@/cut/lib/types";
/** The "…" menu on a generated asset (image tile, video job row, voiceover
* row). Every surface gets the same pair — move the asset into the Media
* panel (drop its `origin` tag) or copy it into the shared library — and
- * slots its own actions around them via `before`/`after`. */
+ * slots its own actions around them via `before`/`after`.
+ *
+ * `onDelete` adds the destructive item and its confirmation: the asset takes
+ * its media file with it, so a delete that would also empty places on the
+ * timeline says how many before it happens, and nothing brings them back. */
export function GeneratedAssetMenu({
asset,
projectId,
triggerClassName,
before,
after,
+ onDelete,
+ deleteLabel = "Delete",
}: {
asset: MediaAsset;
projectId: string;
triggerClassName: string;
before?: ReactNode;
after?: ReactNode;
+ onDelete?: () => void;
+ deleteLabel?: string;
}) {
+ // Timeline items the delete would take with it; null = no prompt open.
+ const [confirmUses, setConfirmUses] = useState<number | null>(null);
+
+ const remove = () => {
+ if (!onDelete) return;
+ const s = useEditor.getState();
+ const uses =
+ s.clips.filter((c) => c.assetId === asset.id).length +
+ s.audioClips.filter((c) => c.assetId === asset.id).length;
+ // Deleting something the cut never used costs the user nothing to redo.
+ if (uses > 0) setConfirmUses(uses);
+ else onDelete();
+ };
+
return (
+ <>
<DropdownMenu>
<DropdownMenuTrigger
aria-label="More actions"
@@ -60,9 +93,40 @@ export function GeneratedAssetMenu({
>
<FolderPlus /> Add to library
</DropdownMenuItem>
- {after != null && <DropdownMenuSeparator />}
+ {(after != null || onDelete) && <DropdownMenuSeparator />}
{after}
+ {onDelete && (
+ <DropdownMenuItem variant="destructive" onClick={remove}>
+ <Trash2 /> {deleteLabel}
+ </DropdownMenuItem>
+ )}
</DropdownMenuContent>
</DropdownMenu>
+ <AlertDialog open={confirmUses !== null} onOpenChange={(o) => !o && setConfirmUses(null)}>
+ <AlertDialogContent>
+ <AlertDialogHeader>
+ <AlertDialogTitle>Delete “{asset.name}”?</AlertDialogTitle>
+ <AlertDialogDescription>
+ {confirmUses === 1
+ ? "It plays in 1 place on the timeline, which goes with it."
+ : `It plays in ${confirmUses} places on the timeline, which go with it.`}{" "}
+ The media file is deleted too, and this can’t be undone.
+ </AlertDialogDescription>
+ </AlertDialogHeader>
+ <AlertDialogFooter>
+ <AlertDialogCancel>Cancel</AlertDialogCancel>
+ <AlertDialogAction
+ className="bg-destructive/10 text-destructive hover:bg-destructive/20"
+ onClick={() => {
+ setConfirmUses(null);
+ onDelete?.();
+ }}
+ >
+ Delete
+ </AlertDialogAction>
+ </AlertDialogFooter>
+ </AlertDialogContent>
+ </AlertDialog>
+ </>
);
}