mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 18:13:31 +00:00
fix(queue): random start index when play shuffled center control is enabled, play mode is now, no start specified
This commit is contained in:
parent
b7a0b7f997
commit
a86d44a29e
1 changed files with 9 additions and 1 deletions
|
|
@ -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;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue