about summary refs log tree commit diff
path: root/src/state/queries/list.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-04-25 15:39:28 -0500
committerGitHub <noreply@github.com>2024-04-25 21:39:28 +0100
commita69e56799193ef9b1e5ea9c96bbf0bcc28158d3f (patch)
tree525825a1efc3db5c9d697fdcfb8f11ffd2aba878 /src/state/queries/list.ts
parentec376960347a6255f1ec12c1758797ac30c073ff (diff)
downloadvoidsky-a69e56799193ef9b1e5ea9c96bbf0bcc28158d3f.tar.zst
[Session] Drill into `getAgent` into `whenAppViewReady` (#3702)
* Drill into whenAppViewReady

(cherry picked from commit e290e5be3df509bdd9d0e626a164996c9dee3636)

* Drill getAgent instead

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/state/queries/list.ts')
-rw-r--r--src/state/queries/list.ts62
1 files changed, 42 insertions, 20 deletions
diff --git a/src/state/queries/list.ts b/src/state/queries/list.ts
index c653d5376..1edf2606c 100644
--- a/src/state/queries/list.ts
+++ b/src/state/queries/list.ts
@@ -4,6 +4,7 @@ import {
   AppBskyGraphGetList,
   AppBskyGraphList,
   AtUri,
+  BskyAgent,
   Facet,
 } from '@atproto/api'
 import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
@@ -85,9 +86,13 @@ export function useListCreateMutation() {
         )
 
         // wait for the appview to update
-        await whenAppViewReady(res.uri, (v: AppBskyGraphGetList.Response) => {
-          return typeof v?.data?.list.uri === 'string'
-        })
+        await whenAppViewReady(
+          getAgent,
+          res.uri,
+          (v: AppBskyGraphGetList.Response) => {
+            return typeof v?.data?.list.uri === 'string'
+          },
+        )
         return res
       },
       onSuccess() {
@@ -150,12 +155,16 @@ export function useListMetadataMutation() {
       ).data
 
       // wait for the appview to update
-      await whenAppViewReady(res.uri, (v: AppBskyGraphGetList.Response) => {
-        const list = v.data.list
-        return (
-          list.name === record.name && list.description === record.description
-        )
-      })
+      await whenAppViewReady(
+        getAgent,
+        res.uri,
+        (v: AppBskyGraphGetList.Response) => {
+          const list = v.data.list
+          return (
+            list.name === record.name && list.description === record.description
+          )
+        },
+      )
       return res
     },
     onSuccess(data, variables) {
@@ -220,9 +229,13 @@ export function useListDeleteMutation() {
       }
 
       // wait for the appview to update
-      await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
-        return !v?.success
-      })
+      await whenAppViewReady(
+        getAgent,
+        uri,
+        (v: AppBskyGraphGetList.Response) => {
+          return !v?.success
+        },
+      )
     },
     onSuccess() {
       invalidateMyLists(queryClient)
@@ -244,9 +257,13 @@ export function useListMuteMutation() {
         await getAgent().unmuteModList(uri)
       }
 
-      await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
-        return Boolean(v?.data.list.viewer?.muted) === mute
-      })
+      await whenAppViewReady(
+        getAgent,
+        uri,
+        (v: AppBskyGraphGetList.Response) => {
+          return Boolean(v?.data.list.viewer?.muted) === mute
+        },
+      )
     },
     onSuccess(data, variables) {
       queryClient.invalidateQueries({
@@ -266,11 +283,15 @@ export function useListBlockMutation() {
         await getAgent().unblockModList(uri)
       }
 
-      await whenAppViewReady(uri, (v: AppBskyGraphGetList.Response) => {
-        return block
-          ? typeof v?.data.list.viewer?.blocked === 'string'
-          : !v?.data.list.viewer?.blocked
-      })
+      await whenAppViewReady(
+        getAgent,
+        uri,
+        (v: AppBskyGraphGetList.Response) => {
+          return block
+            ? typeof v?.data.list.viewer?.blocked === 'string'
+            : !v?.data.list.viewer?.blocked
+        },
+      )
     },
     onSuccess(data, variables) {
       queryClient.invalidateQueries({
@@ -281,6 +302,7 @@ export function useListBlockMutation() {
 }
 
 async function whenAppViewReady(
+  getAgent: () => BskyAgent,
   uri: string,
   fn: (res: AppBskyGraphGetList.Response) => boolean,
 ) {