diff options
Diffstat (limited to 'src/state/queries/profile-follows.ts')
-rw-r--r-- | src/state/queries/profile-follows.ts | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/src/state/queries/profile-follows.ts b/src/state/queries/profile-follows.ts index 8af1fba07..428c8aebd 100644 --- a/src/state/queries/profile-follows.ts +++ b/src/state/queries/profile-follows.ts @@ -1,5 +1,10 @@ -import {AppBskyGraphGetFollows} from '@atproto/api' -import {useInfiniteQuery, InfiniteData, QueryKey} from '@tanstack/react-query' +import {AppBskyActorDefs, AppBskyGraphGetFollows} from '@atproto/api' +import { + useInfiniteQuery, + InfiniteData, + QueryClient, + QueryKey, +} from '@tanstack/react-query' import {getAgent} from '#/state/session' import {STALE} from '#/state/queries' @@ -33,3 +38,26 @@ export function useProfileFollowsQuery(did: string | undefined) { enabled: !!did, }) } + +export function* findAllProfilesInQueryData( + queryClient: QueryClient, + did: string, +): Generator<AppBskyActorDefs.ProfileView, void> { + const queryDatas = queryClient.getQueriesData< + InfiniteData<AppBskyGraphGetFollows.OutputSchema> + >({ + queryKey: ['profile-follows'], + }) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData?.pages) { + continue + } + for (const page of queryData?.pages) { + for (const follow of page.follows) { + if (follow.did === did) { + yield follow + } + } + } + } +} |