Browse Source

update drag logic

- now consistent when dragging onto a consective selected row
master
jeffvli 3 years ago
parent
commit
1e19e27540
  1. 15
      src/redux/multiSelectSlice.ts
  2. 18
      src/redux/playQueueSlice.ts

15
src/redux/multiSelectSlice.ts

@ -31,6 +31,21 @@ const multiSelectSlice = createSlice({
name: 'multiSelect',
initialState,
reducers: {
/* updateSelected: (state, action: PayloadAction<Entry[]>) => {
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<boolean>) => {
state.isDragging = action.payload;
},

18
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(

Loading…
Cancel
Save