Skip to content

Commit

Permalink
[bugfix]: fix queue offset when removing tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 committed Oct 13, 2023
1 parent 3675146 commit 2342248
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions src/renderer/store/player.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,10 +631,17 @@ export const usePlayerStore = create<PlayerSlice>()(
removeFromQueue: (uniqueIds) => {
const queue = get().queue.default;
const currentSong = get().current.song;
const currentPosition = get().current.index;
let queueShift = 0;

const newQueue = queue.filter(
(song) => !uniqueIds.includes(song.uniqueId),
);
const newQueue = queue.filter((song, index) => {
const shouldKeep = !uniqueIds.includes(song.uniqueId);
if (!shouldKeep && index < currentPosition) {
queueShift += 1;
}

return shouldKeep;
});
const newShuffledQueue = get().queue.shuffled.filter(
(uniqueId) => !uniqueIds.includes(uniqueId),
);
Expand All @@ -648,6 +655,10 @@ export const usePlayerStore = create<PlayerSlice>()(
if (isCurrentSongRemoved) {
state.current.song = newQueue[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;
}
});

Expand Down

0 comments on commit 2342248

Please sign in to comment.