re-implement shuffle play type

This commit is contained in:
jeffvli
2025-11-14 17:58:56 -08:00
parent b6c3200419
commit 3d4f35e881
+49
View File
@@ -199,6 +199,29 @@ export const usePlayerStoreBase = create<PlayerState>()(
}
});
break;
}
case Play.SHUFFLE: {
set((state) => {
// Add new songs to songs object
newItems.forEach((item) => {
state.queue.songs[item._uniqueId] = item;
});
// Shuffle the new items before adding to queue
const shuffledIds = shuffleInPlace([...newUniqueIds]);
state.queue.default = [];
state.player.index = 0;
state.player.status = PlayerStatus.PLAYING;
state.player.playerNum = 1;
state.player.timestamp = 0;
state.queue.default = shuffledIds;
// Always maintain shuffled array when using Play.SHUFFLE
state.queue.shuffled = shuffleInPlace([...shuffledIds]);
});
break;
}
}
@@ -331,6 +354,32 @@ export const usePlayerStoreBase = create<PlayerState>()(
});
break;
}
case Play.SHUFFLE: {
set((state) => {
// Add new songs to songs object
newItems.forEach((item) => {
state.queue.songs[item._uniqueId] = item;
});
// Shuffle the new items before adding to queue
const shuffledIds = shuffleInPlace([...newUniqueIds]);
state.queue.default = [];
state.queue.priority = [];
state.player.index = 0;
state.player.status = PlayerStatus.PLAYING;
state.player.playerNum = 1;
state.player.timestamp = 0;
// Add first item to priority queue, rest to default
state.queue.priority = [shuffledIds[0]];
state.queue.default = shuffledIds.slice(1);
// Always maintain shuffled array when using Play.SHUFFLE
state.queue.shuffled = shuffleInPlace([...shuffledIds]);
});
break;
}
}
break;
}