feat: add confirmation dialog for track deletion
Right-click → Delete track now shows an AlertDialog with element count before removing. Prevents accidental destruction of tracks with many clips. Fixes #738
This commit is contained in:
parent
5cc6abc3a4
commit
c29633588f
|
|
@ -20,6 +20,16 @@ import {
|
|||
ContextMenuItem,
|
||||
ContextMenuTrigger,
|
||||
} from "@/components/ui/context-menu";
|
||||
import {
|
||||
AlertDialog,
|
||||
AlertDialogAction,
|
||||
AlertDialogCancel,
|
||||
AlertDialogContent,
|
||||
AlertDialogDescription,
|
||||
AlertDialogFooter,
|
||||
AlertDialogHeader,
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { useTimelineZoom } from "@/hooks/timeline/use-timeline-zoom";
|
||||
import {
|
||||
useCallback,
|
||||
|
|
@ -675,6 +685,7 @@ function TimelineTrackRows({
|
|||
const timeline = useEditor((e) => e.timeline);
|
||||
const tracks = useEditor((e) => e.timeline.getTracks());
|
||||
const { selectedElements } = useElementSelection();
|
||||
const [trackToDelete, setTrackToDelete] = useState<TimelineTrack | null>(null);
|
||||
const tracksWithSelection = useMemo(
|
||||
() => new Set(selectedElements.map((el) => el.trackId)),
|
||||
[selectedElements],
|
||||
|
|
@ -773,7 +784,7 @@ function TimelineTrackRows({
|
|||
icon={<HugeiconsIcon icon={Delete02Icon} />}
|
||||
onClick={(event: React.MouseEvent) => {
|
||||
event.stopPropagation();
|
||||
timeline.removeTrack({ trackId: track.id });
|
||||
setTrackToDelete(track);
|
||||
}}
|
||||
variant="destructive"
|
||||
>
|
||||
|
|
@ -783,6 +794,30 @@ function TimelineTrackRows({
|
|||
</ContextMenuContent>
|
||||
</ContextMenu>
|
||||
))}
|
||||
{trackToDelete && (
|
||||
<AlertDialog open onOpenChange={(open) => !open && setTrackToDelete(null)}>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete track?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
This will remove {trackToDelete.elements.length} element{trackToDelete.elements.length === 1 ? "" : "s"}.
|
||||
This action cannot be undone.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction
|
||||
onClick={() => {
|
||||
timeline.removeTrack({ trackId: trackToDelete.id });
|
||||
setTrackToDelete(null);
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</AlertDialogAction>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue