about summary refs log tree commit diff
path: root/src/state/queries/profile-follows.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2023-11-30 21:35:58 +0000
committerGitHub <noreply@github.com>2023-11-30 13:35:58 -0800
commit46b63accb8e73997f2a1bee24cfda220d29e048b (patch)
tree748de65b464e98d8241cc6fd8d11a9c17d9ec05c /src/state/queries/profile-follows.ts
parent143fc80951d3a0620c0a5e55f46229f2fc743758 (diff)
downloadvoidsky-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/profile-follows.ts')
-rw-r--r--src/state/queries/profile-follows.ts32
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
+        }
+      }
+    }
+  }
+}