fix: Only remove track if it becomes empty and has no other clips

This commit is contained in:
priyankarpal
2025-06-26 21:41:26 +05:30
parent f76555dae5
commit fff95afbc6

View File

@ -64,7 +64,13 @@ export function MediaPanel() {
// Remove tracks automatically when delete media
const { tracks, removeTrack } = useTimelineStore.getState();
tracks.forEach((track) => {
if (track.clips.some((clip) => clip.mediaId === id)) {
const clipsToRemove = track.clips.filter((clip) => clip.mediaId === id);
clipsToRemove.forEach((clip) => {
useTimelineStore.getState().removeClipFromTrack(track.id, clip.id);
});
// Only remove track if it becomes empty and has no other clips
const updatedTrack = useTimelineStore.getState().tracks.find(t => t.id === track.id);
if (updatedTrack && updatedTrack.clips.length === 0) {
removeTrack(track.id);
}
});