2022-12-27 13:52:50 -08:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
|
|
|
|
import { useRef } from 'react';
|
2023-03-05 18:28:26 -08:00
|
|
|
import { useParams, useSearchParams } from 'react-router-dom';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { AnimatedPage } from '/@/renderer/features/shared';
|
2022-12-27 13:52:50 -08:00
|
|
|
import { SongListContent } from '/@/renderer/features/songs/components/song-list-content';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { SongListHeader } from '/@/renderer/features/songs/components/song-list-header';
|
2023-03-05 18:28:26 -08:00
|
|
|
import { SongListContext } from '/@/renderer/features/songs/context/song-list-context';
|
2023-01-07 03:28:03 -08:00
|
|
|
import { useSongList } from '/@/renderer/features/songs/queries/song-list-query';
|
2023-03-05 18:28:26 -08:00
|
|
|
import { generatePageKey, useCurrentServer, useSongListFilter } from '/@/renderer/store';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const TrackListRoute = () => {
|
2022-12-27 13:52:50 -08:00
|
|
|
const tableRef = useRef<AgGridReactType | null>(null);
|
2023-03-05 18:28:26 -08:00
|
|
|
const server = useCurrentServer();
|
2023-01-15 20:39:43 -08:00
|
|
|
const [searchParams] = useSearchParams();
|
2023-03-05 18:28:26 -08:00
|
|
|
const { albumArtistId } = useParams();
|
|
|
|
|
const pageKey = generatePageKey(
|
|
|
|
|
'song',
|
|
|
|
|
albumArtistId ? `${albumArtistId}_${server?.id}` : undefined,
|
|
|
|
|
);
|
2023-01-15 20:39:43 -08:00
|
|
|
|
2023-03-05 18:28:26 -08:00
|
|
|
const songListFilter = useSongListFilter({ id: albumArtistId, key: pageKey });
|
2023-04-30 22:01:52 -07:00
|
|
|
const itemCountCheck = useSongList({
|
|
|
|
|
options: {
|
|
|
|
|
cacheTime: 1000 * 60,
|
|
|
|
|
staleTime: 1000 * 60,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
2023-01-07 03:28:03 -08:00
|
|
|
limit: 1,
|
|
|
|
|
startIndex: 0,
|
2023-03-05 18:28:26 -08:00
|
|
|
...songListFilter,
|
2023-01-07 03:28:03 -08:00
|
|
|
},
|
2023-04-30 22:01:52 -07:00
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-01-07 03:28:03 -08:00
|
|
|
|
|
|
|
|
const itemCount =
|
|
|
|
|
itemCountCheck.data?.totalRecordCount === null
|
|
|
|
|
? undefined
|
|
|
|
|
: itemCountCheck.data?.totalRecordCount;
|
|
|
|
|
|
2022-12-19 15:59:14 -08:00
|
|
|
return (
|
|
|
|
|
<AnimatedPage>
|
2023-03-05 18:28:26 -08:00
|
|
|
<SongListContext.Provider value={{ id: albumArtistId, pageKey }}>
|
|
|
|
|
<SongListHeader
|
|
|
|
|
itemCount={itemCount}
|
|
|
|
|
tableRef={tableRef}
|
|
|
|
|
title={searchParams.get('artistName') || undefined}
|
|
|
|
|
/>
|
|
|
|
|
<SongListContent
|
|
|
|
|
itemCount={itemCount}
|
|
|
|
|
tableRef={tableRef}
|
|
|
|
|
/>
|
|
|
|
|
</SongListContext.Provider>
|
2022-12-19 15:59:14 -08:00
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default TrackListRoute;
|