summaryrefslogtreecommitdiff
path: root/apps/web/src/stores/timeline-store.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/stores/timeline-store.ts')
-rw-r--r--apps/web/src/stores/timeline-store.ts58
1 files changed, 28 insertions, 30 deletions
diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts
index f21a4d57..01ad1635 100644
--- a/apps/web/src/stores/timeline-store.ts
+++ b/apps/web/src/stores/timeline-store.ts
@@ -106,17 +106,20 @@ interface TimelineStore {
trackId: string,
elementId: string,
trimStart: number,
- trimEnd: number
+ trimEnd: number,
+ pushHistory?: boolean
) => void;
updateElementDuration: (
trackId: string,
elementId: string,
- duration: number
+ duration: number,
+ pushHistory?: boolean
) => void;
updateElementStartTime: (
trackId: string,
elementId: string,
- startTime: number
+ startTime: number,
+ pushHistory?: boolean
) => void;
toggleTrackMute: (trackId: string) => void;
@@ -158,8 +161,6 @@ interface TimelineStore {
// Computed values
getTotalDuration: () => number;
- getContentWidth: (zoomLevel: number) => number;
- calculateFitToWindowZoom: (containerWidth: number) => number;
// History actions
undo: () => void;
@@ -689,8 +690,14 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
updateTracksAndSave(newTracks);
},
- updateElementTrim: (trackId, elementId, trimStart, trimEnd) => {
- get().pushHistory();
+ updateElementTrim: (
+ trackId,
+ elementId,
+ trimStart,
+ trimEnd,
+ pushHistory = true
+ ) => {
+ if (pushHistory) get().pushHistory();
updateTracksAndSave(
get()._tracks.map((track) =>
track.id === trackId
@@ -707,8 +714,13 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
);
},
- updateElementDuration: (trackId, elementId, duration) => {
- get().pushHistory();
+ updateElementDuration: (
+ trackId,
+ elementId,
+ duration,
+ pushHistory = true
+ ) => {
+ if (pushHistory) get().pushHistory();
updateTracksAndSave(
get()._tracks.map((track) =>
track.id === trackId
@@ -723,8 +735,13 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
);
},
- updateElementStartTime: (trackId, elementId, startTime) => {
- get().pushHistory();
+ updateElementStartTime: (
+ trackId,
+ elementId,
+ startTime,
+ pushHistory = true
+ ) => {
+ if (pushHistory) get().pushHistory();
updateTracksAndSave(
get()._tracks.map((track) =>
track.id === trackId
@@ -1159,25 +1176,6 @@ export const useTimelineStore = create<TimelineStore>((set, get) => {
return Math.max(...trackEndTimes, 0);
},
- getContentWidth: (zoomLevel: number) => {
- const totalDuration = get().getTotalDuration();
- return totalDuration * TIMELINE_CONSTANTS.PIXELS_PER_SECOND * zoomLevel;
- },
-
- calculateFitToWindowZoom: (containerWidth: number) => {
- const totalDuration = get().getTotalDuration();
- if (totalDuration === 0) return 1;
-
- // Leave some padding (10% on each side)
- const CONTAINER_PADDING_FACTOR = 0.8;
- const availableWidth = containerWidth * CONTAINER_PADDING_FACTOR;
- const requiredWidth = totalDuration * TIMELINE_CONSTANTS.PIXELS_PER_SECOND;
- const calculatedZoom = availableWidth / requiredWidth;
-
- // Clamp between min and max zoom levels
- return Math.max(TIMELINE_CONSTANTS.MIN_ZOOM, Math.min(TIMELINE_CONSTANTS.MAX_ZOOM, calculatedZoom));
- },
-
redo: () => {
const { redoStack } = get();
if (redoStack.length === 0) return;