feishin/src/renderer/features/songs/components/song-list-content.tsx

49 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-27 13:52:50 -08:00
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
2023-07-16 11:44:33 -07:00
import { lazy, MutableRefObject, Suspense } from 'react';
import { Spinner } from '/@/renderer/components';
2023-07-19 20:04:56 -07:00
import { useListContext } from '/@/renderer/context/list-context';
import { useListStoreByKey } from '/@/renderer/store';
2023-07-16 11:44:33 -07:00
import { ListDisplayType } from '/@/renderer/types';
2023-09-23 15:36:57 -07:00
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
2023-07-16 11:44:33 -07:00
const SongListTableView = lazy(() =>
import('/@/renderer/features/songs/components/song-list-table-view').then((module) => ({
default: module.SongListTableView,
})),
);
2022-12-27 13:52:50 -08:00
2023-09-23 15:36:57 -07:00
const SongListGridView = lazy(() =>
import('/@/renderer/features/songs/components/song-list-grid-view').then((module) => ({
default: module.SongListGridView,
})),
);
2022-12-27 13:52:50 -08:00
interface SongListContentProps {
2023-09-23 15:36:57 -07:00
gridRef: MutableRefObject<VirtualInfiniteGridRef | null>;
2023-07-01 19:10:05 -07:00
itemCount?: number;
tableRef: MutableRefObject<AgGridReactType | null>;
2022-12-27 13:52:50 -08:00
}
2023-09-23 15:36:57 -07:00
export const SongListContent = ({ itemCount, gridRef, tableRef }: SongListContentProps) => {
2023-07-19 20:04:56 -07:00
const { pageKey } = useListContext();
const { display } = useListStoreByKey({ key: pageKey });
2023-07-01 19:10:05 -07:00
2023-07-16 11:44:33 -07:00
const isGrid = display === ListDisplayType.CARD || display === ListDisplayType.POSTER;
2023-07-01 19:10:05 -07:00
return (
2023-07-16 11:44:33 -07:00
<Suspense fallback={<Spinner container />}>
{isGrid ? (
2023-09-23 15:36:57 -07:00
<SongListGridView
gridRef={gridRef}
itemCount={itemCount}
/>
2023-07-16 11:44:33 -07:00
) : (
<SongListTableView
itemCount={itemCount}
tableRef={tableRef}
2023-07-01 19:10:05 -07:00
/>
2023-07-16 11:44:33 -07:00
)}
</Suspense>
2023-07-01 19:10:05 -07:00
);
2022-12-27 13:52:50 -08:00
};