mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 12:30:12 +02:00
add more shuffle play modes
This commit is contained in:
@@ -47,6 +47,14 @@ export const PlayAction = ({ ids, itemType, songs }: PlayActionProps) => {
|
||||
handlePlay(Play.SHUFFLE);
|
||||
}, [handlePlay]);
|
||||
|
||||
const handlePlayNextShuffled = useCallback(() => {
|
||||
handlePlay(Play.NEXT_SHUFFLE);
|
||||
}, [handlePlay]);
|
||||
|
||||
const handlePlayLastShuffled = useCallback(() => {
|
||||
handlePlay(Play.LAST_SHUFFLE);
|
||||
}, [handlePlay]);
|
||||
|
||||
const playButtonBehavior = usePlayButtonBehavior();
|
||||
|
||||
const defaultPlayAction = useCallback(() => {
|
||||
@@ -76,9 +84,16 @@ export const PlayAction = ({ ids, itemType, songs }: PlayActionProps) => {
|
||||
<ContextMenu.Item leftIcon="mediaPlayLast" onSelect={handlePlayLast}>
|
||||
{t('player.addLast', { postProcess: 'sentenceCase' })}
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Divider />
|
||||
<ContextMenu.Item leftIcon="mediaShuffle" onSelect={handlePlayShuffled}>
|
||||
{t('player.shuffle', { postProcess: 'sentenceCase' })}
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item leftIcon="mediaPlayNext" onSelect={handlePlayNextShuffled}>
|
||||
{t('player.addNextShuffled', { postProcess: 'sentenceCase' })}
|
||||
</ContextMenu.Item>
|
||||
<ContextMenu.Item leftIcon="mediaPlayLast" onSelect={handlePlayLastShuffled}>
|
||||
{t('player.addLastShuffled', { postProcess: 'sentenceCase' })}
|
||||
</ContextMenu.Item>
|
||||
</ContextMenu.SubmenuContent>
|
||||
</ContextMenu.Submenu>
|
||||
);
|
||||
|
||||
@@ -160,6 +160,34 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.LAST_SHUFFLE: {
|
||||
set((state) => {
|
||||
const currentIndex = state.player.index;
|
||||
newItems.forEach((item) => {
|
||||
state.queue.songs[item._uniqueId] = item;
|
||||
});
|
||||
|
||||
// Shuffle the new items before appending
|
||||
const shuffledIds = shuffleInPlace([...newUniqueIds]);
|
||||
|
||||
state.queue.default = [
|
||||
...state.queue.default,
|
||||
...shuffledIds,
|
||||
];
|
||||
|
||||
if (state.player.shuffle === PlayerShuffle.TRACK) {
|
||||
state.queue.shuffled = [
|
||||
...state.queue.shuffled.slice(0, currentIndex),
|
||||
state.queue.shuffled[currentIndex],
|
||||
...shuffleInPlace([
|
||||
...state.queue.shuffled.slice(currentIndex + 1),
|
||||
...shuffledIds,
|
||||
]),
|
||||
];
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NEXT: {
|
||||
set((state) => {
|
||||
const currentIndex = state.player.index;
|
||||
@@ -186,6 +214,35 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NEXT_SHUFFLE: {
|
||||
set((state) => {
|
||||
const currentIndex = state.player.index;
|
||||
newItems.forEach((item) => {
|
||||
state.queue.songs[item._uniqueId] = item;
|
||||
});
|
||||
|
||||
// Shuffle the new items before inserting
|
||||
const shuffledIds = shuffleInPlace([...newUniqueIds]);
|
||||
|
||||
state.queue.default = [
|
||||
...state.queue.default.slice(0, currentIndex + 1),
|
||||
...shuffledIds,
|
||||
...state.queue.default.slice(currentIndex + 1),
|
||||
];
|
||||
|
||||
if (state.player.shuffle === PlayerShuffle.TRACK) {
|
||||
state.queue.shuffled = [
|
||||
...state.queue.shuffled.slice(0, currentIndex),
|
||||
state.queue.shuffled[currentIndex],
|
||||
...shuffleInPlace([
|
||||
...state.queue.shuffled.slice(currentIndex + 1),
|
||||
...shuffledIds,
|
||||
]),
|
||||
];
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NOW: {
|
||||
set((state) => {
|
||||
newItems.forEach((item) => {
|
||||
@@ -252,6 +309,28 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.LAST_SHUFFLE: {
|
||||
set((state) => {
|
||||
// Add new songs to songs object
|
||||
newItems.forEach((item) => {
|
||||
state.queue.songs[item._uniqueId] = item;
|
||||
});
|
||||
|
||||
// Shuffle the new items before appending
|
||||
const shuffledIds = shuffleInPlace([...newUniqueIds]);
|
||||
|
||||
state.queue.priority = [
|
||||
...state.queue.priority,
|
||||
...shuffledIds,
|
||||
];
|
||||
|
||||
state.queue.shuffled = [
|
||||
...state.queue.shuffled,
|
||||
...shuffledIds,
|
||||
];
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NEXT: {
|
||||
set((state) => {
|
||||
const currentIndex = state.player.index;
|
||||
@@ -287,6 +366,44 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NEXT_SHUFFLE: {
|
||||
set((state) => {
|
||||
const currentIndex = state.player.index;
|
||||
const isInPriority =
|
||||
currentIndex < state.queue.priority.length;
|
||||
|
||||
// Add new songs to songs object
|
||||
newItems.forEach((item) => {
|
||||
state.queue.songs[item._uniqueId] = item;
|
||||
});
|
||||
|
||||
// Shuffle the new items before inserting
|
||||
const shuffledIds = shuffleInPlace([...newUniqueIds]);
|
||||
|
||||
if (isInPriority) {
|
||||
state.queue.priority = [
|
||||
...state.queue.priority.slice(0, currentIndex + 1),
|
||||
...shuffledIds,
|
||||
...state.queue.priority.slice(currentIndex + 1),
|
||||
];
|
||||
} else {
|
||||
state.queue.priority = [
|
||||
...state.queue.priority,
|
||||
...shuffledIds,
|
||||
];
|
||||
}
|
||||
|
||||
state.queue.shuffled = [
|
||||
...state.queue.shuffled.slice(0, currentIndex),
|
||||
state.queue.shuffled[currentIndex],
|
||||
...shuffleInPlace([
|
||||
...state.queue.shuffled.slice(currentIndex + 1),
|
||||
...shuffledIds,
|
||||
]),
|
||||
];
|
||||
});
|
||||
break;
|
||||
}
|
||||
case Play.NOW: {
|
||||
set((state) => {
|
||||
// Add new songs to songs object
|
||||
|
||||
Reference in New Issue
Block a user