mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
fix(player): handle items in the queue moved to next before current index
This commit is contained in:
@@ -1238,14 +1238,24 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
});
|
});
|
||||||
|
|
||||||
const currentIndex = state.player.index;
|
const currentIndex = state.player.index;
|
||||||
const filtered = state.queue.default.filter(
|
let beforeCurrent = 0;
|
||||||
(id) => !uniqueIds.includes(id),
|
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 = [
|
const newQueue = [
|
||||||
...filtered.slice(0, currentIndex + 1),
|
...filtered.slice(0, insertIndex),
|
||||||
...uniqueIds,
|
...uniqueIds,
|
||||||
...filtered.slice(currentIndex + 1),
|
...filtered.slice(insertIndex),
|
||||||
];
|
];
|
||||||
|
|
||||||
recalculatePlayerIndex(state, newQueue);
|
recalculatePlayerIndex(state, newQueue);
|
||||||
|
|||||||
Reference in New Issue
Block a user