mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Split key pagination in central handler
This commit is contained in:
parent
1cb0a1d72a
commit
6821735f65
4 changed files with 91 additions and 103 deletions
|
|
@ -1,11 +1,11 @@
|
|||
import { MutableRefObject, useCallback, useMemo } from 'react';
|
||||
import { IDatasource } from '@ag-grid-community/core';
|
||||
import type { AgGridReact as AgGridReactType } from '@ag-grid-community/react/lib/agGridReact';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys, QueryPagination } from '/@/renderer/api/query-keys';
|
||||
import { LibraryItem, ServerListItem, BasePaginatedResponse } from '/@/renderer/api/types';
|
||||
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
||||
import { QueryKey, useQueryClient } from '@tanstack/react-query';
|
||||
import { MutableRefObject, useCallback, useMemo } from 'react';
|
||||
import { api } from '/@/renderer/api';
|
||||
import { queryKeys } from '/@/renderer/api/query-keys';
|
||||
import { BasePaginatedResponse, LibraryItem, ServerListItem } from '/@/renderer/api/types';
|
||||
import { VirtualInfiniteGridRef } from '/@/renderer/components/virtual-grid';
|
||||
|
||||
interface UseHandleListFilterChangeProps {
|
||||
itemType: LibraryItem;
|
||||
|
|
@ -15,24 +15,23 @@ interface UseHandleListFilterChangeProps {
|
|||
export const useListFilterRefresh = ({ server, itemType }: UseHandleListFilterChangeProps) => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
const queryKeyFn:
|
||||
| ((serverId: string, query: Record<any, any>, pagination: QueryPagination) => QueryKey)
|
||||
| null = useMemo(() => {
|
||||
if (itemType === LibraryItem.ALBUM) {
|
||||
return queryKeys.albums.list;
|
||||
}
|
||||
if (itemType === LibraryItem.ALBUM_ARTIST) {
|
||||
return queryKeys.albumArtists.list;
|
||||
}
|
||||
if (itemType === LibraryItem.PLAYLIST) {
|
||||
return queryKeys.playlists.list;
|
||||
}
|
||||
if (itemType === LibraryItem.SONG) {
|
||||
return queryKeys.songs.list;
|
||||
}
|
||||
const queryKeyFn: ((serverId: string, query: Record<any, any>) => QueryKey) | null =
|
||||
useMemo(() => {
|
||||
if (itemType === LibraryItem.ALBUM) {
|
||||
return queryKeys.albums.list;
|
||||
}
|
||||
if (itemType === LibraryItem.ALBUM_ARTIST) {
|
||||
return queryKeys.albumArtists.list;
|
||||
}
|
||||
if (itemType === LibraryItem.PLAYLIST) {
|
||||
return queryKeys.playlists.list;
|
||||
}
|
||||
if (itemType === LibraryItem.SONG) {
|
||||
return queryKeys.songs.list;
|
||||
}
|
||||
|
||||
return null;
|
||||
}, [itemType]);
|
||||
return null;
|
||||
}, [itemType]);
|
||||
|
||||
const queryFn: ((args: any) => Promise<BasePaginatedResponse<any> | null | undefined>) | null =
|
||||
useMemo(() => {
|
||||
|
|
@ -63,13 +62,9 @@ export const useListFilterRefresh = ({ server, itemType }: UseHandleListFilterCh
|
|||
const limit = params.endRow - params.startRow;
|
||||
const startIndex = params.startRow;
|
||||
|
||||
const query = filter;
|
||||
const pagination = {
|
||||
limit,
|
||||
startIndex,
|
||||
};
|
||||
const query = { ...filter, limit, startIndex };
|
||||
|
||||
const queryKey = queryKeyFn(server?.id || '', query, pagination);
|
||||
const queryKey = queryKeyFn(server?.id || '', query);
|
||||
|
||||
const res = await queryClient.fetchQuery({
|
||||
queryFn: async ({ signal }) => {
|
||||
|
|
@ -107,13 +102,9 @@ export const useListFilterRefresh = ({ server, itemType }: UseHandleListFilterCh
|
|||
gridRef.current?.resetLoadMoreItemsCache();
|
||||
gridRef.current?.setItemData([]);
|
||||
|
||||
const query = filter;
|
||||
const pagination = {
|
||||
limit: 200,
|
||||
startIndex: 0,
|
||||
};
|
||||
const query = { ...filter, limit: 200, startIndex: 0 };
|
||||
|
||||
const queryKey = queryKeyFn(server?.id || '', query, pagination);
|
||||
const queryKey = queryKeyFn(server?.id || '', query);
|
||||
|
||||
const res = await queryClient.fetchQuery({
|
||||
queryFn: async ({ signal }) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue