summaryrefslogtreecommitdiff
path: root/apps/web/src/stores
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/stores')
-rw-r--r--apps/web/src/stores/timeline-store.ts18
1 files changed, 17 insertions, 1 deletions
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<TimelineStore>((set) => ({
+export const useTimelineStore = create<TimelineStore>((set, get) => ({
tracks: [],
addTrack: (type) => {
@@ -134,4 +137,17 @@ export const useTimelineStore = create<TimelineStore>((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);
+ },
}));