Add custom query prop to play queue add
This commit is contained in:
parent
6747fbb701
commit
93530008a9
3 changed files with 14 additions and 7 deletions
|
@ -29,7 +29,7 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
const handlePlayQueueAdd = useCallback(
|
const handlePlayQueueAdd = useCallback(
|
||||||
async (options: PlayQueueAddOptions) => {
|
async (options: PlayQueueAddOptions) => {
|
||||||
if (!server) return toast.error({ message: 'No server selected', type: 'error' });
|
if (!server) return toast.error({ message: 'No server selected', type: 'error' });
|
||||||
const { initialIndex, initialSongId, playType, byData, byItemType } = options;
|
const { initialIndex, initialSongId, playType, byData, byItemType, query } = options;
|
||||||
let songs: QueueSong[] | null = null;
|
let songs: QueueSong[] | null = null;
|
||||||
let initialSongIndex = 0;
|
let initialSongIndex = 0;
|
||||||
|
|
||||||
|
@ -39,11 +39,11 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (itemType === LibraryItem.PLAYLIST) {
|
if (itemType === LibraryItem.PLAYLIST) {
|
||||||
songList = await getPlaylistSongsById({ id: id?.[0], queryClient, server });
|
songList = await getPlaylistSongsById({ id: id?.[0], query, queryClient, server });
|
||||||
} else if (itemType === LibraryItem.ALBUM) {
|
} else if (itemType === LibraryItem.ALBUM) {
|
||||||
songList = await getAlbumSongsById({ id, queryClient, server });
|
songList = await getAlbumSongsById({ id, query, queryClient, server });
|
||||||
} else if (itemType === LibraryItem.ALBUM_ARTIST) {
|
} else if (itemType === LibraryItem.ALBUM_ARTIST) {
|
||||||
songList = await getAlbumArtistSongsById({ id, queryClient, server });
|
songList = await getAlbumArtistSongsById({ id, query, queryClient, server });
|
||||||
} else {
|
} else {
|
||||||
songList = await getSongById({ id: id?.[0], queryClient, server });
|
songList = await getSongById({ id: id?.[0], queryClient, server });
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,16 +13,18 @@ import { ServerListItem } from '/@/renderer/types';
|
||||||
|
|
||||||
export const getPlaylistSongsById = async (args: {
|
export const getPlaylistSongsById = async (args: {
|
||||||
id: string;
|
id: string;
|
||||||
|
query?: Partial<PlaylistSongListQuery>;
|
||||||
queryClient: QueryClient;
|
queryClient: QueryClient;
|
||||||
server: ServerListItem;
|
server: ServerListItem;
|
||||||
}) => {
|
}) => {
|
||||||
const { id, queryClient, server } = args;
|
const { id, queryClient, server, query } = args;
|
||||||
|
|
||||||
const queryFilter: PlaylistSongListQuery = {
|
const queryFilter: PlaylistSongListQuery = {
|
||||||
id,
|
id,
|
||||||
sortBy: SongListSort.ID,
|
sortBy: SongListSort.ID,
|
||||||
sortOrder: SortOrder.ASC,
|
sortOrder: SortOrder.ASC,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
|
...query,
|
||||||
};
|
};
|
||||||
|
|
||||||
const queryKey = queryKeys.playlists.songList(server?.id, id, queryFilter);
|
const queryKey = queryKeys.playlists.songList(server?.id, id, queryFilter);
|
||||||
|
@ -49,16 +51,18 @@ export const getPlaylistSongsById = async (args: {
|
||||||
export const getAlbumSongsById = async (args: {
|
export const getAlbumSongsById = async (args: {
|
||||||
id: string[];
|
id: string[];
|
||||||
orderByIds?: boolean;
|
orderByIds?: boolean;
|
||||||
|
query?: Partial<SongListQuery>;
|
||||||
queryClient: QueryClient;
|
queryClient: QueryClient;
|
||||||
server: ServerListItem;
|
server: ServerListItem;
|
||||||
}) => {
|
}) => {
|
||||||
const { id, queryClient, server } = args;
|
const { id, queryClient, server, query } = args;
|
||||||
|
|
||||||
const queryFilter: SongListQuery = {
|
const queryFilter: SongListQuery = {
|
||||||
albumIds: id,
|
albumIds: id,
|
||||||
sortBy: SongListSort.ALBUM,
|
sortBy: SongListSort.ALBUM,
|
||||||
sortOrder: SortOrder.ASC,
|
sortOrder: SortOrder.ASC,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
|
...query,
|
||||||
};
|
};
|
||||||
|
|
||||||
const queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
const queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
|
@ -85,16 +89,18 @@ export const getAlbumSongsById = async (args: {
|
||||||
export const getAlbumArtistSongsById = async (args: {
|
export const getAlbumArtistSongsById = async (args: {
|
||||||
id: string[];
|
id: string[];
|
||||||
orderByIds?: boolean;
|
orderByIds?: boolean;
|
||||||
|
query?: Partial<SongListQuery>;
|
||||||
queryClient: QueryClient;
|
queryClient: QueryClient;
|
||||||
server: ServerListItem;
|
server: ServerListItem;
|
||||||
}) => {
|
}) => {
|
||||||
const { id, queryClient, server } = args;
|
const { id, queryClient, server, query } = args;
|
||||||
|
|
||||||
const queryFilter: SongListQuery = {
|
const queryFilter: SongListQuery = {
|
||||||
artistIds: id || [],
|
artistIds: id || [],
|
||||||
sortBy: SongListSort.ALBUM_ARTIST,
|
sortBy: SongListSort.ALBUM_ARTIST,
|
||||||
sortOrder: SortOrder.ASC,
|
sortOrder: SortOrder.ASC,
|
||||||
startIndex: 0,
|
startIndex: 0,
|
||||||
|
...query,
|
||||||
};
|
};
|
||||||
|
|
||||||
const queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
const queryKey = queryKeys.songs.list(server?.id, queryFilter);
|
||||||
|
|
|
@ -157,6 +157,7 @@ export type PlayQueueAddOptions = {
|
||||||
initialIndex?: number;
|
initialIndex?: number;
|
||||||
initialSongId?: string;
|
initialSongId?: string;
|
||||||
playType: Play;
|
playType: Play;
|
||||||
|
query?: Record<string, any>;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type GridCardData = {
|
export type GridCardData = {
|
||||||
|
|
Reference in a new issue