From c59db6b2696b97d49ce473f8ee1cf5680c6674cb Mon Sep 17 00:00:00 2001 From: isaiahfuller <9921699+isaiahfuller@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:11:09 -0400 Subject: [PATCH 1/2] Add option to play similar songs from context menu --- src/i18n/locales/en.json | 2 ++ .../context-menu/context-menu-items.tsx | 9 +++++--- .../context-menu/context-menu-provider.tsx | 23 +++++++++++++++++++ src/renderer/features/context-menu/events.ts | 3 ++- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/i18n/locales/en.json b/src/i18n/locales/en.json index 55e92a07e..b6aa1bcfe 100644 --- a/src/i18n/locales/en.json +++ b/src/i18n/locales/en.json @@ -322,6 +322,7 @@ "moveToTop": "$t(action.moveToTop)", "numberSelected": "{{count}} selected", "play": "$t(player.play)", + "playSimilarSongs": "$t(player.playSimilarSongs)", "removeFromFavorites": "$t(action.removeFromFavorites)", "removeFromPlaylist": "$t(action.removeFromPlaylist)", "removeFromQueue": "$t(action.removeFromQueue)", @@ -416,6 +417,7 @@ "playbackFetchNoResults": "no songs found", "playbackSpeed": "playback speed", "playRandom": "play random", + "playSimilarSongs": "play similar songs", "previous": "previous", "queue_clear": "clear queue", "queue_moveToBottom": "move selected to top", diff --git a/src/renderer/features/context-menu/context-menu-items.tsx b/src/renderer/features/context-menu/context-menu-items.tsx index b9bb027fe..27e125280 100644 --- a/src/renderer/features/context-menu/context-menu-items.tsx +++ b/src/renderer/features/context-menu/context-menu-items.tsx @@ -15,7 +15,8 @@ export const QUEUE_CONTEXT_MENU_ITEMS: SetContextMenuItems = [ export const SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [ { id: 'play' }, { id: 'playLast' }, - { divider: true, id: 'playNext' }, + { id: 'playNext' }, + { divider: true, id: 'playSimilarSongs' }, { divider: true, id: 'addToPlaylist' }, { id: 'addToFavorites' }, { divider: true, id: 'removeFromFavorites' }, @@ -34,7 +35,8 @@ export const SONG_ALBUM_PAGE: SetContextMenuItems = [ export const PLAYLIST_SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [ { id: 'play' }, { id: 'playLast' }, - { divider: true, id: 'playNext' }, + { id: 'playNext' }, + { divider: true, id: 'playSimilarSongs' }, { id: 'addToPlaylist' }, { divider: true, id: 'removeFromPlaylist' }, { id: 'addToFavorites' }, @@ -46,7 +48,8 @@ export const PLAYLIST_SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [ export const SMART_PLAYLIST_SONG_CONTEXT_MENU_ITEMS: SetContextMenuItems = [ { id: 'play' }, { id: 'playLast' }, - { divider: true, id: 'playNext' }, + { id: 'playNext' }, + { divider: true, id: 'playSimilarSongs' }, { divider: true, id: 'addToPlaylist' }, { id: 'addToFavorites' }, { divider: true, id: 'removeFromFavorites' }, diff --git a/src/renderer/features/context-menu/context-menu-provider.tsx b/src/renderer/features/context-menu/context-menu-provider.tsx index 5bb0a11a6..6ba62cbee 100644 --- a/src/renderer/features/context-menu/context-menu-provider.tsx +++ b/src/renderer/features/context-menu/context-menu-provider.tsx @@ -29,6 +29,7 @@ import { RiCloseCircleLine, RiShareForwardFill, RiInformationFill, + RiRadio2Fill, } from 'react-icons/ri'; import { AnyLibraryItems, LibraryItem, ServerType, AnyLibraryItem } from '/@/renderer/api/types'; import { @@ -50,6 +51,7 @@ import { useDeletePlaylist } from '/@/renderer/features/playlists'; import { useRemoveFromPlaylist } from '/@/renderer/features/playlists/mutations/remove-from-playlist-mutation'; import { useCreateFavorite, useDeleteFavorite, useSetRating } from '/@/renderer/features/shared'; import { + getServerById, useAuthStore, useCurrentServer, usePlayerStore, @@ -58,6 +60,7 @@ import { import { usePlaybackType } from '/@/renderer/store/settings.store'; import { Play, PlaybackType } from '/@/renderer/types'; import { ItemDetailsModal } from '/@/renderer/features/item-details/components/item-details-modal'; +import { controller } from '/@/renderer/api/controller'; type ContextMenuContextProps = { closeContextMenu: () => void; @@ -658,6 +661,19 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { }); }, [ctx.data, t]); + const handleSimilar = useCallback(async () => { + const item = ctx.data[0]; + console.log(ctx); + const songs = await controller.getSimilarSongs({ + apiClientProps: { + server: getServerById(item.serverId), + signal: undefined, + }, + query: { albumArtistIds: item.albumArtistIds, songId: item.id }, + }); + handlePlayQueueAdd?.({ byData: [ctx.data[0], ...songs], playType: Play.NOW }); + }, [ctx, handlePlayQueueAdd]); + const contextMenuItems: Record = useMemo(() => { return { addToFavorites: { @@ -719,6 +735,12 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { leftIcon: , onClick: () => handlePlay(Play.NEXT), }, + playSimilarSongs: { + id: 'playSimilarSongs', + label: t('page.contextMenu.playSimilarSongs', { postProcess: 'sentenceCase' }), + leftIcon: , + onClick: handleSimilar, + }, removeFromFavorites: { id: 'removeFromFavorites', label: t('page.contextMenu.removeFromFavorites', { postProcess: 'sentenceCase' }), @@ -838,6 +860,7 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { handleUpdateRating, handleShareItem, server, + handleSimilar, ]); const mergedRef = useMergedRef(ref, clickOutsideRef); diff --git a/src/renderer/features/context-menu/events.ts b/src/renderer/features/context-menu/events.ts index 0e7242997..63e4fe325 100644 --- a/src/renderer/features/context-menu/events.ts +++ b/src/renderer/features/context-menu/events.ts @@ -35,7 +35,8 @@ export type ContextMenuItemType = | 'moveToTopOfQueue' | 'removeFromQueue' | 'deselectAll' - | 'showDetails'; + | 'showDetails' + | 'playSimilarSongs'; export type SetContextMenuItems = { children?: boolean; From 4e4ca0c968be6c169717d9503d86b2bdb913f012 Mon Sep 17 00:00:00 2001 From: isaiahfuller <9921699+isaiahfuller@users.noreply.github.com> Date: Mon, 24 Jun 2024 16:22:10 -0400 Subject: [PATCH 2/2] remove console.log --- src/renderer/features/context-menu/context-menu-provider.tsx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/renderer/features/context-menu/context-menu-provider.tsx b/src/renderer/features/context-menu/context-menu-provider.tsx index 6ba62cbee..2c657aa64 100644 --- a/src/renderer/features/context-menu/context-menu-provider.tsx +++ b/src/renderer/features/context-menu/context-menu-provider.tsx @@ -663,7 +663,6 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => { const handleSimilar = useCallback(async () => { const item = ctx.data[0]; - console.log(ctx); const songs = await controller.getSimilarSongs({ apiClientProps: { server: getServerById(item.serverId),