diff options
| author | Mohamed Bassem <me@mbassem.com> | 2024-12-22 16:17:22 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2024-12-22 23:38:38 +0000 |
| commit | 353e5d6374c77a2744590a5bfd3329672009b281 (patch) | |
| tree | 5a64f13ddc930fbcf699101248b35f72cda6fc6b /apps/web/lib/hooks | |
| parent | 71d7490d0a647e9254bf15b38201177057d88f95 (diff) | |
| download | karakeep-353e5d6374c77a2744590a5bfd3329672009b281.tar.zst | |
feat: Add basic pagination to searchBookmarks tRPC
Diffstat (limited to 'apps/web/lib/hooks')
| -rw-r--r-- | apps/web/lib/hooks/bookmark-search.ts | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/apps/web/lib/hooks/bookmark-search.ts b/apps/web/lib/hooks/bookmark-search.ts index ffdf402d..9890ac6f 100644 --- a/apps/web/lib/hooks/bookmark-search.ts +++ b/apps/web/lib/hooks/bookmark-search.ts @@ -50,16 +50,25 @@ export function useDoBookmarkSearch() { export function useBookmarkSearch() { const { searchQuery } = useSearchQuery(); - const { data, isPending, isPlaceholderData, error } = - api.bookmarks.searchBookmarks.useQuery( - { - text: searchQuery, - }, - { - placeholderData: keepPreviousData, - gcTime: 0, - }, - ); + const { + data, + isPending, + isPlaceholderData, + error, + hasNextPage, + fetchNextPage, + isFetchingNextPage, + } = api.bookmarks.searchBookmarks.useInfiniteQuery( + { + text: searchQuery, + }, + { + placeholderData: keepPreviousData, + gcTime: 0, + initialCursor: null, + getNextPageParam: (lastPage) => lastPage.nextCursor, + }, + ); if (error) { throw error; @@ -71,5 +80,8 @@ export function useBookmarkSearch() { data, isPending, isPlaceholderData, + hasNextPage, + fetchNextPage, + isFetchingNextPage, }; } |
