about summary refs log tree commit diff
path: root/src/state/queries/threadgate/index.ts
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2024-08-21 22:16:03 -0500
committerGitHub <noreply@github.com>2024-08-21 20:16:03 -0700
commitd5c78b9183ac78620f59538fed61c8130ae1c47a (patch)
tree53ad7c63b9263e508df587aa6d837c4036f394e9 /src/state/queries/threadgate/index.ts
parent61f0be705d614a31331945e1c4b9361d71b81403 (diff)
downloadvoidsky-d5c78b9183ac78620f59538fed61c8130ae1c47a.tar.zst
Prep threadgate shadow hack (#4970)
Co-authored-by: Hailey <me@haileyok.com>
Diffstat (limited to 'src/state/queries/threadgate/index.ts')
-rw-r--r--src/state/queries/threadgate/index.ts15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/state/queries/threadgate/index.ts b/src/state/queries/threadgate/index.ts
index a88197cd5..faa166e2c 100644
--- a/src/state/queries/threadgate/index.ts
+++ b/src/state/queries/threadgate/index.ts
@@ -9,10 +9,12 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
 
 import {networkRetry, retry} from '#/lib/async/retry'
 import {until} from '#/lib/async/until'
+import {updatePostShadow} from '#/state/cache/post-shadow'
 import {STALE} from '#/state/queries'
 import {RQKEY_ROOT as postThreadQueryKeyRoot} from '#/state/queries/post-thread'
 import {ThreadgateAllowUISetting} from '#/state/queries/threadgate/types'
 import {
+  createTempThreadgateView,
   createThreadgateRecord,
   mergeThreadgateRecords,
   threadgateAllowUISettingToAllowRecordValue,
@@ -342,17 +344,26 @@ export function useToggleReplyVisibilityMutation() {
         }
       })
     },
-    onSuccess() {
+    onSuccess(_, {postUri, replyUri}) {
+      updatePostShadow(queryClient, postUri, {
+        threadgateView: createTempThreadgateView({
+          postUri,
+          hiddenReplies: [replyUri],
+        }),
+      })
       queryClient.invalidateQueries({
         queryKey: [threadgateRecordQueryKeyRoot],
       })
     },
-    onError(_, {replyUri, action}) {
+    onError(_, {postUri, replyUri, action}) {
       if (action === 'hide') {
         hiddenReplies.removeHiddenReplyUri(replyUri)
       } else if (action === 'show') {
         hiddenReplies.addHiddenReplyUri(replyUri)
       }
+      updatePostShadow(queryClient, postUri, {
+        threadgateView: undefined,
+      })
     },
   })
 }