[enhancement]: prreserve current song position when shuffling queue
This commit is contained in:
parent
6e677d7454
commit
20b161ee86
1 changed files with 11 additions and 9 deletions
|
@ -935,17 +935,19 @@ export const usePlayerStore = create<PlayerSlice>()(
|
||||||
},
|
},
|
||||||
shuffleQueue: () => {
|
shuffleQueue: () => {
|
||||||
const queue = get().queue.default;
|
const queue = get().queue.default;
|
||||||
const shuffledQueue = shuffle(queue);
|
|
||||||
|
|
||||||
const currentSongUniqueId = get().current.song?.uniqueId;
|
if (queue.length > 2) {
|
||||||
const newCurrentSongIndex = shuffledQueue.findIndex(
|
const index = get().current.index;
|
||||||
(song) => song.uniqueId === currentSongUniqueId,
|
|
||||||
);
|
|
||||||
|
|
||||||
set((state) => {
|
const first = queue.slice(0, index);
|
||||||
state.current.index = newCurrentSongIndex;
|
const second = queue.slice(index + 1);
|
||||||
state.queue.default = shuffledQueue;
|
const shuffledQueue = shuffle(first.concat(second));
|
||||||
});
|
shuffledQueue.splice(index, 0, queue[index]);
|
||||||
|
|
||||||
|
set((state) => {
|
||||||
|
state.queue.default = shuffledQueue;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return get().actions.getPlayerData();
|
return get().actions.getPlayerData();
|
||||||
},
|
},
|
||||||
|
|
Reference in a new issue