summaryrefslogtreecommitdiff
path: root/apps/web
diff options
context:
space:
mode:
authorDevloperAmanSingh <amansinghneh211205@gmail.com>2025-06-27 00:07:47 +0530
committerDevloperAmanSingh <amansinghneh211205@gmail.com>2025-06-27 00:07:47 +0530
commit6262f2b3797623cc1b62c82a8e810ad3aaf1d2b1 (patch)
tree0f753ad45b5180061f86a250778b591cecd8fd86 /apps/web
parent3f0fe9d20e85a10e8615fd868e9ff8222dba0c29 (diff)
downloadopencut-6262f2b3797623cc1b62c82a8e810ad3aaf1d2b1.tar.gz
refactor: introduce helper function for consistent clip naming with suffixes in timeline store
Diffstat (limited to 'apps/web')
-rw-r--r--apps/web/src/stores/timeline-store.ts25
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"),
},
],
}