Browse Source

Add move to index for playlist view

master
jeffvli 3 years ago
parent
commit
4e6305411c
  1. 5
      src/components/playlist/PlaylistView.tsx
  2. 32
      src/components/shared/ContextMenu.tsx
  3. 7
      src/redux/playlistSlice.ts

5
src/components/playlist/PlaylistView.tsx

@ -244,7 +244,10 @@ const PlaylistView = ({ ...rest }) => {
const handleDragEnd = () => { const handleDragEnd = () => {
if (multiSelect.isDragging) { if (multiSelect.isDragging) {
dispatch( dispatch(
moveToIndex({ entries: multiSelect.selected, moveBeforeId: multiSelect.currentMouseOverId }) moveToIndex({
selectedEntries: multiSelect.selected,
moveBeforeId: multiSelect.currentMouseOverId,
})
); );
dispatch(setIsDragging(false)); dispatch(setIsDragging(false));
} }

32
src/components/shared/ContextMenu.tsx

@ -29,6 +29,7 @@ import {
setStar, setStar,
} from '../../redux/playQueueSlice'; } from '../../redux/playQueueSlice';
import { import {
moveToIndex as plMoveToIndex,
moveToBottom as plMoveToBottom, moveToBottom as plMoveToBottom,
moveToTop as plMoveToTop, moveToTop as plMoveToTop,
moveUp as plMoveUp, moveUp as plMoveUp,
@ -88,6 +89,7 @@ export const GlobalContextMenu = () => {
const history = useHistory(); const history = useHistory();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const queryClient = useQueryClient(); const queryClient = useQueryClient();
const playlist = useAppSelector((state) => state.playlist);
const playQueue = useAppSelector((state) => state.playQueue); const playQueue = useAppSelector((state) => state.playQueue);
const misc = useAppSelector((state) => state.misc); const misc = useAppSelector((state) => state.misc);
const multiSelect = useAppSelector((state) => state.multiSelect); const multiSelect = useAppSelector((state) => state.multiSelect);
@ -242,10 +244,21 @@ export const GlobalContextMenu = () => {
}; };
const handleMoveSelectedToIndex = () => { const handleMoveSelectedToIndex = () => {
const currentEntryList = getCurrentEntryList(playQueue); if (misc.contextMenu.type === 'nowPlaying') {
const uniqueIdOfIndexToMoveTo = playQueue[currentEntryList][indexToMoveTo].uniqueId; const currentEntryList = getCurrentEntryList(playQueue);
const uniqueIdOfIndexToMoveTo = playQueue[currentEntryList][indexToMoveTo].uniqueId;
dispatch(moveToIndex({ entries: multiSelect.selected, moveBeforeId: uniqueIdOfIndexToMoveTo })); dispatch(
moveToIndex({ entries: multiSelect.selected, moveBeforeId: uniqueIdOfIndexToMoveTo })
);
} else {
const uniqueIdOfIndexToMoveTo = playlist.entry[indexToMoveTo].uniqueId;
dispatch(
plMoveToIndex({
selectedEntries: multiSelect.selected,
moveBeforeId: uniqueIdOfIndexToMoveTo,
})
);
}
}; };
const handleMoveToTop = () => { const handleMoveToTop = () => {
@ -417,7 +430,11 @@ export const GlobalContextMenu = () => {
<StyledInputNumber <StyledInputNumber
defaultValue={0} defaultValue={0}
min={0} min={0}
max={playQueue[getCurrentEntryList(playQueue)].length} max={
misc.contextMenu.type === 'nowPlaying'
? playQueue[getCurrentEntryList(playQueue)].length
: playlist.entry.length
}
value={indexToMoveTo} value={indexToMoveTo}
onChange={(e: number) => setIndexToMoveTo(e)} onChange={(e: number) => setIndexToMoveTo(e)}
/> />
@ -425,8 +442,9 @@ export const GlobalContextMenu = () => {
type="submit" type="submit"
onClick={handleMoveSelectedToIndex} onClick={handleMoveSelectedToIndex}
disabled={ disabled={
indexToMoveTo > playQueue[getCurrentEntryList(playQueue)].length || (misc.contextMenu.type === 'nowPlaying'
indexToMoveTo < 0 ? indexToMoveTo > playQueue[getCurrentEntryList(playQueue)].length
: indexToMoveTo > playlist.entry.length) || indexToMoveTo < 0
} }
> >
Go Go

7
src/redux/playlistSlice.ts

@ -30,10 +30,13 @@ const playlistSlice = createSlice({
state.entry = state.entry.filter((entry) => !uniqueIds.includes(entry.uniqueId)); state.entry = state.entry.filter((entry) => !uniqueIds.includes(entry.uniqueId));
}, },
moveToIndex: (state, action: PayloadAction<{ entries: Entry[]; moveBeforeId: string }>) => { moveToIndex: (
state,
action: PayloadAction<{ selectedEntries: Entry[]; moveBeforeId: string }>
) => {
state.entry = moveSelectedToIndex( state.entry = moveSelectedToIndex(
state.entry, state.entry,
action.payload.entries, action.payload.selectedEntries,
action.payload.moveBeforeId action.payload.moveBeforeId
); );
}, },

Loading…
Cancel
Save