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', name: 'multiSelect',
initialState, initialState,
reducers: { 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>) => { setIsDragging: (state, action: PayloadAction<boolean>) => {
state.isDragging = action.payload; state.isDragging = action.payload;
}, },

18
src/redux/playQueueSlice.ts

@ -718,15 +718,29 @@ const playQueueSlice = createSlice({
action.payload.moveBeforeId 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. /* If we get a negative index, don't move the entry.
This can happen if you try to drag and drop too fast */ This can happen if you try to drag and drop too fast */
if (spliceIndexPre < 0 && spliceIndexPost < 0) { if (spliceIndexPre < 0 && spliceIndexPre < 0) {
return; return;
} }
// Find the slice index to add the selected entries to // Find the slice index to add the selected entries to
const spliceIndex = 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 // Sort the entries by their rowIndex so that we can add them in the proper order
const sortedEntries = action.payload.entries.sort( const sortedEntries = action.payload.entries.sort(

Loading…
Cancel
Save