fix: remmove video track when media is deleted

This commit is contained in:
priyankarpal
2025-06-26 21:29:03 +05:30
parent 53184217bf
commit f76555dae5
3 changed files with 33 additions and 23 deletions

View File

@ -1,14 +1,15 @@
"use client"; "use client";
import { Button } from "../ui/button";
import { AspectRatio } from "../ui/aspect-ratio";
import { DragOverlay } from "../ui/drag-overlay";
import { useMediaStore, type MediaItem } from "@/stores/media-store";
import { processMediaFiles } from "@/lib/media-processing";
import { Plus, Image, Video, Music, Trash2, Upload } from "lucide-react";
import { useDragDrop } from "@/hooks/use-drag-drop"; import { useDragDrop } from "@/hooks/use-drag-drop";
import { processMediaFiles } from "@/lib/media-processing";
import { useMediaStore, type MediaItem } from "@/stores/media-store";
import { useTimelineStore } from "@/stores/timeline-store";
import { Image, Music, Plus, Trash2, Upload, Video } from "lucide-react";
import { useEffect, useRef, useState } from "react"; import { useEffect, useRef, useState } from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { AspectRatio } from "../ui/aspect-ratio";
import { Button } from "../ui/button";
import { DragOverlay } from "../ui/drag-overlay";
// MediaPanel lets users add, view, and drag media (images, videos, audio) into the project. // MediaPanel lets users add, view, and drag media (images, videos, audio) into the project.
// You can upload files or drag them from your computer. Dragging from here to the timeline adds them to your video project. // You can upload files or drag them from your computer. Dragging from here to the timeline adds them to your video project.
@ -58,6 +59,15 @@ export function MediaPanel() {
const handleRemove = (e: React.MouseEvent, id: string) => { const handleRemove = (e: React.MouseEvent, id: string) => {
// Remove a media item from the store // Remove a media item from the store
e.stopPropagation(); e.stopPropagation();
// Remove tracks automatically when delete media
const { tracks, removeTrack } = useTimelineStore.getState();
tracks.forEach((track) => {
if (track.clips.some((clip) => clip.mediaId === id)) {
removeTrack(track.id);
}
});
removeMediaItem(id); removeMediaItem(id);
}; };