Add song filter as add queue type
This commit is contained in:
parent
d94d7b5ee5
commit
2df96c0d31
2 changed files with 78 additions and 14 deletions
|
@ -33,11 +33,25 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
if (!server) return toast.error({ message: 'No server selected', type: 'error' });
|
if (!server) return toast.error({ message: 'No server selected', type: 'error' });
|
||||||
let songs = null;
|
let songs = null;
|
||||||
|
|
||||||
|
// const itemCount = options.byItemType?.id?.length || 0;
|
||||||
|
// const fetchId = itemCount > 1 ? nanoid() : null;
|
||||||
|
|
||||||
if (options.byItemType) {
|
if (options.byItemType) {
|
||||||
let songsList;
|
let songsList;
|
||||||
let queryFilter: any;
|
let queryFilter: any;
|
||||||
let queryKey: any;
|
let queryKey: any;
|
||||||
|
|
||||||
if (options.byItemType.type === LibraryItem.PLAYLIST) {
|
if (options.byItemType.type === LibraryItem.PLAYLIST) {
|
||||||
|
// if (fetchId) {
|
||||||
|
// toast.success({
|
||||||
|
// autoClose: false,
|
||||||
|
// id: fetchId,
|
||||||
|
// loading: true,
|
||||||
|
// message: `This may take a while...`,
|
||||||
|
// title: `Adding ${itemCount} albums to the queue`,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
queryFilter = {
|
queryFilter = {
|
||||||
id: options.byItemType?.id || [],
|
id: options.byItemType?.id || [],
|
||||||
sortBy: 'id',
|
sortBy: 'id',
|
||||||
|
@ -51,6 +65,16 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
queryFilter,
|
queryFilter,
|
||||||
);
|
);
|
||||||
} else if (options.byItemType.type === LibraryItem.ALBUM) {
|
} else if (options.byItemType.type === LibraryItem.ALBUM) {
|
||||||
|
// if (fetchId) {
|
||||||
|
// toast.success({
|
||||||
|
// autoClose: false,
|
||||||
|
// id: fetchId,
|
||||||
|
// loading: true,
|
||||||
|
// message: `This may take a while...`,
|
||||||
|
// title: `Adding ${itemCount} albums to the queue`,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
queryFilter = {
|
queryFilter = {
|
||||||
albumIds: options.byItemType?.id || [],
|
albumIds: options.byItemType?.id || [],
|
||||||
sortBy: SongListSort.ALBUM,
|
sortBy: SongListSort.ALBUM,
|
||||||
|
@ -60,32 +84,57 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
|
|
||||||
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
} else if (options.byItemType.type === LibraryItem.ALBUM_ARTIST) {
|
} else if (options.byItemType.type === LibraryItem.ALBUM_ARTIST) {
|
||||||
|
// if (fetchId) {
|
||||||
|
// toast.success({
|
||||||
|
// autoClose: false,
|
||||||
|
// id: fetchId,
|
||||||
|
// loading: true,
|
||||||
|
// message: `This may take a while...`,
|
||||||
|
// title: `Adding ${itemCount} album artists to the queue`,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
queryFilter = {
|
queryFilter = {
|
||||||
artistIds: options.byItemType?.id || [],
|
artistIds: options.byItemType?.id || [],
|
||||||
sortBy: SongListSort.ALBUM,
|
sortBy: SongListSort.ALBUM_ARTIST,
|
||||||
sortOrder: SortOrder.ASC,
|
sortOrder: SortOrder.ASC,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
|
} else if (options.byItemType.type === LibraryItem.SONG) {
|
||||||
|
queryFilter = options.byItemType.id;
|
||||||
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (options.byItemType?.type === LibraryItem.PLAYLIST) {
|
if (options.byItemType?.type === LibraryItem.PLAYLIST) {
|
||||||
songsList = await queryClient.fetchQuery(queryKey, async ({ signal }) =>
|
songsList = await queryClient.fetchQuery(
|
||||||
|
queryKey,
|
||||||
|
async ({ signal }) =>
|
||||||
api.controller.getPlaylistSongList({
|
api.controller.getPlaylistSongList({
|
||||||
query: queryFilter,
|
query: queryFilter,
|
||||||
server,
|
server,
|
||||||
signal,
|
signal,
|
||||||
}),
|
}),
|
||||||
|
{
|
||||||
|
cacheTime: 1000 * 60,
|
||||||
|
staleTime: 1000 * 60,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
songsList = await queryClient.fetchQuery(queryKey, async ({ signal }) =>
|
songsList = await queryClient.fetchQuery(
|
||||||
|
queryKey,
|
||||||
|
async ({ signal }) =>
|
||||||
api.controller.getSongList({
|
api.controller.getSongList({
|
||||||
query: queryFilter,
|
query: queryFilter,
|
||||||
server,
|
server,
|
||||||
signal,
|
signal,
|
||||||
}),
|
}),
|
||||||
|
{
|
||||||
|
cacheTime: 1000 * 60,
|
||||||
|
staleTime: 1000 * 60,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
|
@ -134,6 +183,21 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
play();
|
play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if (fetchId) {
|
||||||
|
// toast.update({
|
||||||
|
// autoClose: 1000,
|
||||||
|
// id: fetchId,
|
||||||
|
// message: '',
|
||||||
|
// title: `Added ${songs.length} items to the queue`,
|
||||||
|
// });
|
||||||
|
// // toast.hide(fetchId);
|
||||||
|
// } else {
|
||||||
|
// toast.success({
|
||||||
|
// // message: 'Success',
|
||||||
|
// title: `Added ${songs.length} items to the queue`,
|
||||||
|
// });
|
||||||
|
// }
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
[deviceId, play, playerType, queryClient, server],
|
[deviceId, play, playerType, queryClient, server],
|
||||||
|
|
|
@ -151,7 +151,7 @@ export enum TableColumn {
|
||||||
export type PlayQueueAddOptions = {
|
export type PlayQueueAddOptions = {
|
||||||
byData?: QueueSong[];
|
byData?: QueueSong[];
|
||||||
byItemType?: {
|
byItemType?: {
|
||||||
id: string[];
|
id: string[] | any;
|
||||||
type: LibraryItem;
|
type: LibraryItem;
|
||||||
};
|
};
|
||||||
play: Play;
|
play: Play;
|
||||||
|
|
Reference in a new issue