diff options
author | Samuel Newman <mozzius@protonmail.com> | 2024-04-10 23:32:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-10 23:32:31 +0100 |
commit | 9007810cdb5ffc8fbdf8e2a2af6c073b76b318f3 (patch) | |
tree | 13b19716a4de5373d6c74039f7d8d674ad9ef893 /src/state/queries | |
parent | 310d86544028e0b168be3f0c55259bcc852aaa8e (diff) | |
download | voidsky-9007810cdb5ffc8fbdf8e2a2af6c073b76b318f3.tar.zst |
Search - only enable queries once tab is active (#3471)
* only enable queries once tab is active * remove hasBeenTrue hook * make enabled optional
Diffstat (limited to 'src/state/queries')
-rw-r--r-- | src/state/queries/actor-search.ts | 16 | ||||
-rw-r--r-- | src/state/queries/search-posts.ts | 3 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/state/queries/actor-search.ts b/src/state/queries/actor-search.ts index f19916103..eb065b6cf 100644 --- a/src/state/queries/actor-search.ts +++ b/src/state/queries/actor-search.ts @@ -5,19 +5,25 @@ import {STALE} from '#/state/queries' import {getAgent} from '#/state/session' const RQKEY_ROOT = 'actor-search' -export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix] +export const RQKEY = (query: string) => [RQKEY_ROOT, query] -export function useActorSearch(prefix: string) { +export function useActorSearch({ + query, + enabled, +}: { + query: string + enabled?: boolean +}) { return useQuery<AppBskyActorDefs.ProfileView[]>({ staleTime: STALE.MINUTES.ONE, - queryKey: RQKEY(prefix || ''), + queryKey: RQKEY(query || ''), async queryFn() { const res = await getAgent().searchActors({ - q: prefix, + q: query, }) return res.data.actors }, - enabled: !!prefix, + enabled: enabled && !!query, }) } diff --git a/src/state/queries/search-posts.ts b/src/state/queries/search-posts.ts index ef8b08358..1822577c9 100644 --- a/src/state/queries/search-posts.ts +++ b/src/state/queries/search-posts.ts @@ -19,9 +19,11 @@ const searchPostsQueryKey = ({query, sort}: {query: string; sort?: string}) => [ export function useSearchPostsQuery({ query, sort, + enabled, }: { query: string sort?: 'top' | 'latest' + enabled?: boolean }) { return useInfiniteQuery< AppBskyFeedSearchPosts.OutputSchema, @@ -47,6 +49,7 @@ export function useSearchPostsQuery({ }, initialPageParam: undefined, getNextPageParam: lastPage => lastPage.cursor, + enabled, }) } |