2023-05-09 02:25:57 -07:00
|
|
|
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
2022-12-19 15:59:14 -08:00
|
|
|
import { AnimatedPage } from '/@/renderer/features/shared';
|
|
|
|
|
import { AlbumListHeader } from '/@/renderer/features/albums/components/album-list-header';
|
2022-12-24 14:07:58 -08:00
|
|
|
import { AlbumListContent } from '/@/renderer/features/albums/components/album-list-content';
|
2022-12-24 20:20:17 -08:00
|
|
|
import { useRef } from 'react';
|
2022-12-28 01:44:49 -08:00
|
|
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
2023-01-07 03:28:03 -08:00
|
|
|
import { useAlbumList } from '/@/renderer/features/albums/queries/album-list-query';
|
2023-03-05 18:28:26 -08:00
|
|
|
import { generatePageKey, useAlbumListFilter, useCurrentServer } from '/@/renderer/store';
|
|
|
|
|
import { useParams, useSearchParams } from 'react-router-dom';
|
|
|
|
|
import { AlbumListContext } from '/@/renderer/features/albums/context/album-list-context';
|
2022-12-19 15:59:14 -08:00
|
|
|
|
|
|
|
|
const AlbumListRoute = () => {
|
2023-07-01 19:10:05 -07:00
|
|
|
const gridRef = useRef<VirtualInfiniteGridRef | null>(null);
|
|
|
|
|
const tableRef = useRef<AgGridReactType | null>(null);
|
|
|
|
|
const server = useCurrentServer();
|
2023-01-15 16:22:07 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const [searchParams] = useSearchParams();
|
|
|
|
|
const { albumArtistId } = useParams();
|
2023-01-15 16:22:07 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const pageKey = generatePageKey(
|
|
|
|
|
'album',
|
|
|
|
|
albumArtistId ? `${albumArtistId}_${server?.id}` : undefined,
|
|
|
|
|
);
|
2023-03-05 18:28:26 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const albumListFilter = useAlbumListFilter({ id: albumArtistId || undefined, key: pageKey });
|
2023-01-07 03:28:03 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const itemCountCheck = useAlbumList({
|
|
|
|
|
options: {
|
|
|
|
|
cacheTime: 1000 * 60,
|
|
|
|
|
staleTime: 1000 * 60,
|
|
|
|
|
},
|
|
|
|
|
query: {
|
|
|
|
|
limit: 1,
|
|
|
|
|
startIndex: 0,
|
|
|
|
|
...albumListFilter,
|
|
|
|
|
},
|
|
|
|
|
serverId: server?.id,
|
|
|
|
|
});
|
2023-01-07 03:28:03 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
const itemCount =
|
|
|
|
|
itemCountCheck.data?.totalRecordCount === null
|
|
|
|
|
? undefined
|
|
|
|
|
: itemCountCheck.data?.totalRecordCount;
|
2022-12-24 20:20:17 -08:00
|
|
|
|
2023-07-01 19:10:05 -07:00
|
|
|
return (
|
|
|
|
|
<AnimatedPage>
|
|
|
|
|
<AlbumListContext.Provider value={{ id: albumArtistId || undefined, pageKey }}>
|
|
|
|
|
<AlbumListHeader
|
|
|
|
|
gridRef={gridRef}
|
|
|
|
|
itemCount={itemCount}
|
|
|
|
|
tableRef={tableRef}
|
|
|
|
|
title={searchParams.get('artistName') || undefined}
|
|
|
|
|
/>
|
|
|
|
|
<AlbumListContent
|
|
|
|
|
gridRef={gridRef}
|
|
|
|
|
itemCount={itemCount}
|
|
|
|
|
tableRef={tableRef}
|
|
|
|
|
/>
|
|
|
|
|
</AlbumListContext.Provider>
|
|
|
|
|
</AnimatedPage>
|
|
|
|
|
);
|
2022-12-19 15:59:14 -08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default AlbumListRoute;
|