about summary refs log tree commit diff
path: root/src/state/queries/my-follows.ts
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-11-12 12:45:25 -0800
committerGitHub <noreply@github.com>2023-11-12 12:45:25 -0800
commitd9e0a927c1c98ebd6aa3885ab517af27e7de2522 (patch)
treecee196297391e497f1aa3b650d66633f3a86ca34 /src/state/queries/my-follows.ts
parent05b728fffcdb17708fdb52685725faf7fdc545bc (diff)
downloadvoidsky-d9e0a927c1c98ebd6aa3885ab517af27e7de2522.tar.zst
Refactor lists to use new queries (#1875)
* Refactor lists queries to react-query

* Delete old lists-list model

* Implement list, list-members, and list-memberships react-queries

* Update CreateOrEditList modal

* First pass at my-follows and actor-autocomplete queries

* Update ListAddUserModal to use new queries, change to ListAddRemoveUsersModal

* Update UserAddRemoveLists modal

* Remove old TODO

* Fix indent, autocomplete query

* Add a todo

---------

Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/state/queries/my-follows.ts')
-rw-r--r--src/state/queries/my-follows.ts43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/state/queries/my-follows.ts b/src/state/queries/my-follows.ts
new file mode 100644
index 000000000..ad6cf837d
--- /dev/null
+++ b/src/state/queries/my-follows.ts
@@ -0,0 +1,43 @@
+import {AppBskyActorDefs} from '@atproto/api'
+import {useQuery} from '@tanstack/react-query'
+import {useSession} from '../session'
+
+// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
+const SANITY_PAGE_LIMIT = 1000
+const PAGE_SIZE = 100
+// ...which comes 10,000k follows
+
+export const RQKEY = () => ['my-follows']
+
+export function useMyFollowsQuery() {
+  const {agent, currentAccount} = useSession()
+  return useQuery<AppBskyActorDefs.ProfileViewBasic[]>({
+    queryKey: RQKEY(),
+    async queryFn() {
+      if (!currentAccount) {
+        return []
+      }
+      let cursor
+      let arr: AppBskyActorDefs.ProfileViewBasic[] = []
+      for (let i = 0; i < SANITY_PAGE_LIMIT; i++) {
+        const res = await agent.getFollows({
+          actor: currentAccount.did,
+          cursor,
+          limit: PAGE_SIZE,
+        })
+        // TODO
+        // res.data.follows = res.data.follows.filter(
+        //   profile =>
+        //     !moderateProfile(profile, this.rootStore.preferences.moderationOpts)
+        //       .account.filter,
+        // )
+        arr = arr.concat(res.data.follows)
+        if (!res.data.cursor) {
+          break
+        }
+        cursor = res.data.cursor
+      }
+      return arr
+    },
+  })
+}