mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
handle song selection in context menu play action
This commit is contained in:
@@ -4,15 +4,16 @@ import { useTranslation } from 'react-i18next';
|
||||
import { usePlayer } from '/@/renderer/features/player/context/player-context';
|
||||
import { useCurrentServerId } from '/@/renderer/store';
|
||||
import { ContextMenu } from '/@/shared/components/context-menu/context-menu';
|
||||
import { LibraryItem } from '/@/shared/types/domain-types';
|
||||
import { LibraryItem, Song } from '/@/shared/types/domain-types';
|
||||
import { Play } from '/@/shared/types/types';
|
||||
|
||||
interface PlayActionProps {
|
||||
ids: string[];
|
||||
itemType: LibraryItem;
|
||||
songs?: Song[];
|
||||
}
|
||||
|
||||
export const PlayAction = ({ ids, itemType }: PlayActionProps) => {
|
||||
export const PlayAction = ({ ids, itemType, songs }: PlayActionProps) => {
|
||||
const { t } = useTranslation();
|
||||
const player = usePlayer();
|
||||
const serverId = useCurrentServerId();
|
||||
@@ -20,9 +21,14 @@ export const PlayAction = ({ ids, itemType }: PlayActionProps) => {
|
||||
const handlePlay = useCallback(
|
||||
(playType: Play) => {
|
||||
if (ids.length === 0 || !serverId) return;
|
||||
player.addToQueueByFetch(serverId, ids, itemType, playType);
|
||||
|
||||
if (itemType === LibraryItem.SONG) {
|
||||
player.addToQueueByData(songs || [], playType);
|
||||
} else {
|
||||
player.addToQueueByFetch(serverId, ids, itemType, playType);
|
||||
}
|
||||
},
|
||||
[ids, itemType, player, serverId],
|
||||
[ids, itemType, player, serverId, songs],
|
||||
);
|
||||
|
||||
const handlePlayNow = useCallback(() => {
|
||||
|
||||
@@ -21,9 +21,11 @@ export const SongContextMenu = ({ items }: SongContextMenuProps) => {
|
||||
return { ids };
|
||||
}, [items]);
|
||||
|
||||
console.log(items, ids);
|
||||
|
||||
return (
|
||||
<ContextMenu.Content>
|
||||
<PlayAction ids={ids} itemType={LibraryItem.SONG} />
|
||||
<PlayAction ids={ids} itemType={LibraryItem.SONG} songs={items} />
|
||||
<ContextMenu.Divider />
|
||||
<AddToPlaylistAction items={ids} itemType={LibraryItem.SONG} />
|
||||
<ContextMenu.Divider />
|
||||
|
||||
Reference in New Issue
Block a user