about summary refs log tree commit diff
path: root/src/state/queries/post.ts
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-01-25 21:21:07 +0000
committerGitHub <noreply@github.com>2024-01-25 21:21:07 +0000
commit3b26b32f7f8b51b8349754df2b4d12717a9b932e (patch)
tree11eb04ce669e415e06e278601049fa70650245d6 /src/state/queries/post.ts
parenta588b0d5489143dfd6bf6675e76f7aa3f6ec0f4d (diff)
downloadvoidsky-3b26b32f7f8b51b8349754df2b4d12717a9b932e.tar.zst
Derive shadow like count (#2616)
Diffstat (limited to 'src/state/queries/post.ts')
-rw-r--r--src/state/queries/post.ts24
1 files changed, 4 insertions, 20 deletions
diff --git a/src/state/queries/post.ts b/src/state/queries/post.ts
index 5570f022b..449304ad0 100644
--- a/src/state/queries/post.ts
+++ b/src/state/queries/post.ts
@@ -59,13 +59,12 @@ export function usePostLikeMutation() {
   return useMutation<
     {uri: string}, // responds with the uri of the like
     Error,
-    {uri: string; cid: string; likeCount: number} // the post's uri, cid, and likes
+    {uri: string; cid: string} // the post's uri and cid
   >({
     mutationFn: post => getAgent().like(post.uri, post.cid),
     onMutate(variables) {
       // optimistically update the post-shadow
       updatePostShadow(variables.uri, {
-        likeCount: variables.likeCount + 1,
         likeUri: 'pending',
       })
     },
@@ -79,7 +78,6 @@ export function usePostLikeMutation() {
     onError(error, variables) {
       // revert the optimistic update
       updatePostShadow(variables.uri, {
-        likeCount: variables.likeCount,
         likeUri: undefined,
       })
     },
@@ -87,11 +85,7 @@ export function usePostLikeMutation() {
 }
 
 export function usePostUnlikeMutation() {
-  return useMutation<
-    void,
-    Error,
-    {postUri: string; likeUri: string; likeCount: number}
-  >({
+  return useMutation<void, Error, {postUri: string; likeUri: string}>({
     mutationFn: async ({likeUri}) => {
       await getAgent().deleteLike(likeUri)
       track('Post:Unlike')
@@ -99,14 +93,12 @@ export function usePostUnlikeMutation() {
     onMutate(variables) {
       // optimistically update the post-shadow
       updatePostShadow(variables.postUri, {
-        likeCount: variables.likeCount - 1,
         likeUri: undefined,
       })
     },
     onError(error, variables) {
       // revert the optimistic update
       updatePostShadow(variables.postUri, {
-        likeCount: variables.likeCount,
         likeUri: variables.likeUri,
       })
     },
@@ -117,13 +109,12 @@ export function usePostRepostMutation() {
   return useMutation<
     {uri: string}, // responds with the uri of the repost
     Error,
-    {uri: string; cid: string; repostCount: number} // the post's uri, cid, and reposts
+    {uri: string; cid: string} // the post's uri and cid
   >({
     mutationFn: post => getAgent().repost(post.uri, post.cid),
     onMutate(variables) {
       // optimistically update the post-shadow
       updatePostShadow(variables.uri, {
-        repostCount: variables.repostCount + 1,
         repostUri: 'pending',
       })
     },
@@ -137,7 +128,6 @@ export function usePostRepostMutation() {
     onError(error, variables) {
       // revert the optimistic update
       updatePostShadow(variables.uri, {
-        repostCount: variables.repostCount,
         repostUri: undefined,
       })
     },
@@ -145,11 +135,7 @@ export function usePostRepostMutation() {
 }
 
 export function usePostUnrepostMutation() {
-  return useMutation<
-    void,
-    Error,
-    {postUri: string; repostUri: string; repostCount: number}
-  >({
+  return useMutation<void, Error, {postUri: string; repostUri: string}>({
     mutationFn: async ({repostUri}) => {
       await getAgent().deleteRepost(repostUri)
       track('Post:Unrepost')
@@ -157,14 +143,12 @@ export function usePostUnrepostMutation() {
     onMutate(variables) {
       // optimistically update the post-shadow
       updatePostShadow(variables.postUri, {
-        repostCount: variables.repostCount - 1,
         repostUri: undefined,
       })
     },
     onError(error, variables) {
       // revert the optimistic update
       updatePostShadow(variables.postUri, {
-        repostCount: variables.repostCount,
         repostUri: variables.repostUri,
       })
     },