2023-01-13 13:51:19 -08:00
|
|
|
import { useRef } from 'react';
|
2023-04-30 22:01:52 -07:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
2023-01-13 13:51:19 -08:00
|
|
|
import { useParams } from 'react-router';
|
|
|
|
|
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';
|
2023-04-30 22:01:52 -07:00
|
|
|
import { useCurrentServer } from '../../../store/auth.store';
|
2023-01-13 13:51:19 -08:00
|
|
|
|
|
|
|
|
const AlbumArtistDetailTopSongsListRoute = () => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const tableRef = useRef<AgGridReactType | null>(null);
|
|
|
|
|
const { albumArtistId } = useParams() as { albumArtistId: string };
|
|
|
|
|
const server = useCurrentServer();
|
2023-01-13 13:51:19 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const detailQuery = useAlbumArtistDetail({
|
|
|
|
|
query: { id: albumArtistId },
|
|
|
|
|
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 },
|
|
|
|
|
query: { artist: detailQuery?.data?.name || '', artistId: albumArtistId },
|
|
|
|
|
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-07-01 19:10:05 -07:00
|
|
|
if (detailQuery.isLoading || topSongsQuery?.isLoading) return null;
|
2023-01-13 13:51:19 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<AnimatedPage>
|
|
|
|
|
<AlbumArtistDetailTopSongsListHeader
|
|
|
|
|
data={topSongsQuery?.data?.items || []}
|
|
|
|
|
itemCount={itemCount}
|
|
|
|
|
title={detailQuery?.data?.name || 'Unknown'}
|
|
|
|
|
/>
|
|
|
|
|
<AlbumArtistDetailTopSongsListContent
|
|
|
|
|
data={topSongsQuery?.data?.items || []}
|
|
|
|
|
tableRef={tableRef}
|
|
|
|
|
/>
|
|
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
2023-01-13 13:51:19 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AlbumArtistDetailTopSongsListRoute;
|