Skip to content

Commit

Permalink
[bugfix]: fix queue offset when removing tracks (#301)
Browse files Browse the repository at this point in the history
* [bugfix]: fix queue offset when removing tracks

* Fix song index numbers when removing songs

---------

Co-authored-by: jeffvli <[email protected]>
  • Loading branch information
kgarner7 and jeffvli authored Oct 22, 2023
1 parent 3a144ab commit e6ed922
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
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

1 comment on commit e6ed922

@vercel
Copy link

@vercel vercel bot commented on e6ed922 Oct 22, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feishin – ./

feishin.vercel.app
feishin-jeffvli.vercel.app
feishin-git-development-jeffvli.vercel.app

Please sign in to comment.