mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
[enhancement]: prreserve current song position when shuffling queue
This commit is contained in:
@@ -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 New Issue
Block a user