From 1e19e275408f7f75ddf82517960ff2e29a1a617f Mon Sep 17 00:00:00 2001 From: jeffvli Date: Mon, 13 Sep 2021 21:46:26 -0700 Subject: [PATCH] update drag logic - now consistent when dragging onto a consective selected row --- src/redux/multiSelectSlice.ts | 15 +++++++++++++++ src/redux/playQueueSlice.ts | 18 ++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/redux/multiSelectSlice.ts b/src/redux/multiSelectSlice.ts index 64d2f52..b0cdb90 100644 --- a/src/redux/multiSelectSlice.ts +++ b/src/redux/multiSelectSlice.ts @@ -31,6 +31,21 @@ const multiSelectSlice = createSlice({ name: 'multiSelect', initialState, reducers: { + /* updateSelected: (state, action: PayloadAction) => { + const newSelected: Entry[] = []; + state.selected.map((entry: Entry) => { + const matchedEntry = action.payload.find( + (item: Entry) => item.uniqueId === entry.uniqueId + ); + if (matchedEntry) { + newSelected.push(matchedEntry); + } + return undefined; + }); + + state.selected = newSelected; + }, */ + setIsDragging: (state, action: PayloadAction) => { state.isDragging = action.payload; }, diff --git a/src/redux/playQueueSlice.ts b/src/redux/playQueueSlice.ts index 466d12c..fc91364 100644 --- a/src/redux/playQueueSlice.ts +++ b/src/redux/playQueueSlice.ts @@ -718,15 +718,29 @@ const playQueueSlice = createSlice({ action.payload.moveBeforeId ); + // If the moveBeforeId index is selected, then we find the first consecutive selected index to move to + let firstConesecutiveSelectedDragIndex = -1; + for (let i = spliceIndexPre - 1; i > 0; i -= 1) { + if (uniqueIds.includes(tempQueue[i].uniqueId)) { + firstConesecutiveSelectedDragIndex = i; + } else { + break; + } + } + /* If we get a negative index, don't move the entry. This can happen if you try to drag and drop too fast */ - if (spliceIndexPre < 0 && spliceIndexPost < 0) { + if (spliceIndexPre < 0 && spliceIndexPre < 0) { return; } // Find the slice index to add the selected entries to const spliceIndex = - spliceIndexPost >= 0 ? spliceIndexPost : spliceIndexPre; + spliceIndexPost >= 0 + ? spliceIndexPost + : firstConesecutiveSelectedDragIndex >= 0 + ? firstConesecutiveSelectedDragIndex + : spliceIndexPre; // Sort the entries by their rowIndex so that we can add them in the proper order const sortedEntries = action.payload.entries.sort(