handle playback on new artist list

This commit is contained in:
jeffvli 2025-05-06 14:43:42 -07:00
parent b9611589ba
commit 4a3604b1a8
12 changed files with 121 additions and 31 deletions

View file

@ -20,6 +20,7 @@ import {
getAlbumArtistSongsById,
getSongsByQuery,
getGenreSongsById,
getArtistSongsById,
} from '/@/renderer/features/player/utils';
import { queryKeys } from '/@/renderer/api/query-keys';
import { useTranslation } from 'react-i18next';
@ -75,6 +76,8 @@ export const useHandlePlayQueueAdd = () => {
let songs: QueueSong[] | null = null;
let initialSongIndex = 0;
console.log('options :>> ', options);
if (byItemType) {
let songList: SongListResponse | undefined;
const { type: itemType, id } = byItemType;
@ -119,6 +122,13 @@ export const useHandlePlayQueueAdd = () => {
queryClient,
server,
});
} else if (itemType === LibraryItem.ARTIST) {
songList = await getArtistSongsById({
id,
query,
queryClient,
server,
});
} else if (itemType === LibraryItem.GENRE) {
songList = await getGenreSongsById({ id, query, queryClient, server });
} else if (itemType === LibraryItem.SONG) {

View file

@ -146,7 +146,7 @@ export const getAlbumArtistSongsById = async (args: {
const { id, queryClient, server, query } = args;
const queryFilter: SongListQuery = {
artistIds: id || [],
albumArtistIds: id || [],
sortBy: SongListSort.ALBUM_ARTIST,
sortOrder: SortOrder.ASC,
startIndex: 0,
@ -174,6 +174,43 @@ export const getAlbumArtistSongsById = async (args: {
return res;
};
export const getArtistSongsById = async (args: {
id: string[];
query?: Partial<SongListQuery>;
queryClient: QueryClient;
server: ServerListItem;
}) => {
const { id, queryClient, server, query } = args;
const queryFilter: SongListQuery = {
artistIds: id,
sortBy: SongListSort.ALBUM,
sortOrder: SortOrder.ASC,
startIndex: 0,
...query,
};
const queryKey = queryKeys.songs.list(server?.id, queryFilter);
const res = await queryClient.fetchQuery(
queryKey,
async ({ signal }) =>
api.controller.getSongList({
apiClientProps: {
server,
signal,
},
query: queryFilter,
}),
{
cacheTime: 1000 * 60,
staleTime: 1000 * 60,
},
);
return res;
};
export const getSongsByQuery = async (args: {
query?: Partial<SongListQuery>;
queryClient: QueryClient;