mirror of
https://github.com/jeffvli/feishin.git
synced 2026-06-17 00:44:23 +02:00
always set start song index to 0 when adding to queue in shuffle mode
This commit is contained in:
@@ -462,9 +462,40 @@ export const usePlayerStoreBase = createWithEqualityFn<PlayerState>()(
|
|||||||
state.player.shuffle === PlayerShuffle.TRACK &&
|
state.player.shuffle === PlayerShuffle.TRACK &&
|
||||||
state.player.queueType !== PlayerQueueType.PRIORITY
|
state.player.queueType !== PlayerQueueType.PRIORITY
|
||||||
) {
|
) {
|
||||||
state.queue.shuffled = generateShuffledIndexes(
|
// If targetSongUniqueId is provided, ensure it's at position 0 in shuffled array
|
||||||
newUniqueIds.length,
|
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,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user