feishin/src/renderer/features/artists/routes/album-artist-detail-top-songs-list-route.tsx

63 lines
2.4 KiB
TypeScript
Raw Normal View History

import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
import { useMemo, useRef } from 'react';
2023-01-13 13:51:19 -08:00
import { useParams } from 'react-router';
import { ListContext } from '/@/renderer/context/list-context';
2023-01-13 13:51:19 -08:00
import { AlbumArtistDetailTopSongsListContent } from '/@/renderer/features/artists/components/album-artist-detail-top-songs-list-content';
import { AlbumArtistDetailTopSongsListHeader } from '/@/renderer/features/artists/components/album-artist-detail-top-songs-list-header';
import { useAlbumArtistDetail } from '/@/renderer/features/artists/queries/album-artist-detail-query';
import { useTopSongsList } from '/@/renderer/features/artists/queries/top-songs-list-query';
import { AnimatedPage } from '/@/renderer/features/shared';
2025-05-20 19:23:36 -07:00
import { useCurrentServer } from '/@/renderer/store/auth.store';
import { LibraryItem } from '/@/shared/types/domain-types';
2023-01-13 13:51:19 -08:00
const AlbumArtistDetailTopSongsListRoute = () => {
2023-07-01 19:10:05 -07:00
const tableRef = useRef<AgGridReactType | null>(null);
2025-05-06 14:43:42 -07:00
const { albumArtistId, artistId } = useParams() as {
albumArtistId?: string;
artistId?: string;
};
const routeId = (artistId || albumArtistId) as string;
2023-07-01 19:10:05 -07:00
const server = useCurrentServer();
const pageKey = LibraryItem.SONG;
2023-01-13 13:51:19 -08:00
2023-07-01 19:10:05 -07:00
const detailQuery = useAlbumArtistDetail({
2025-05-06 14:43:42 -07:00
query: { id: routeId },
2023-07-01 19:10:05 -07:00
serverId: server?.id,
});
2023-01-13 13:51:19 -08:00
2023-07-01 19:10:05 -07:00
const topSongsQuery = useTopSongsList({
options: { enabled: !!detailQuery?.data?.name },
2025-05-06 14:43:42 -07:00
query: { artist: detailQuery?.data?.name || '', artistId: routeId },
2023-07-01 19:10:05 -07:00
serverId: server?.id,
});
2023-01-13 13:51:19 -08:00
2023-07-01 19:10:05 -07:00
const itemCount = topSongsQuery?.data?.items?.length || 0;
2023-01-13 13:51:19 -08:00
2023-08-08 00:38:32 -07:00
const providerValue = useMemo(() => {
return {
2025-05-06 14:43:42 -07:00
id: routeId,
2023-08-08 00:38:32 -07:00
pageKey,
};
2025-05-06 14:43:42 -07:00
}, [routeId, pageKey]);
2023-01-13 13:51:19 -08:00
2023-07-01 19:10:05 -07:00
return (
<AnimatedPage>
2023-08-08 00:38:32 -07:00
<ListContext.Provider value={providerValue}>
<AlbumArtistDetailTopSongsListHeader
data={topSongsQuery?.data?.items || []}
itemCount={itemCount}
title={detailQuery?.data?.name || 'Unknown'}
/>
<AlbumArtistDetailTopSongsListContent
data={topSongsQuery?.data?.items || []}
tableRef={tableRef}
/>
</ListContext.Provider>
2023-07-01 19:10:05 -07:00
</AnimatedPage>
);
2023-01-13 13:51:19 -08:00
};
export default AlbumArtistDetailTopSongsListRoute;