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>
This commit is contained in:
parent
143fc80951
commit
46b63accb8
14 changed files with 462 additions and 172 deletions
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue