fix(queue): random start index when play shuffled center control is enabled, play mode is now, no start specified

This commit is contained in:
Kendall Garner 2025-07-06 21:24:45 -07:00
parent b7a0b7f997
commit a86d44a29e
No known key found for this signature in database
GPG key ID: 9355F387FE765C94

View file

@ -1,5 +1,6 @@
import map from 'lodash/map'; import map from 'lodash/map';
import merge from 'lodash/merge'; import merge from 'lodash/merge';
import random from 'lodash/random';
import shuffle from 'lodash/shuffle'; import shuffle from 'lodash/shuffle';
import { nanoid } from 'nanoid/non-secure'; import { nanoid } from 'nanoid/non-secure';
import { devtools, persist, subscribeWithSelector } from 'zustand/middleware'; import { devtools, persist, subscribeWithSelector } from 'zustand/middleware';
@ -144,8 +145,14 @@ export const usePlayerStore = createWithEqualityFn<PlayerSlice>()(
// If the queue is empty, next/last should behave the same as now // If the queue is empty, next/last should behave the same as now
if (playType === Play.NOW || queue.length === 0) { if (playType === Play.NOW || queue.length === 0) {
const index = initialIndex || 0;
if (get().shuffle === PlayerShuffle.TRACK) { if (get().shuffle === PlayerShuffle.TRACK) {
// If the initial index is specified (double click), use that for
// shuffle start. Otherwise (e.g., big play button), use random start.
const index =
initialIndex !== undefined
? initialIndex
: random(0, songsToAddToQueue.length, false);
const initialSong = songsToAddToQueue[index]; const initialSong = songsToAddToQueue[index];
const queueCopy = [...songsToAddToQueue]; const queueCopy = [...songsToAddToQueue];
@ -172,6 +179,7 @@ export const usePlayerStore = createWithEqualityFn<PlayerSlice>()(
state.current.song = initialSong; state.current.song = initialSong;
}); });
} else { } else {
const index = initialIndex || 0;
set((state) => { set((state) => {
state.queue.default = songsToAddToQueue; state.queue.default = songsToAddToQueue;
state.current.time = 0; state.current.time = 0;