diff options
| author | iza <59828082+izadoesdev@users.noreply.github.com> | 2025-06-23 19:10:18 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-23 19:10:18 +0300 |
| commit | fddbecc736a037b938385eb5eb7d1ec752581c76 (patch) | |
| tree | 5f9cae6fb7466973552409c848fa037f30d01ea7 /apps/web/src/stores/timeline-store.ts | |
| parent | 13817a5ff847762a3ac4eb7cb09d17012b59e520 (diff) | |
| parent | e1ffb97be6db8396442fa9f0c42d41b85f597f8c (diff) | |
| download | opencut-fddbecc736a037b938385eb5eb7d1ec752581c76.tar.gz | |
Merge pull request #18 from aashishparuvada/main
enabled-multiclip-selection-and-deselection
Diffstat (limited to 'apps/web/src/stores/timeline-store.ts')
| -rw-r--r-- | apps/web/src/stores/timeline-store.ts | 39 |
1 files changed, 30 insertions, 9 deletions
diff --git a/apps/web/src/stores/timeline-store.ts b/apps/web/src/stores/timeline-store.ts index ea6fc35e..4b55a53d 100644 --- a/apps/web/src/stores/timeline-store.ts +++ b/apps/web/src/stores/timeline-store.ts @@ -21,10 +21,12 @@ export interface TimelineTrack { interface TimelineStore {
tracks: TimelineTrack[];
- // Selection
- selectedClip: { trackId: string; clipId: string } | null;
- selectClip: (trackId: string, clipId: string) => void;
- clearSelectedClip: () => void;
+ // Multi-selection
+ selectedClips: { trackId: string; clipId: string }[];
+ selectClip: (trackId: string, clipId: string, multi?: boolean) => void;
+ deselectClip: (trackId: string, clipId: string) => void;
+ clearSelectedClips: () => void;
+ setSelectedClips: (clips: { trackId: string; clipId: string }[]) => void;
// Actions
addTrack: (type: "video" | "audio" | "effects") => string;
@@ -55,15 +57,34 @@ interface TimelineStore { export const useTimelineStore = create<TimelineStore>((set, get) => ({
tracks: [],
- selectedClip: null,
+ selectedClips: [],
- selectClip: (trackId, clipId) => {
- set({ selectedClip: { trackId, clipId } });
+ selectClip: (trackId, clipId, multi = false) => {
+ set((state) => {
+ const exists = state.selectedClips.some(
+ (c) => c.trackId === trackId && c.clipId === clipId
+ );
+ if (multi) {
+ // Toggle selection
+ return exists
+ ? { selectedClips: state.selectedClips.filter((c) => !(c.trackId === trackId && c.clipId === clipId)) }
+ : { selectedClips: [...state.selectedClips, { trackId, clipId }] };
+ } else {
+ return { selectedClips: [{ trackId, clipId }] };
+ }
+ });
+ },
+ deselectClip: (trackId, clipId) => {
+ set((state) => ({
+ selectedClips: state.selectedClips.filter((c) => !(c.trackId === trackId && c.clipId === clipId)),
+ }));
},
- clearSelectedClip: () => {
- set({ selectedClip: null });
+ clearSelectedClips: () => {
+ set({ selectedClips: [] });
},
+ setSelectedClips: (clips) => set({ selectedClips: clips }),
+
addTrack: (type) => {
const newTrack: TimelineTrack = {
id: crypto.randomUUID(),
|
