From 7e3a80eb74af23a36cfff43aa61175e1630222e1 Mon Sep 17 00:00:00 2001 From: Maze Winther Date: Sun, 22 Jun 2025 22:10:50 +0200 Subject: improve lots of stuff around the editor --- apps/web/src/stores/timeline-store.ts | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (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 243ed220..12129afa 100644 --- a/apps/web/src/stores/timeline-store.ts +++ b/apps/web/src/stores/timeline-store.ts @@ -33,9 +33,12 @@ interface TimelineStore { clipId: string, newIndex: number ) => void; + + // Computed values + getTotalDuration: () => number; } -export const useTimelineStore = create((set) => ({ +export const useTimelineStore = create((set, get) => ({ tracks: [], addTrack: (type) => { @@ -134,4 +137,17 @@ export const useTimelineStore = create((set) => ({ }), })); }, + + getTotalDuration: () => { + const { tracks } = get(); + if (tracks.length === 0) return 0; + + // Calculate the duration of each track (sum of all clips in that track) + const trackDurations = tracks.map((track) => + track.clips.reduce((total, clip) => total + clip.duration, 0) + ); + + // Return the maximum track duration (longest track determines project duration) + return Math.max(...trackDurations, 0); + }, })); -- cgit v1.3.1