improve lots of stuff around the editor

This commit is contained in:
Maze Winther
2025-06-22 22:10:50 +02:00
parent ce49c5ff5f
commit 7e3a80eb74
4 changed files with 59 additions and 25 deletions

View File

@ -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);
},
}));