handle song selection in context menu play action

This commit is contained in:
jeffvli
2025-11-16 14:35:54 -08:00
parent dc15ede3dc
commit 2f6ef7906f
2 changed files with 13 additions and 5 deletions
@@ -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 />