diff options
author | dan <dan.abramov@gmail.com> | 2023-11-30 21:35:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 13:35:58 -0800 |
commit | 46b63accb8e73997f2a1bee24cfda220d29e048b (patch) | |
tree | 748de65b464e98d8241cc6fd8d11a9c17d9ec05c /src/state/queries/suggested-follows.ts | |
parent | 143fc80951d3a0620c0a5e55f46229f2fc743758 (diff) | |
download | voidsky-46b63accb8e73997f2a1bee24cfda220d29e048b.tar.zst |
Rewrite the shadow logic to look inside the cache (#2045)
* Reset * Associate shadows with the cache * Use colocated helpers * Fix types * Reorder for clarity * More types * Copy paste logic for profile * Hook up profile query * Hook up suggested follows * Hook up other profile things * Fix shape * Pass setShadow into the effect deps * Include reply posts in the shadow cache search --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
Diffstat (limited to 'src/state/queries/suggested-follows.ts')
-rw-r--r-- | src/state/queries/suggested-follows.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/state/queries/suggested-follows.ts b/src/state/queries/suggested-follows.ts index eadcb590a..932226b75 100644 --- a/src/state/queries/suggested-follows.ts +++ b/src/state/queries/suggested-follows.ts @@ -1,5 +1,6 @@ import React from 'react' import { + AppBskyActorDefs, AppBskyActorGetSuggestions, AppBskyGraphGetSuggestedFollowsByActor, moderateProfile, @@ -9,6 +10,7 @@ import { useQueryClient, useQuery, InfiniteData, + QueryClient, QueryKey, } from '@tanstack/react-query' @@ -106,3 +108,56 @@ export function useGetSuggestedFollowersByActor() { [queryClient], ) } + +export function* findAllProfilesInQueryData( + queryClient: QueryClient, + did: string, +): Generator<AppBskyActorDefs.ProfileView, void> { + yield* findAllProfilesInSuggestedFollowsQueryData(queryClient, did) + yield* findAllProfilesInSuggestedFollowsByActorQueryData(queryClient, did) +} + +function* findAllProfilesInSuggestedFollowsQueryData( + queryClient: QueryClient, + did: string, +) { + const queryDatas = queryClient.getQueriesData< + InfiniteData<AppBskyActorGetSuggestions.OutputSchema> + >({ + queryKey: ['suggested-follows'], + }) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData?.pages) { + continue + } + for (const page of queryData?.pages) { + for (const actor of page.actors) { + if (actor.did === did) { + yield actor + } + } + } + } +} + +function* findAllProfilesInSuggestedFollowsByActorQueryData( + queryClient: QueryClient, + did: string, +) { + const queryDatas = + queryClient.getQueriesData<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema>( + { + queryKey: ['suggested-follows-by-actor'], + }, + ) + for (const [_queryKey, queryData] of queryDatas) { + if (!queryData) { + continue + } + for (const suggestion of queryData.suggestions) { + if (suggestion.did === did) { + yield suggestion + } + } + } +} |