Move the current agent to a global and reset RQ queries on agent change (#1946)

This commit is contained in:
Paul Frazee 2023-11-16 18:26:22 -08:00 committed by GitHub
parent 3043b32468
commit 357c752a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
40 changed files with 218 additions and 260 deletions

View file

@ -1,7 +1,7 @@
import {AppBskyGraphGetLists} from '@atproto/api'
import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query'
import {useSession} from '#/state/session'
import {getAgent} from '#/state/session'
import {STALE} from '#/state/queries'
const PAGE_SIZE = 30
@ -10,7 +10,6 @@ type RQPageParam = string | undefined
export const RQKEY = (did: string) => ['profile-lists', did]
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
const {agent} = useSession()
const enabled = opts?.enabled !== false
return useInfiniteQuery<
AppBskyGraphGetLists.OutputSchema,
@ -22,7 +21,7 @@ export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
staleTime: STALE.MINUTES.ONE,
queryKey: RQKEY(did),
async queryFn({pageParam}: {pageParam: RQPageParam}) {
const res = await agent.app.bsky.graph.getLists({
const res = await getAgent().app.bsky.graph.getLists({
actor: did,
limit: PAGE_SIZE,
cursor: pageParam,