always set start song index to 0 when adding to queue in shuffle mode

This commit is contained in:
jeffvli
2025-12-10 19:34:59 -08:00
parent c1ea39aa14
commit 10aec7bcac
+34 -3
View File
@@ -462,9 +462,40 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
state.player.shuffle === PlayerShuffle.TRACK &&
state.player.queueType !== PlayerQueueType.PRIORITY
) {
state.queue.shuffled = generateShuffledIndexes(
newUniqueIds.length,
);
// If targetSongUniqueId is provided, ensure it's at position 0 in shuffled array
if (targetSongUniqueId) {
const initialIndex = newUniqueIds.findIndex(
(id) => id === targetSongUniqueId,
);
if (initialIndex !== -1) {
const allIndexes = Array.from(
{ length: newUniqueIds.length },
(_, i) => i,
);
const remainingIndexes = allIndexes.filter(
(idx) => idx !== initialIndex,
);
const shuffledRemaining = shuffleInPlace([
...remainingIndexes,
]);
state.queue.shuffled = [
initialIndex,
...shuffledRemaining,
];
} else {
// Fallback: if initial song not found, generate normally
state.queue.shuffled = generateShuffledIndexes(
newUniqueIds.length,
);
}
} else {
state.queue.shuffled = generateShuffledIndexes(
newUniqueIds.length,
);
}
}
});