From 9abb502919135782cc51e82fa8a7154a7fc95a80 Mon Sep 17 00:00:00 2001 From: Sompalkar Date: Mon, 23 Jun 2025 14:43:12 +0530 Subject: fix: delete only selected clip from timeline --- apps/web/src/stores/timeline-store.ts | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'apps/web/src/stores') diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts index 4b56e6bd..c569ae11 100644 --- a/apps/web/src/stores/timeline-store.ts +++ b/apps/web/src/stores/timeline-store.ts @@ -15,6 +15,7 @@ export interface TimelineTrack { name: string; type: "video" | "audio" | "effects"; clips: TimelineClip[]; + muted?: boolean; } interface TimelineStore { @@ -41,6 +42,7 @@ interface TimelineStore { clipId: string, startTime: number ) => void; + toggleTrackMute: (trackId: string) => void; // Computed values getTotalDuration: () => number; @@ -55,6 +57,7 @@ export const useTimelineStore = create((set, get) => ({ name: `${type.charAt(0).toUpperCase() + type.slice(1)} Track`, type, clips: [], + muted: false, }; set((state) => ({ tracks: [...state.tracks, newTrack], @@ -125,8 +128,6 @@ export const useTimelineStore = create((set, get) => ({ }); }, - - updateClipTrim: (trackId, clipId, trimStart, trimEnd) => { set((state) => ({ tracks: state.tracks.map((track) => @@ -134,9 +135,7 @@ export const useTimelineStore = create((set, get) => ({ ? { ...track, clips: track.clips.map((clip) => - clip.id === clipId - ? { ...clip, trimStart, trimEnd } - : clip + clip.id === clipId ? { ...clip, trimStart, trimEnd } : clip ), } : track @@ -151,9 +150,7 @@ export const useTimelineStore = create((set, get) => ({ ? { ...track, clips: track.clips.map((clip) => - clip.id === clipId - ? { ...clip, startTime } - : clip + clip.id === clipId ? { ...clip, startTime } : clip ), } : track @@ -161,13 +158,22 @@ export const useTimelineStore = create((set, get) => ({ })); }, + toggleTrackMute: (trackId) => { + set((state) => ({ + tracks: state.tracks.map((track) => + track.id === trackId ? { ...track, muted: !track.muted } : track + ), + })); + }, + getTotalDuration: () => { const { tracks } = get(); if (tracks.length === 0) return 0; const trackEndTimes = tracks.map((track) => track.clips.reduce((maxEnd, clip) => { - const clipEnd = clip.startTime + clip.duration - clip.trimStart - clip.trimEnd; + const clipEnd = + clip.startTime + clip.duration - clip.trimStart - clip.trimEnd; return Math.max(maxEnd, clipEnd); }, 0) ); -- cgit v1.3.1