refactor: introduce helper function for consistent clip naming with suffixes in timeline store
This commit is contained in:
@ -1,5 +1,20 @@
|
|||||||
import { create } from "zustand";
|
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 {
|
export interface TimelineClip {
|
||||||
id: string;
|
id: string;
|
||||||
mediaId: string;
|
mediaId: string;
|
||||||
@ -319,14 +334,14 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({
|
|||||||
{
|
{
|
||||||
...c,
|
...c,
|
||||||
trimEnd: c.trimEnd + secondDuration,
|
trimEnd: c.trimEnd + secondDuration,
|
||||||
name: c.name + " (left)",
|
name: getClipNameWithSuffix(c.name, "left"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...c,
|
...c,
|
||||||
id: secondClipId,
|
id: secondClipId,
|
||||||
startTime: splitTime,
|
startTime: splitTime,
|
||||||
trimStart: c.trimStart + firstDuration,
|
trimStart: c.trimStart + firstDuration,
|
||||||
name: c.name + " (right)",
|
name: getClipNameWithSuffix(c.name, "right"),
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
: [c]
|
: [c]
|
||||||
@ -369,7 +384,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({
|
|||||||
? {
|
? {
|
||||||
...c,
|
...c,
|
||||||
trimEnd: c.trimEnd + durationToRemove,
|
trimEnd: c.trimEnd + durationToRemove,
|
||||||
name: c.name + " (left)",
|
name: getClipNameWithSuffix(c.name, "left"),
|
||||||
}
|
}
|
||||||
: c
|
: c
|
||||||
),
|
),
|
||||||
@ -408,7 +423,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({
|
|||||||
...c,
|
...c,
|
||||||
startTime: splitTime,
|
startTime: splitTime,
|
||||||
trimStart: c.trimStart + relativeTime,
|
trimStart: c.trimStart + relativeTime,
|
||||||
name: c.name + " (right)",
|
name: getClipNameWithSuffix(c.name, "right"),
|
||||||
}
|
}
|
||||||
: c
|
: c
|
||||||
),
|
),
|
||||||
@ -458,7 +473,7 @@ export const useTimelineStore = create<TimelineStore>((set, get) => ({
|
|||||||
{
|
{
|
||||||
...clip,
|
...clip,
|
||||||
id: audioClipId,
|
id: audioClipId,
|
||||||
name: clip.name + " (audio)",
|
name: getClipNameWithSuffix(clip.name, "audio"),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user