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