mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-10 04:30:25 +02:00
add more shuffle play modes
This commit is contained in:
@@ -485,6 +485,8 @@
|
|||||||
"player": {
|
"player": {
|
||||||
"addLast": "add last",
|
"addLast": "add last",
|
||||||
"addNext": "add next",
|
"addNext": "add next",
|
||||||
|
"addLastShuffled": "add last (shuffled)",
|
||||||
|
"addNextShuffled": "add next (shuffled)",
|
||||||
"favorite": "favorite",
|
"favorite": "favorite",
|
||||||
"mute": "mute",
|
"mute": "mute",
|
||||||
"muted": "muted",
|
"muted": "muted",
|
||||||
@@ -509,7 +511,7 @@
|
|||||||
"repeat_off": "repeat disabled",
|
"repeat_off": "repeat disabled",
|
||||||
"repeat_one": "repeat one",
|
"repeat_one": "repeat one",
|
||||||
"repeat_other": "",
|
"repeat_other": "",
|
||||||
"shuffle": "play shuffled",
|
"shuffle": "play (shuffled)",
|
||||||
"shuffle_off": "shuffle disabled",
|
"shuffle_off": "shuffle disabled",
|
||||||
"skip": "skip",
|
"skip": "skip",
|
||||||
"skip_back": "skip backwards",
|
"skip_back": "skip backwards",
|
||||||
|
|||||||
@@ -47,6 +47,14 @@ export const PlayAction = ({ ids, itemType, songs }: PlayActionProps) => {
|
|||||||
handlePlay(Play.SHUFFLE);
|
handlePlay(Play.SHUFFLE);
|
||||||
}, [handlePlay]);
|
}, [handlePlay]);
|
||||||
|
|
||||||
|
const handlePlayNextShuffled = useCallback(() => {
|
||||||
|
handlePlay(Play.NEXT_SHUFFLE);
|
||||||
|
}, [handlePlay]);
|
||||||
|
|
||||||
|
const handlePlayLastShuffled = useCallback(() => {
|
||||||
|
handlePlay(Play.LAST_SHUFFLE);
|
||||||
|
}, [handlePlay]);
|
||||||
|
|
||||||
const playButtonBehavior = usePlayButtonBehavior();
|
const playButtonBehavior = usePlayButtonBehavior();
|
||||||
|
|
||||||
const defaultPlayAction = useCallback(() => {
|
const defaultPlayAction = useCallback(() => {
|
||||||
@@ -76,9 +84,16 @@ export const PlayAction = ({ ids, itemType, songs }: PlayActionProps) => {
|
|||||||
<ContextMenu.Item leftIcon="mediaPlayLast" onSelect={handlePlayLast}>
|
<ContextMenu.Item leftIcon="mediaPlayLast" onSelect={handlePlayLast}>
|
||||||
{t('player.addLast', { postProcess: 'sentenceCase' })}
|
{t('player.addLast', { postProcess: 'sentenceCase' })}
|
||||||
</ContextMenu.Item>
|
</ContextMenu.Item>
|
||||||
|
<ContextMenu.Divider />
|
||||||
<ContextMenu.Item leftIcon="mediaShuffle" onSelect={handlePlayShuffled}>
|
<ContextMenu.Item leftIcon="mediaShuffle" onSelect={handlePlayShuffled}>
|
||||||
{t('player.shuffle', { postProcess: 'sentenceCase' })}
|
{t('player.shuffle', { postProcess: 'sentenceCase' })}
|
||||||
</ContextMenu.Item>
|
</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.SubmenuContent>
|
||||||
</ContextMenu.Submenu>
|
</ContextMenu.Submenu>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -160,6 +160,34 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
});
|
});
|
||||||
break;
|
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: {
|
case Play.NEXT: {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const currentIndex = state.player.index;
|
const currentIndex = state.player.index;
|
||||||
@@ -186,6 +214,35 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
});
|
});
|
||||||
break;
|
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: {
|
case Play.NOW: {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
newItems.forEach((item) => {
|
newItems.forEach((item) => {
|
||||||
@@ -252,6 +309,28 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
});
|
});
|
||||||
break;
|
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: {
|
case Play.NEXT: {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const currentIndex = state.player.index;
|
const currentIndex = state.player.index;
|
||||||
@@ -287,6 +366,44 @@ export const usePlayerStoreBase = create<PlayerState>()(
|
|||||||
});
|
});
|
||||||
break;
|
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: {
|
case Play.NOW: {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
// Add new songs to songs object
|
// Add new songs to songs object
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
import { useLongPress as useMantineLongPress } from '@mantine/hooks';
|
||||||
|
|
||||||
|
export const useLongPress = useMantineLongPress;
|
||||||
@@ -110,7 +110,9 @@ export enum FontType {
|
|||||||
export enum Play {
|
export enum Play {
|
||||||
INDEX = 'index',
|
INDEX = 'index',
|
||||||
LAST = 'last',
|
LAST = 'last',
|
||||||
|
LAST_SHUFFLE = 'lastShuffle',
|
||||||
NEXT = 'next',
|
NEXT = 'next',
|
||||||
|
NEXT_SHUFFLE = 'nextShuffle',
|
||||||
NOW = 'now',
|
NOW = 'now',
|
||||||
SHUFFLE = 'shuffle',
|
SHUFFLE = 'shuffle',
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user