Support genres in context menu
This commit is contained in:
parent
0b207c78e7
commit
d0aba6e16e
12 changed files with 182 additions and 56 deletions
|
@ -140,7 +140,9 @@ const normalizeSong = (
|
||||||
imageUrl: null,
|
imageUrl: null,
|
||||||
name: entry.Name,
|
name: entry.Name,
|
||||||
})),
|
})),
|
||||||
bitRate: item.MediaSources && Number(Math.trunc(item.MediaSources[0]?.Bitrate / 1000)),
|
bitRate:
|
||||||
|
item.MediaSources?.[0].Bitrate &&
|
||||||
|
Number(Math.trunc(item.MediaSources[0].Bitrate / 1000)),
|
||||||
bpm: null,
|
bpm: null,
|
||||||
channels: null,
|
channels: null,
|
||||||
comment: null,
|
comment: null,
|
||||||
|
@ -149,7 +151,12 @@ const normalizeSong = (
|
||||||
createdAt: item.DateCreated,
|
createdAt: item.DateCreated,
|
||||||
discNumber: (item.ParentIndexNumber && item.ParentIndexNumber) || 1,
|
discNumber: (item.ParentIndexNumber && item.ParentIndexNumber) || 1,
|
||||||
duration: item.RunTimeTicks / 10000000,
|
duration: item.RunTimeTicks / 10000000,
|
||||||
genres: item.GenreItems.map((entry: any) => ({ id: entry.Id, name: entry.Name })),
|
genres: item.GenreItems.map((entry) => ({
|
||||||
|
id: entry.Id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: entry.Name,
|
||||||
|
})),
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
imagePlaceholderUrl: null,
|
imagePlaceholderUrl: null,
|
||||||
imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }),
|
imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }),
|
||||||
|
@ -202,7 +209,12 @@ const normalizeAlbum = (
|
||||||
backdropImageUrl: null,
|
backdropImageUrl: null,
|
||||||
createdAt: item.DateCreated,
|
createdAt: item.DateCreated,
|
||||||
duration: item.RunTimeTicks / 10000000,
|
duration: item.RunTimeTicks / 10000000,
|
||||||
genres: item.GenreItems?.map((entry) => ({ id: entry.Id, name: entry.Name })),
|
genres: item.GenreItems.map((entry) => ({
|
||||||
|
id: entry.Id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: entry.Name,
|
||||||
|
})),
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
imagePlaceholderUrl: null,
|
imagePlaceholderUrl: null,
|
||||||
imageUrl: getAlbumCoverArtUrl({
|
imageUrl: getAlbumCoverArtUrl({
|
||||||
|
@ -254,7 +266,12 @@ const normalizeAlbumArtist = (
|
||||||
backgroundImageUrl: null,
|
backgroundImageUrl: null,
|
||||||
biography: item.Overview || null,
|
biography: item.Overview || null,
|
||||||
duration: item.RunTimeTicks / 10000,
|
duration: item.RunTimeTicks / 10000,
|
||||||
genres: item.GenreItems?.map((entry) => ({ id: entry.Id, name: entry.Name })),
|
genres: item.GenreItems.map((entry) => ({
|
||||||
|
id: entry.Id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: entry.Name,
|
||||||
|
})),
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
imageUrl: getAlbumArtistCoverArtUrl({
|
imageUrl: getAlbumArtistCoverArtUrl({
|
||||||
baseUrl: server?.url || '',
|
baseUrl: server?.url || '',
|
||||||
|
@ -290,7 +307,12 @@ const normalizePlaylist = (
|
||||||
return {
|
return {
|
||||||
description: item.Overview || null,
|
description: item.Overview || null,
|
||||||
duration: item.RunTimeTicks / 10000,
|
duration: item.RunTimeTicks / 10000,
|
||||||
genres: item.GenreItems?.map((entry) => ({ id: entry.Id, name: entry.Name })),
|
genres: item.GenreItems.map((entry) => ({
|
||||||
|
id: entry.Id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: entry.Name,
|
||||||
|
})),
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
imagePlaceholderUrl,
|
imagePlaceholderUrl,
|
||||||
imageUrl: imageUrl || null,
|
imageUrl: imageUrl || null,
|
||||||
|
@ -339,6 +361,8 @@ const normalizeGenre = (item: JFGenre): Genre => {
|
||||||
return {
|
return {
|
||||||
albumCount: undefined,
|
albumCount: undefined,
|
||||||
id: item.Id,
|
id: item.Id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
name: item.Name,
|
name: item.Name,
|
||||||
songCount: undefined,
|
songCount: undefined,
|
||||||
};
|
};
|
||||||
|
|
|
@ -112,7 +112,7 @@ const getGenreList = async (args: GenreListArgs): Promise<GenreListResponse> =>
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
items: res.body.data,
|
items: res.body.data.map((genre) => ndNormalize.genre(genre)),
|
||||||
startIndex: query.startIndex || 0,
|
startIndex: query.startIndex || 0,
|
||||||
totalRecordCount: Number(res.body.headers.get('x-total-count') || 0),
|
totalRecordCount: Number(res.body.headers.get('x-total-count') || 0),
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,9 +1,18 @@
|
||||||
import { nanoid } from 'nanoid';
|
import { nanoid } from 'nanoid';
|
||||||
import { Song, LibraryItem, Album, Playlist, User, AlbumArtist } from '/@/renderer/api/types';
|
import {
|
||||||
|
Song,
|
||||||
|
LibraryItem,
|
||||||
|
Album,
|
||||||
|
Playlist,
|
||||||
|
User,
|
||||||
|
AlbumArtist,
|
||||||
|
Genre,
|
||||||
|
} from '/@/renderer/api/types';
|
||||||
import { ServerListItem, ServerType } from '/@/renderer/types';
|
import { ServerListItem, ServerType } from '/@/renderer/types';
|
||||||
import z from 'zod';
|
import z from 'zod';
|
||||||
import { ndType } from './navidrome-types';
|
import { ndType } from './navidrome-types';
|
||||||
import { ssType } from '/@/renderer/api/subsonic/subsonic-types';
|
import { ssType } from '/@/renderer/api/subsonic/subsonic-types';
|
||||||
|
import { NDGenre } from '/@/renderer/api/navidrome.types';
|
||||||
|
|
||||||
const getImageUrl = (args: { url: string | null }) => {
|
const getImageUrl = (args: { url: string | null }) => {
|
||||||
const { url } = args;
|
const { url } = args;
|
||||||
|
@ -81,7 +90,12 @@ const normalizeSong = (
|
||||||
createdAt: item.createdAt.split('T')[0],
|
createdAt: item.createdAt.split('T')[0],
|
||||||
discNumber: item.discNumber,
|
discNumber: item.discNumber,
|
||||||
duration: item.duration,
|
duration: item.duration,
|
||||||
genres: item.genres,
|
genres: item.genres?.map((genre) => ({
|
||||||
|
id: genre.id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: genre.name,
|
||||||
|
})),
|
||||||
id,
|
id,
|
||||||
imagePlaceholderUrl,
|
imagePlaceholderUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
|
@ -130,7 +144,12 @@ const normalizeAlbum = (
|
||||||
backdropImageUrl: imageBackdropUrl,
|
backdropImageUrl: imageBackdropUrl,
|
||||||
createdAt: item.createdAt.split('T')[0],
|
createdAt: item.createdAt.split('T')[0],
|
||||||
duration: item.duration * 1000 || null,
|
duration: item.duration * 1000 || null,
|
||||||
genres: item.genres,
|
genres: item.genres?.map((genre) => ({
|
||||||
|
id: genre.id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: genre.name,
|
||||||
|
})),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
imagePlaceholderUrl,
|
imagePlaceholderUrl,
|
||||||
imageUrl,
|
imageUrl,
|
||||||
|
@ -166,7 +185,12 @@ const normalizeAlbumArtist = (
|
||||||
backgroundImageUrl: null,
|
backgroundImageUrl: null,
|
||||||
biography: item.biography || null,
|
biography: item.biography || null,
|
||||||
duration: null,
|
duration: null,
|
||||||
genres: item.genres,
|
genres: item.genres?.map((genre) => ({
|
||||||
|
id: genre.id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: genre.name,
|
||||||
|
})),
|
||||||
id: item.id,
|
id: item.id,
|
||||||
imageUrl: imageUrl || null,
|
imageUrl: imageUrl || null,
|
||||||
itemType: LibraryItem.ALBUM_ARTIST,
|
itemType: LibraryItem.ALBUM_ARTIST,
|
||||||
|
@ -222,6 +246,17 @@ const normalizePlaylist = (
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const normalizeGenre = (item: NDGenre): Genre => {
|
||||||
|
return {
|
||||||
|
albumCount: undefined,
|
||||||
|
id: item.id,
|
||||||
|
imageUrl: null,
|
||||||
|
itemType: LibraryItem.GENRE,
|
||||||
|
name: item.name,
|
||||||
|
songCount: undefined,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const normalizeUser = (item: z.infer<typeof ndType._response.user>): User => {
|
const normalizeUser = (item: z.infer<typeof ndType._response.user>): User => {
|
||||||
return {
|
return {
|
||||||
createdAt: item.createdAt,
|
createdAt: item.createdAt,
|
||||||
|
@ -237,6 +272,7 @@ const normalizeUser = (item: z.infer<typeof ndType._response.user>): User => {
|
||||||
export const ndNormalize = {
|
export const ndNormalize = {
|
||||||
album: normalizeAlbum,
|
album: normalizeAlbum,
|
||||||
albumArtist: normalizeAlbumArtist,
|
albumArtist: normalizeAlbumArtist,
|
||||||
|
genre: normalizeGenre,
|
||||||
playlist: normalizePlaylist,
|
playlist: normalizePlaylist,
|
||||||
song: normalizeSong,
|
song: normalizeSong,
|
||||||
user: normalizeUser,
|
user: normalizeUser,
|
||||||
|
|
|
@ -137,6 +137,8 @@ export type AuthenticationResponse = {
|
||||||
export type Genre = {
|
export type Genre = {
|
||||||
albumCount?: number;
|
albumCount?: number;
|
||||||
id: string;
|
id: string;
|
||||||
|
imageUrl: string | null;
|
||||||
|
itemType: LibraryItem.GENRE;
|
||||||
name: string;
|
name: string;
|
||||||
songCount?: number;
|
songCount?: number;
|
||||||
};
|
};
|
||||||
|
|
|
@ -166,6 +166,8 @@ export const useVirtualTable = <TFilter>({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
})) as BasePaginatedResponse<any>;
|
})) as BasePaginatedResponse<any>;
|
||||||
|
|
||||||
|
|
|
@ -52,6 +52,13 @@ export const ALBUM_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
||||||
{ children: true, disabled: false, id: 'setRating' },
|
{ children: true, disabled: false, id: 'setRating' },
|
||||||
];
|
];
|
||||||
|
|
||||||
|
export const GENRE_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
||||||
|
{ id: 'play' },
|
||||||
|
{ id: 'playLast' },
|
||||||
|
{ divider: true, id: 'playNext' },
|
||||||
|
{ divider: true, id: 'addToPlaylist' },
|
||||||
|
];
|
||||||
|
|
||||||
export const ARTIST_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
export const ARTIST_CONTEXT_MENU_ITEMS: SetContextMenuItems = [
|
||||||
{ id: 'play' },
|
{ id: 'play' },
|
||||||
{ id: 'playLast' },
|
{ id: 'playLast' },
|
||||||
|
|
|
@ -196,6 +196,12 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
playType,
|
playType,
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
case LibraryItem.GENRE:
|
||||||
|
handlePlayQueueAdd?.({
|
||||||
|
byItemType: { id: ctx.data.map((item) => item.id), type: ctx.type },
|
||||||
|
playType,
|
||||||
|
});
|
||||||
|
break;
|
||||||
case LibraryItem.SONG:
|
case LibraryItem.SONG:
|
||||||
handlePlayQueueAdd?.({ byData: ctx.data, playType });
|
handlePlayQueueAdd?.({ byData: ctx.data, playType });
|
||||||
break;
|
break;
|
||||||
|
@ -403,9 +409,11 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
const albumId: string[] = [];
|
const albumId: string[] = [];
|
||||||
const artistId: string[] = [];
|
const artistId: string[] = [];
|
||||||
const songId: string[] = [];
|
const songId: string[] = [];
|
||||||
|
const genreId: string[] = [];
|
||||||
|
|
||||||
if (ctx.dataNodes) {
|
if (ctx.dataNodes) {
|
||||||
for (const node of ctx.dataNodes) {
|
for (const node of ctx.dataNodes) {
|
||||||
|
console.log('node.data.itemType :>> ', node.data.itemType);
|
||||||
switch (node.data.itemType) {
|
switch (node.data.itemType) {
|
||||||
case LibraryItem.ALBUM:
|
case LibraryItem.ALBUM:
|
||||||
albumId.push(node.data.id);
|
albumId.push(node.data.id);
|
||||||
|
@ -413,6 +421,9 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
case LibraryItem.ARTIST:
|
case LibraryItem.ARTIST:
|
||||||
artistId.push(node.data.id);
|
artistId.push(node.data.id);
|
||||||
break;
|
break;
|
||||||
|
case LibraryItem.GENRE:
|
||||||
|
genreId.push(node.data.id);
|
||||||
|
break;
|
||||||
case LibraryItem.SONG:
|
case LibraryItem.SONG:
|
||||||
songId.push(node.data.id);
|
songId.push(node.data.id);
|
||||||
break;
|
break;
|
||||||
|
@ -427,6 +438,9 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
case LibraryItem.ARTIST:
|
case LibraryItem.ARTIST:
|
||||||
artistId.push(item.id);
|
artistId.push(item.id);
|
||||||
break;
|
break;
|
||||||
|
case LibraryItem.GENRE:
|
||||||
|
genreId.push(item.id);
|
||||||
|
break;
|
||||||
case LibraryItem.SONG:
|
case LibraryItem.SONG:
|
||||||
songId.push(item.id);
|
songId.push(item.id);
|
||||||
break;
|
break;
|
||||||
|
@ -434,10 +448,13 @@ export const ContextMenuProvider = ({ children }: ContextMenuProviderProps) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('genreId', genreId);
|
||||||
|
|
||||||
openContextModal({
|
openContextModal({
|
||||||
innerProps: {
|
innerProps: {
|
||||||
albumId: albumId.length > 0 ? albumId : undefined,
|
albumId: albumId.length > 0 ? albumId : undefined,
|
||||||
artistId: artistId.length > 0 ? artistId : undefined,
|
artistId: artistId.length > 0 ? artistId : undefined,
|
||||||
|
genreId: genreId.length > 0 ? genreId : undefined,
|
||||||
songId: songId.length > 0 ? songId : undefined,
|
songId: songId.length > 0 ? songId : undefined,
|
||||||
},
|
},
|
||||||
modal: 'addToPlaylist',
|
modal: 'addToPlaylist',
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { VirtualGridAutoSizerContainer } from '/@/renderer/components/virtual-gr
|
||||||
import { VirtualTable } from '/@/renderer/components/virtual-table';
|
import { VirtualTable } from '/@/renderer/components/virtual-table';
|
||||||
import { useVirtualTable } from '/@/renderer/components/virtual-table/hooks/use-virtual-table';
|
import { useVirtualTable } from '/@/renderer/components/virtual-table/hooks/use-virtual-table';
|
||||||
import { useListContext } from '/@/renderer/context/list-context';
|
import { useListContext } from '/@/renderer/context/list-context';
|
||||||
import { ALBUM_CONTEXT_MENU_ITEMS } from '/@/renderer/features/context-menu/context-menu-items';
|
import { GENRE_CONTEXT_MENU_ITEMS } from '/@/renderer/features/context-menu/context-menu-items';
|
||||||
import { useCurrentServer } from '/@/renderer/store';
|
import { useCurrentServer } from '/@/renderer/store';
|
||||||
import { MutableRefObject, useCallback } from 'react';
|
import { MutableRefObject, useCallback } from 'react';
|
||||||
import { RowDoubleClickedEvent } from '@ag-grid-community/core';
|
import { RowDoubleClickedEvent } from '@ag-grid-community/core';
|
||||||
|
@ -22,7 +22,7 @@ export const GenreListTableView = ({ tableRef, itemCount }: GenreListTableViewPr
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const tableProps = useVirtualTable({
|
const tableProps = useVirtualTable({
|
||||||
contextMenu: ALBUM_CONTEXT_MENU_ITEMS,
|
contextMenu: GENRE_CONTEXT_MENU_ITEMS,
|
||||||
customFilters,
|
customFilters,
|
||||||
itemCount,
|
itemCount,
|
||||||
itemType: LibraryItem.GENRE,
|
itemType: LibraryItem.GENRE,
|
||||||
|
|
|
@ -1,24 +1,18 @@
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import { useCallback, useMemo, useRef } from 'react';
|
import { useMemo, useRef } from 'react';
|
||||||
import { api } from '/@/renderer/api';
|
import { GenreListSort, SortOrder } from '/@/renderer/api/types';
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
|
||||||
import { GenreListSort, LibraryItem, SortOrder } from '/@/renderer/api/types';
|
|
||||||
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
||||||
import { ListContext } from '/@/renderer/context/list-context';
|
import { ListContext } from '/@/renderer/context/list-context';
|
||||||
import { GenreListContent } from '/@/renderer/features/genres/components/genre-list-content';
|
import { GenreListContent } from '/@/renderer/features/genres/components/genre-list-content';
|
||||||
import { GenreListHeader } from '/@/renderer/features/genres/components/genre-list-header';
|
import { GenreListHeader } from '/@/renderer/features/genres/components/genre-list-header';
|
||||||
import { useGenreList } from '/@/renderer/features/genres/queries/genre-list-query';
|
import { useGenreList } from '/@/renderer/features/genres/queries/genre-list-query';
|
||||||
import { usePlayQueueAdd } from '/@/renderer/features/player';
|
|
||||||
import { AnimatedPage } from '/@/renderer/features/shared';
|
import { AnimatedPage } from '/@/renderer/features/shared';
|
||||||
import { queryClient } from '/@/renderer/lib/react-query';
|
|
||||||
import { useCurrentServer } from '/@/renderer/store';
|
import { useCurrentServer } from '/@/renderer/store';
|
||||||
import { Play } from '/@/renderer/types';
|
|
||||||
|
|
||||||
const GenreListRoute = () => {
|
const GenreListRoute = () => {
|
||||||
const gridRef = useRef<VirtualInfiniteGridRef | null>(null);
|
const gridRef = useRef<VirtualInfiniteGridRef | null>(null);
|
||||||
const tableRef = useRef<AgGridReactType | null>(null);
|
const tableRef = useRef<AgGridReactType | null>(null);
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
|
||||||
const pageKey = 'genre';
|
const pageKey = 'genre';
|
||||||
|
|
||||||
const itemCountCheck = useGenreList({
|
const itemCountCheck = useGenreList({
|
||||||
|
@ -36,44 +30,11 @@ const GenreListRoute = () => {
|
||||||
? undefined
|
? undefined
|
||||||
: itemCountCheck.data?.totalRecordCount;
|
: itemCountCheck.data?.totalRecordCount;
|
||||||
|
|
||||||
const handlePlay = useCallback(
|
|
||||||
async (args: { initialSongId?: string; playType: Play }) => {
|
|
||||||
if (!itemCount || itemCount === 0) return;
|
|
||||||
const { playType } = args;
|
|
||||||
const query = {
|
|
||||||
startIndex: 0,
|
|
||||||
};
|
|
||||||
const queryKey = queryKeys.albums.list(server?.id || '', query);
|
|
||||||
|
|
||||||
const albumListRes = await queryClient.fetchQuery({
|
|
||||||
queryFn: ({ signal }) => {
|
|
||||||
return api.controller.getAlbumList({
|
|
||||||
apiClientProps: { server, signal },
|
|
||||||
query,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
queryKey,
|
|
||||||
});
|
|
||||||
|
|
||||||
const albumIds = albumListRes?.items?.map((a) => a.id) || [];
|
|
||||||
|
|
||||||
handlePlayQueueAdd?.({
|
|
||||||
byItemType: {
|
|
||||||
id: albumIds,
|
|
||||||
type: LibraryItem.ALBUM,
|
|
||||||
},
|
|
||||||
playType,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[handlePlayQueueAdd, itemCount, server],
|
|
||||||
);
|
|
||||||
|
|
||||||
const providerValue = useMemo(() => {
|
const providerValue = useMemo(() => {
|
||||||
return {
|
return {
|
||||||
handlePlay,
|
|
||||||
pageKey,
|
pageKey,
|
||||||
};
|
};
|
||||||
}, [handlePlay]);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AnimatedPage>
|
<AnimatedPage>
|
||||||
|
|
|
@ -25,6 +25,7 @@ import {
|
||||||
getAlbumSongsById,
|
getAlbumSongsById,
|
||||||
getAlbumArtistSongsById,
|
getAlbumArtistSongsById,
|
||||||
getSongsByQuery,
|
getSongsByQuery,
|
||||||
|
getGenreSongsById,
|
||||||
} from '/@/renderer/features/player/utils';
|
} from '/@/renderer/features/player/utils';
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||||
|
|
||||||
|
@ -38,6 +39,9 @@ const getRootQueryKey = (itemType: LibraryItem, serverId: string) => {
|
||||||
case LibraryItem.ALBUM_ARTIST:
|
case LibraryItem.ALBUM_ARTIST:
|
||||||
queryKey = queryKeys.songs.list(serverId);
|
queryKey = queryKeys.songs.list(serverId);
|
||||||
break;
|
break;
|
||||||
|
case LibraryItem.GENRE:
|
||||||
|
queryKey = queryKeys.songs.list(serverId);
|
||||||
|
break;
|
||||||
case LibraryItem.PLAYLIST:
|
case LibraryItem.PLAYLIST:
|
||||||
queryKey = queryKeys.playlists.songList(serverId);
|
queryKey = queryKeys.playlists.songList(serverId);
|
||||||
break;
|
break;
|
||||||
|
@ -112,6 +116,8 @@ export const useHandlePlayQueueAdd = () => {
|
||||||
queryClient,
|
queryClient,
|
||||||
server,
|
server,
|
||||||
});
|
});
|
||||||
|
} else if (itemType === LibraryItem.GENRE) {
|
||||||
|
songList = await getGenreSongsById({ id, query, queryClient, server });
|
||||||
} else if (itemType === LibraryItem.SONG) {
|
} else if (itemType === LibraryItem.SONG) {
|
||||||
if (id?.length === 1) {
|
if (id?.length === 1) {
|
||||||
songList = await getSongById({ id: id?.[0], queryClient, server });
|
songList = await getSongById({ id: id?.[0], queryClient, server });
|
||||||
|
|
|
@ -9,7 +9,7 @@ import {
|
||||||
SongListSort,
|
SongListSort,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
} from '/@/renderer/api/types';
|
} from '/@/renderer/api/types';
|
||||||
import { ServerListItem } from '/@/renderer/types';
|
import { ServerListItem, ServerType } from '/@/renderer/types';
|
||||||
|
|
||||||
export const getPlaylistSongsById = async (args: {
|
export const getPlaylistSongsById = async (args: {
|
||||||
id: string;
|
id: string;
|
||||||
|
@ -86,6 +86,65 @@ export const getAlbumSongsById = async (args: {
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getGenreSongsById = async (args: {
|
||||||
|
id: string[];
|
||||||
|
orderByIds?: boolean;
|
||||||
|
query?: Partial<SongListQuery>;
|
||||||
|
queryClient: QueryClient;
|
||||||
|
server: ServerListItem | null;
|
||||||
|
}) => {
|
||||||
|
const { id, queryClient, server, query } = args;
|
||||||
|
|
||||||
|
const data: SongListResponse = {
|
||||||
|
items: [],
|
||||||
|
startIndex: 0,
|
||||||
|
totalRecordCount: 0,
|
||||||
|
};
|
||||||
|
for (const genreId of id) {
|
||||||
|
const queryFilter: SongListQuery = {
|
||||||
|
_custom: {
|
||||||
|
...(server?.type === ServerType.JELLYFIN && {
|
||||||
|
jellyfin: {
|
||||||
|
GenreIds: genreId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
...(server?.type === ServerType.NAVIDROME && {
|
||||||
|
navidrome: {
|
||||||
|
genre_id: genreId,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
},
|
||||||
|
sortBy: SongListSort.GENRE,
|
||||||
|
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,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
data.items.push(...res!.items);
|
||||||
|
data.totalRecordCount += res!.totalRecordCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
export const getAlbumArtistSongsById = async (args: {
|
export const getAlbumArtistSongsById = async (args: {
|
||||||
id: string[];
|
id: string[];
|
||||||
orderByIds?: boolean;
|
orderByIds?: boolean;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { api } from '/@/renderer/api';
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||||
import { PlaylistListSort, SongListQuery, SongListSort, SortOrder } from '/@/renderer/api/types';
|
import { PlaylistListSort, SongListQuery, SongListSort, SortOrder } from '/@/renderer/api/types';
|
||||||
import { Button, MultiSelect, Switch, toast } from '/@/renderer/components';
|
import { Button, MultiSelect, Switch, toast } from '/@/renderer/components';
|
||||||
|
import { getGenreSongsById } from '/@/renderer/features/player';
|
||||||
import { useAddToPlaylist } from '/@/renderer/features/playlists/mutations/add-to-playlist-mutation';
|
import { useAddToPlaylist } from '/@/renderer/features/playlists/mutations/add-to-playlist-mutation';
|
||||||
import { usePlaylistList } from '/@/renderer/features/playlists/queries/playlist-list-query';
|
import { usePlaylistList } from '/@/renderer/features/playlists/queries/playlist-list-query';
|
||||||
import { queryClient } from '/@/renderer/lib/react-query';
|
import { queryClient } from '/@/renderer/lib/react-query';
|
||||||
|
@ -17,9 +18,10 @@ export const AddToPlaylistContextModal = ({
|
||||||
}: ContextModalProps<{
|
}: ContextModalProps<{
|
||||||
albumId?: string[];
|
albumId?: string[];
|
||||||
artistId?: string[];
|
artistId?: string[];
|
||||||
|
genreId?: string[];
|
||||||
songId?: string[];
|
songId?: string[];
|
||||||
}>) => {
|
}>) => {
|
||||||
const { albumId, artistId, songId } = innerProps;
|
const { albumId, artistId, genreId, songId } = innerProps;
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
|
@ -112,6 +114,16 @@ export const AddToPlaylistContextModal = ({
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (genreId && genreId.length > 0) {
|
||||||
|
const songs = await getGenreSongsById({
|
||||||
|
id: genreId,
|
||||||
|
queryClient,
|
||||||
|
server,
|
||||||
|
});
|
||||||
|
|
||||||
|
allSongIds.push(...(songs?.items?.map((song) => song.id) || []));
|
||||||
|
}
|
||||||
|
|
||||||
if (songId && songId.length > 0) {
|
if (songId && songId.length > 0) {
|
||||||
allSongIds.push(...songId);
|
allSongIds.push(...songId);
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue