From 64cb4eb2497d6d3f7ec81d2d603a6931c35b682e Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Mon, 19 Aug 2024 15:35:02 +0800 Subject: [PATCH] Instead of checking limit use initial index for cache checks --- .../web/lib/networking/library_items/useLibraryItems.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/web/lib/networking/library_items/useLibraryItems.tsx b/packages/web/lib/networking/library_items/useLibraryItems.tsx index a95830ce7..d9fa8ccbc 100644 --- a/packages/web/lib/networking/library_items/useLibraryItems.tsx +++ b/packages/web/lib/networking/library_items/useLibraryItems.tsx @@ -231,6 +231,8 @@ export function useGetLibraryItems( enabled = true ) { const queryClient = useQueryClient() + + const INITIAL_INDEX = '0' const fullQuery = folder ? (`in:${folder} use:folders ` + (searchQuery ?? '')).trim() : searchQuery ?? '' @@ -242,7 +244,7 @@ export function useGetLibraryItems( queryFn: async ({ queryKey, pageParam, meta }) => { console.log('pageParam and limit', Number(pageParam), limit) const cached = queryClient.getQueryData(queryKey) as CachedPagesData - if (Number(pageParam) > limit) { + if (pageParam !== INITIAL_INDEX) { // check in the query cache, if there is an item for this page // in the query page, check if pageIndex - 1 was unchanged since // the last query, this will determine if we should refetch this @@ -302,7 +304,7 @@ export function useGetLibraryItems( } }, enabled, - initialPageParam: '0', + initialPageParam: INITIAL_INDEX, getNextPageParam: (lastPage: LibraryItems, pages) => { return lastPage.pageInfo.hasNextPage ? lastPage?.pageInfo?.endCursor