chore(context menu): show go to only for albums/tracks, prefer artist over album artist where possible

This commit is contained in:
Kendall Garner
2026-05-31 19:44:58 -07:00
parent 08b4c620f2
commit 70594a696b
3 changed files with 26 additions and 44 deletions
@@ -4,50 +4,38 @@ import { generatePath, useNavigate } from 'react-router';
import { AppRoute } from '/@/renderer/router/routes'; import { AppRoute } from '/@/renderer/router/routes';
import { ContextMenu } from '/@/shared/components/context-menu/context-menu'; import { ContextMenu } from '/@/shared/components/context-menu/context-menu';
import { import { Album, LibraryItem, QueueSong, Song } from '/@/shared/types/domain-types';
Album,
AlbumArtist,
Artist,
LibraryItem,
QueueSong,
Song,
} from '/@/shared/types/domain-types';
interface GoToActionProps { interface GoToActionProps {
items: Album[] | AlbumArtist[] | Artist[] | QueueSong[] | Song[]; items: Album[] | QueueSong[] | Song[];
} }
export const GoToAction = ({ items }: GoToActionProps) => { export const GoToAction = ({ items }: GoToActionProps) => {
const { t } = useTranslation(); const { t } = useTranslation();
const navigate = useNavigate(); const navigate = useNavigate();
const { albumArtists, albumId } = useMemo(() => { const { albumId, artists } = useMemo(() => {
const firstItem = items[0]; const firstItem = items[0];
if (firstItem._itemType === LibraryItem.ALBUM) { switch (firstItem._itemType) {
return { case LibraryItem.ALBUM:
albumArtists: firstItem.albumArtists || [], return {
albumId: firstItem.id, albumId: firstItem.id,
}; artists: firstItem.albumArtists || [],
} else if (firstItem._itemType === LibraryItem.SONG) { };
return { case LibraryItem.SONG:
albumArtists: firstItem.albumArtists || [], return {
albumId: firstItem.albumId, albumId: firstItem.albumId,
}; artists:
} else if ( (firstItem.artists?.length ? firstItem.artists : firstItem.albumArtists) ||
firstItem._itemType === LibraryItem.ARTIST || [],
firstItem._itemType === LibraryItem.ALBUM_ARTIST };
) { default:
return { return {
albumArtists: [{ id: firstItem.id, name: firstItem.name }], albumId: null,
albumId: null, artists: [],
}; };
} }
return {
albumArtists: [],
albumId: null,
};
}, [items]); }, [items]);
const handleGoToAlbum = useCallback(() => { const handleGoToAlbum = useCallback(() => {
@@ -55,7 +43,7 @@ export const GoToAction = ({ items }: GoToActionProps) => {
navigate(generatePath(AppRoute.LIBRARY_ALBUMS_DETAIL, { albumId })); navigate(generatePath(AppRoute.LIBRARY_ALBUMS_DETAIL, { albumId }));
}, [albumId, navigate]); }, [albumId, navigate]);
const handleGoToAlbumArtist = useCallback( const handleGoToArtist = useCallback(
(albumArtistId: string) => { (albumArtistId: string) => {
navigate(generatePath(AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL, { albumArtistId })); navigate(generatePath(AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL, { albumArtistId }));
}, },
@@ -81,13 +69,13 @@ export const GoToAction = ({ items }: GoToActionProps) => {
{t('page.contextMenu.goToAlbum')} {t('page.contextMenu.goToAlbum')}
</ContextMenu.Item> </ContextMenu.Item>
)} )}
{albumArtists.map((albumArtist) => ( {artists.map((artist) => (
<ContextMenu.Item <ContextMenu.Item
key={albumArtist.id} key={artist.id}
leftIcon="artist" leftIcon="artist"
onSelect={() => handleGoToAlbumArtist(albumArtist.id)} onSelect={() => handleGoToArtist(artist.id)}
> >
{`${t('page.contextMenu.goTo')} ${albumArtist.name}`} {`${t('page.contextMenu.goTo')} ${artist.name}`}
</ContextMenu.Item> </ContextMenu.Item>
))} ))}
</ContextMenu.SubmenuContent> </ContextMenu.SubmenuContent>
@@ -3,7 +3,6 @@ import { useMemo } from 'react';
import { AddToPlaylistAction } from '/@/renderer/features/context-menu/actions/add-to-playlist-action'; import { AddToPlaylistAction } from '/@/renderer/features/context-menu/actions/add-to-playlist-action';
import { DownloadAction } from '/@/renderer/features/context-menu/actions/download-action'; import { DownloadAction } from '/@/renderer/features/context-menu/actions/download-action';
import { GetInfoAction } from '/@/renderer/features/context-menu/actions/get-info-action'; import { GetInfoAction } from '/@/renderer/features/context-menu/actions/get-info-action';
import { GoToAction } from '/@/renderer/features/context-menu/actions/go-to-action';
import { PlayAction } from '/@/renderer/features/context-menu/actions/play-action'; import { PlayAction } from '/@/renderer/features/context-menu/actions/play-action';
import { PlayArtistRadioAction } from '/@/renderer/features/context-menu/actions/play-artist-radio-action'; import { PlayArtistRadioAction } from '/@/renderer/features/context-menu/actions/play-artist-radio-action';
import { SetFavoriteAction } from '/@/renderer/features/context-menu/actions/set-favorite-action'; import { SetFavoriteAction } from '/@/renderer/features/context-menu/actions/set-favorite-action';
@@ -39,8 +38,6 @@ export const AlbumArtistContextMenu = ({ items, type }: AlbumArtistContextMenuPr
<DownloadAction ids={ids} /> <DownloadAction ids={ids} />
<ShareAction ids={ids} itemType={LibraryItem.ALBUM_ARTIST} /> <ShareAction ids={ids} itemType={LibraryItem.ALBUM_ARTIST} />
<ContextMenu.Divider /> <ContextMenu.Divider />
<GoToAction items={items} />
<ContextMenu.Divider />
<GetInfoAction disabled={items.length === 0} items={items} /> <GetInfoAction disabled={items.length === 0} items={items} />
</ContextMenu.Content> </ContextMenu.Content>
); );
@@ -3,7 +3,6 @@ import { useMemo } from 'react';
import { AddToPlaylistAction } from '/@/renderer/features/context-menu/actions/add-to-playlist-action'; import { AddToPlaylistAction } from '/@/renderer/features/context-menu/actions/add-to-playlist-action';
import { DownloadAction } from '/@/renderer/features/context-menu/actions/download-action'; import { DownloadAction } from '/@/renderer/features/context-menu/actions/download-action';
import { GetInfoAction } from '/@/renderer/features/context-menu/actions/get-info-action'; import { GetInfoAction } from '/@/renderer/features/context-menu/actions/get-info-action';
import { GoToAction } from '/@/renderer/features/context-menu/actions/go-to-action';
import { PlayAction } from '/@/renderer/features/context-menu/actions/play-action'; import { PlayAction } from '/@/renderer/features/context-menu/actions/play-action';
import { PlayArtistRadioAction } from '/@/renderer/features/context-menu/actions/play-artist-radio-action'; import { PlayArtistRadioAction } from '/@/renderer/features/context-menu/actions/play-artist-radio-action';
import { SetFavoriteAction } from '/@/renderer/features/context-menu/actions/set-favorite-action'; import { SetFavoriteAction } from '/@/renderer/features/context-menu/actions/set-favorite-action';
@@ -39,8 +38,6 @@ export const ArtistContextMenu = ({ items, type }: ArtistContextMenuProps) => {
<DownloadAction ids={ids} /> <DownloadAction ids={ids} />
<ShareAction ids={ids} itemType={LibraryItem.ARTIST} /> <ShareAction ids={ids} itemType={LibraryItem.ARTIST} />
<ContextMenu.Divider /> <ContextMenu.Divider />
<GoToAction items={items} />
<ContextMenu.Divider />
<GetInfoAction disabled={items.length === 0} items={items} /> <GetInfoAction disabled={items.length === 0} items={items} />
</ContextMenu.Content> </ContextMenu.Content>
); );