[bugfix]: fix queue offset when removing tracks (#301)
* [bugfix]: fix queue offset when removing tracks * Fix song index numbers when removing songs --------- Co-authored-by: jeffvli <jeffvictorli@gmail.com>
This commit is contained in:
parent
3a144ab821
commit
e6ed9229c2
2 changed files with 17 additions and 4 deletions
|
@ -613,10 +613,12 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ctx.tableApi?.redrawRows();
|
||||||
|
|
||||||
if (isCurrentSongRemoved) {
|
if (isCurrentSongRemoved) {
|
||||||
remote?.updateSong({ song: playerData.current.song });
|
remote?.updateSong({ song: playerData.current.song });
|
||||||
}
|
}
|
||||||
}, [ctx.dataNodes, playerType, removeFromQueue]);
|
}, [ctx.dataNodes, ctx.tableApi, playerType, removeFromQueue]);
|
||||||
|
|
||||||
const handleDeselectAll = useCallback(() => {
|
const handleDeselectAll = useCallback(() => {
|
||||||
ctx.tableApi?.deselectAll();
|
ctx.tableApi?.deselectAll();
|
||||||
|
|
|
@ -631,10 +631,17 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
removeFromQueue: (uniqueIds) => {
|
removeFromQueue: (uniqueIds) => {
|
||||||
const queue = get().queue.default;
|
const queue = get().queue.default;
|
||||||
const currentSong = get().current.song;
|
const currentSong = get().current.song;
|
||||||
|
const currentPosition = get().current.index;
|
||||||
|
let queueShift = 0;
|
||||||
|
|
||||||
const newQueue = queue.filter(
|
const newQueue = queue.filter((song, index) => {
|
||||||
(song) => !uniqueIds.includes(song.uniqueId),
|
const shouldKeep = !uniqueIds.includes(song.uniqueId);
|
||||||
);
|
if (!shouldKeep && index < currentPosition) {
|
||||||
|
queueShift += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shouldKeep;
|
||||||
|
});
|
||||||
const newShuffledQueue = get().queue.shuffled.filter(
|
const newShuffledQueue = get().queue.shuffled.filter(
|
||||||
(uniqueId) => !uniqueIds.includes(uniqueId),
|
(uniqueId) => !uniqueIds.includes(uniqueId),
|
||||||
);
|
);
|
||||||
|
@ -648,6 +655,10 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
if (isCurrentSongRemoved) {
|
if (isCurrentSongRemoved) {
|
||||||
state.current.song = newQueue[0];
|
state.current.song = newQueue[0];
|
||||||
state.current.index = 0;
|
state.current.index = 0;
|
||||||
|
} else {
|
||||||
|
// if we removed any songs prior to the current one,
|
||||||
|
// shift the index back as necessary
|
||||||
|
state.current.index -= queueShift;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Reference in a new issue