Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix]: fix queue offset when removing tracks #301

Merged
merged 2 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/renderer/features/context-menu/context-menu-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -613,10 +613,12 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
}
}

ctx.tableApi?.redrawRows();

if (isCurrentSongRemoved) {
remote?.updateSong({ song: playerData.current.song });
}
}, [ctx.dataNodes, playerType, removeFromQueue]);
}, [ctx.dataNodes, ctx.tableApi, playerType, removeFromQueue]);

const handleDeselectAll = useCallback(() => {
ctx.tableApi?.deselectAll();
Expand Down
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