Set grid view to use local state
This commit is contained in:
parent
77bfb916ba
commit
90b503906f
3 changed files with 12 additions and 20 deletions
|
@ -1,4 +1,12 @@
|
||||||
import { useRef, useMemo, useCallback, forwardRef, Ref, useImperativeHandle } from 'react';
|
import {
|
||||||
|
useState,
|
||||||
|
useRef,
|
||||||
|
useMemo,
|
||||||
|
useCallback,
|
||||||
|
forwardRef,
|
||||||
|
Ref,
|
||||||
|
useImperativeHandle,
|
||||||
|
} from 'react';
|
||||||
import debounce from 'lodash/debounce';
|
import debounce from 'lodash/debounce';
|
||||||
import type { FixedSizeListProps } from 'react-window';
|
import type { FixedSizeListProps } from 'react-window';
|
||||||
import InfiniteLoader from 'react-window-infinite-loader';
|
import InfiniteLoader from 'react-window-infinite-loader';
|
||||||
|
@ -19,14 +27,12 @@ interface VirtualGridProps extends Omit<FixedSizeListProps, 'children' | 'itemSi
|
||||||
fetchFn: (options: { columnCount: number; skip: number; take: number }) => Promise<any>;
|
fetchFn: (options: { columnCount: number; skip: number; take: number }) => Promise<any>;
|
||||||
handleFavorite?: (options: { id: string[]; isFavorite: boolean; itemType: LibraryItem }) => void;
|
handleFavorite?: (options: { id: string[]; isFavorite: boolean; itemType: LibraryItem }) => void;
|
||||||
handlePlayQueueAdd?: (options: PlayQueueAddOptions) => void;
|
handlePlayQueueAdd?: (options: PlayQueueAddOptions) => void;
|
||||||
itemData: any[];
|
|
||||||
itemGap: number;
|
itemGap: number;
|
||||||
itemSize: number;
|
itemSize: number;
|
||||||
itemType: LibraryItem;
|
itemType: LibraryItem;
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
minimumBatchSize?: number;
|
minimumBatchSize?: number;
|
||||||
route?: CardRoute;
|
route?: CardRoute;
|
||||||
setItemData: (data: any[]) => void;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const VirtualInfiniteGrid = forwardRef(
|
export const VirtualInfiniteGrid = forwardRef(
|
||||||
|
@ -37,8 +43,6 @@ export const VirtualInfiniteGrid = forwardRef(
|
||||||
itemSize,
|
itemSize,
|
||||||
itemType,
|
itemType,
|
||||||
cardRows,
|
cardRows,
|
||||||
itemData,
|
|
||||||
setItemData,
|
|
||||||
route,
|
route,
|
||||||
onScroll,
|
onScroll,
|
||||||
display,
|
display,
|
||||||
|
@ -56,6 +60,8 @@ export const VirtualInfiniteGrid = forwardRef(
|
||||||
const listRef = useRef<any>(null);
|
const listRef = useRef<any>(null);
|
||||||
const loader = useRef<InfiniteLoader>(null);
|
const loader = useRef<InfiniteLoader>(null);
|
||||||
|
|
||||||
|
const [itemData, setItemData] = useState<any[]>([]);
|
||||||
|
|
||||||
const { itemHeight, rowCount, columnCount } = useMemo(() => {
|
const { itemHeight, rowCount, columnCount } = useMemo(() => {
|
||||||
const itemsPerRow = itemSize;
|
const itemsPerRow = itemSize;
|
||||||
const widthPerItem = Number(width) / itemsPerRow;
|
const widthPerItem = Number(width) / itemsPerRow;
|
||||||
|
|
|
@ -20,7 +20,6 @@ import { useQueryClient } from '@tanstack/react-query';
|
||||||
import {
|
import {
|
||||||
useCurrentServer,
|
useCurrentServer,
|
||||||
useAlbumListStore,
|
useAlbumListStore,
|
||||||
useAlbumListItemData,
|
|
||||||
useListStoreActions,
|
useListStoreActions,
|
||||||
useAlbumListFilter,
|
useAlbumListFilter,
|
||||||
} from '/@/renderer/store';
|
} from '/@/renderer/store';
|
||||||
|
@ -53,9 +52,6 @@ export const AlbumListContent = ({ itemCount, gridRef, tableRef }: AlbumListCont
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const server = useCurrentServer();
|
const server = useCurrentServer();
|
||||||
const handlePlayQueueAdd = usePlayQueueAdd();
|
const handlePlayQueueAdd = usePlayQueueAdd();
|
||||||
|
|
||||||
const { itemData, setItemData } = useAlbumListItemData();
|
|
||||||
|
|
||||||
const { id, pageKey } = useAlbumListContext();
|
const { id, pageKey } = useAlbumListContext();
|
||||||
const filter = useAlbumListFilter({ id, key: pageKey });
|
const filter = useAlbumListFilter({ id, key: pageKey });
|
||||||
const { setTable, setTablePagination, setGrid } = useListStoreActions();
|
const { setTable, setTablePagination, setGrid } = useListStoreActions();
|
||||||
|
@ -316,7 +312,6 @@ export const AlbumListContent = ({ itemCount, gridRef, tableRef }: AlbumListCont
|
||||||
height={height}
|
height={height}
|
||||||
initialScrollOffset={grid?.scrollOffset || 0}
|
initialScrollOffset={grid?.scrollOffset || 0}
|
||||||
itemCount={itemCount || 0}
|
itemCount={itemCount || 0}
|
||||||
itemData={itemData}
|
|
||||||
itemGap={20}
|
itemGap={20}
|
||||||
itemSize={grid?.itemsPerRow || 5}
|
itemSize={grid?.itemsPerRow || 5}
|
||||||
itemType={LibraryItem.ALBUM}
|
itemType={LibraryItem.ALBUM}
|
||||||
|
@ -326,7 +321,6 @@ export const AlbumListContent = ({ itemCount, gridRef, tableRef }: AlbumListCont
|
||||||
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
route: AppRoute.LIBRARY_ALBUMS_DETAIL,
|
||||||
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
slugs: [{ idProperty: 'id', slugProperty: 'albumId' }],
|
||||||
}}
|
}}
|
||||||
setItemData={setItemData}
|
|
||||||
width={width}
|
width={width}
|
||||||
onScroll={handleGridScroll}
|
onScroll={handleGridScroll}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -16,11 +16,7 @@ import { api } from '/@/renderer/api';
|
||||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||||
import { AlbumArtist, AlbumArtistListSort, LibraryItem } from '/@/renderer/api/types';
|
import { AlbumArtist, AlbumArtistListSort, LibraryItem } from '/@/renderer/api/types';
|
||||||
import { useQueryClient } from '@tanstack/react-query';
|
import { useQueryClient } from '@tanstack/react-query';
|
||||||
import {
|
import { useCurrentServer, useAlbumArtistListStore } from '/@/renderer/store';
|
||||||
useCurrentServer,
|
|
||||||
useAlbumArtistListStore,
|
|
||||||
useAlbumArtistListItemData,
|
|
||||||
} from '/@/renderer/store';
|
|
||||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||||
import {
|
import {
|
||||||
BodyScrollEvent,
|
BodyScrollEvent,
|
||||||
|
@ -55,7 +51,6 @@ export const AlbumArtistListContent = ({ gridRef, tableRef }: AlbumArtistListCon
|
||||||
const filter = useAlbumArtistListFilter({ id, key: pageKey });
|
const filter = useAlbumArtistListFilter({ id, key: pageKey });
|
||||||
const { table, grid, display } = useAlbumArtistListStore();
|
const { table, grid, display } = useAlbumArtistListStore();
|
||||||
const { setTable, setTablePagination, setGrid } = useListStoreActions();
|
const { setTable, setTablePagination, setGrid } = useListStoreActions();
|
||||||
const { itemData, setItemData } = useAlbumArtistListItemData();
|
|
||||||
|
|
||||||
const isPaginationEnabled = display === ListDisplayType.TABLE_PAGINATED;
|
const isPaginationEnabled = display === ListDisplayType.TABLE_PAGINATED;
|
||||||
|
|
||||||
|
@ -265,7 +260,6 @@ export const AlbumArtistListContent = ({ gridRef, tableRef }: AlbumArtistListCon
|
||||||
<AutoSizer>
|
<AutoSizer>
|
||||||
{({ height, width }) => (
|
{({ height, width }) => (
|
||||||
<VirtualInfiniteGrid
|
<VirtualInfiniteGrid
|
||||||
key={`albumartist-list-${server?.id}-${display}`}
|
|
||||||
ref={gridRef}
|
ref={gridRef}
|
||||||
cardRows={cardRows}
|
cardRows={cardRows}
|
||||||
display={display || ListDisplayType.CARD}
|
display={display || ListDisplayType.CARD}
|
||||||
|
@ -274,7 +268,6 @@ export const AlbumArtistListContent = ({ gridRef, tableRef }: AlbumArtistListCon
|
||||||
height={height}
|
height={height}
|
||||||
initialScrollOffset={grid?.scrollOffset || 0}
|
initialScrollOffset={grid?.scrollOffset || 0}
|
||||||
itemCount={checkAlbumArtistList?.data?.totalRecordCount || 0}
|
itemCount={checkAlbumArtistList?.data?.totalRecordCount || 0}
|
||||||
itemData={itemData}
|
|
||||||
itemGap={20}
|
itemGap={20}
|
||||||
itemSize={grid?.itemsPerRow || 5}
|
itemSize={grid?.itemsPerRow || 5}
|
||||||
itemType={LibraryItem.ALBUM_ARTIST}
|
itemType={LibraryItem.ALBUM_ARTIST}
|
||||||
|
@ -284,7 +277,6 @@ export const AlbumArtistListContent = ({ gridRef, tableRef }: AlbumArtistListCon
|
||||||
route: AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL,
|
route: AppRoute.LIBRARY_ALBUM_ARTISTS_DETAIL,
|
||||||
slugs: [{ idProperty: 'id', slugProperty: 'albumArtistId' }],
|
slugs: [{ idProperty: 'id', slugProperty: 'albumArtistId' }],
|
||||||
}}
|
}}
|
||||||
setItemData={setItemData}
|
|
||||||
width={width}
|
width={width}
|
||||||
onScroll={handleGridScroll}
|
onScroll={handleGridScroll}
|
||||||
/>
|
/>
|
||||||
|
|
Reference in a new issue