fix(player): handle items in the queue moved to next before current index

This commit is contained in:
Kendall Garner
2026-03-02 20:05:01 -08:00
parent 14e1f1d003
commit 2854b928f6
+15 -5
View File
@@ -1238,14 +1238,24 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
});
const currentIndex = state.player.index;
const filtered = state.queue.default.filter(
(id) => !uniqueIds.includes(id),
);
let beforeCurrent = 0;
const filtered = state.queue.default.filter((id, idx) => {
const shouldMove = uniqueIds.includes(id);
if (shouldMove && idx < currentIndex) {
beforeCurrent++;
}
return !shouldMove;
});
// For every item that is before the current item, subtract one as
// these items will shift the queue up
const insertIndex = currentIndex + 1 - beforeCurrent;
const newQueue = [
...filtered.slice(0, currentIndex + 1),
...filtered.slice(0, insertIndex),
...uniqueIds,
...filtered.slice(currentIndex + 1),
...filtered.slice(insertIndex),
];
recalculatePlayerIndex(state, newQueue);