diff options
| author | DevloperAmanSingh <amansinghneh211205@gmail.com> | 2025-06-27 00:07:47 +0530 |
|---|---|---|
| committer | DevloperAmanSingh <amansinghneh211205@gmail.com> | 2025-06-27 00:07:47 +0530 |
| commit | 6262f2b3797623cc1b62c82a8e810ad3aaf1d2b1 (patch) | |
| tree | 0f753ad45b5180061f86a250778b591cecd8fd86 | |
| parent | 3f0fe9d20e85a10e8615fd868e9ff8222dba0c29 (diff) | |
| download | opencut-6262f2b3797623cc1b62c82a8e810ad3aaf1d2b1.tar.gz | |
refactor: introduce helper function for consistent clip naming with suffixes in timeline store
| -rw-r--r-- | apps/web/src/stores/timeline-store.ts | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts index f789548f..dd97879f 100644 --- a/apps/web/src/stores/timeline-store.ts +++ b/apps/web/src/stores/timeline-store.ts @@ -1,5 +1,20 @@ import { create } from "zustand"; +// Helper function to manage clip naming with suffixes +const getClipNameWithSuffix = ( + originalName: string, + suffix: string +): string => { + // Remove existing suffixes to prevent accumulation + const baseName = originalName + .replace(/ \(left\)$/, "") + .replace(/ \(right\)$/, "") + .replace(/ \(audio\)$/, "") + .replace(/ \(split \d+\)$/, ""); + + return `${baseName} (${suffix})`; +}; + export interface TimelineClip { id: string; mediaId: string; @@ -319,14 +334,14 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({ { ...c, trimEnd: c.trimEnd + secondDuration, - name: c.name + " (left)", + name: getClipNameWithSuffix(c.name, "left"), }, { ...c, id: secondClipId, startTime: splitTime, trimStart: c.trimStart + firstDuration, - name: c.name + " (right)", + name: getClipNameWithSuffix(c.name, "right"), }, ] : [c] @@ -369,7 +384,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({ ? { ...c, trimEnd: c.trimEnd + durationToRemove, - name: c.name + " (left)", + name: getClipNameWithSuffix(c.name, "left"), } : c ), @@ -408,7 +423,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({ ...c, startTime: splitTime, trimStart: c.trimStart + relativeTime, - name: c.name + " (right)", + name: getClipNameWithSuffix(c.name, "right"), } : c ), @@ -458,7 +473,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({ { ...clip, id: audioClipId, - name: clip.name + " (audio)", + name: getClipNameWithSuffix(clip.name, "audio"), }, ], } |
