mirror of
https://github.com/spacedriveapp/spacedrive.git
synced 2026-04-21 23:18:06 -04:00
* prototype * `.normalise` helper + only `String` keys * implement it for 'search.paths' * redux devtools * fix * refactor backend * wip: upgrade to rspc fork * mega cursed * Upgrade Specta-related stuff * Upgrade Typescript * Cache debug page * bruh * Fix optimistic library setting * Cache clearing * better timeout * Fix tags page * bit of cleanup --------- Co-authored-by: Brendan Allan <brendonovich@outlook.com>
21 lines
754 B
TypeScript
21 lines
754 B
TypeScript
import { UseInfiniteQueryResult, UseQueryResult } from '@tanstack/react-query';
|
|
import { useCallback, useMemo } from 'react';
|
|
import { SearchData, useCache } from '@sd/client';
|
|
|
|
export function useExplorerQuery<Q>(
|
|
query: UseInfiniteQueryResult<SearchData<Q>>,
|
|
count: UseQueryResult<number>
|
|
) {
|
|
const items = useMemo(() => query.data?.pages.flatMap((d) => d.items) ?? null, [query.data]);
|
|
|
|
const loadMore = useCallback(() => {
|
|
if (query.hasNextPage && !query.isFetchingNextPage) {
|
|
query.fetchNextPage.call(undefined);
|
|
}
|
|
}, [query.hasNextPage, query.isFetchingNextPage, query.fetchNextPage]);
|
|
|
|
return { query, items: useCache(items), loadMore, count: count.data };
|
|
}
|
|
|
|
export type UseExplorerQuery<Q> = ReturnType<typeof useExplorerQuery<Q>>;
|