From 9e8741c72cf80467037b5470526e7ce172096fc2 Mon Sep 17 00:00:00 2001 From: make-github-pseudonymous-again <5165674+make-github-pseudonymous-again@users.noreply.github.com> Date: Wed, 25 Dec 2024 14:05:23 +0100 Subject: [PATCH] :adhesive_bandage: fix(makeQuery): Fix loading flicker. By leveraging new generic hook `useQuery`. --- imports/api/makeQuery.ts | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/imports/api/makeQuery.ts b/imports/api/makeQuery.ts index 92a0edf09..ab1e4716f 100644 --- a/imports/api/makeQuery.ts +++ b/imports/api/makeQuery.ts @@ -1,8 +1,9 @@ +import assert from 'assert'; + import {type DependencyList} from 'react'; import type PublicationEndpoint from './publication/PublicationEndpoint'; -import useSubscription from './publication/useSubscription'; -import useCursor from './publication/useCursor'; +import useQuery from './publication/useQuery'; import type Collection from './Collection'; import type Document from './Document'; @@ -15,16 +16,17 @@ const makeQuery = publication: PublicationEndpoint<[UserQuery]>, ) => (query: UserQuery | null, deps: DependencyList) => { - const isLoading = useSubscription(publication, [query], query !== null); - const loadingSubscription = isLoading(); - const [selector, options] = - query === null ? [] : queryToSelectorOptionsPair(query); - const {loading: loadingResults, results} = useCursor( - () => (query === null ? null : collection.find(selector, options)), + return useQuery( + publication, + [query], + () => { + assert(query !== null); + const [selector, options] = queryToSelectorOptionsPair(query); + return collection.find(selector, options); + }, deps, + query !== null, ); - const loading = loadingSubscription || loadingResults; - return {loading, results}; }; export default makeQuery;