]> Untitled Git - lemmy-ui.git/commitdiff
fix: Fix vote buttons not showing spinners while registering vote #1761
authorJay Sitter <jay@jaysitter.com>
Sun, 2 Jul 2023 19:07:24 +0000 (15:07 -0400)
committerJay Sitter <jay@jaysitter.com>
Sun, 2 Jul 2023 19:07:37 +0000 (15:07 -0400)
src/shared/components/common/vote-buttons.tsx

index 69df94bfb395d06e12d8b689691c346aca89014a..2595bb620b0fd6bf8da38816c3c8f4abf90d7f6e 100644 (file)
@@ -64,8 +64,6 @@ const handleUpvote = (i: VoteButtons) => {
         auth: myAuthRequired(),
       });
   }
-
-  i.setState({ upvoteLoading: false });
 };
 
 const handleDownvote = (i: VoteButtons) => {
@@ -86,7 +84,6 @@ const handleDownvote = (i: VoteButtons) => {
         auth: myAuthRequired(),
       });
   }
-  i.setState({ downvoteLoading: false });
 };
 
 export class VoteButtonsCompact extends Component<
@@ -102,6 +99,15 @@ export class VoteButtonsCompact extends Component<
     super(props, context);
   }
 
+  componentWillReceiveProps(nextProps: VoteButtonsProps) {
+    if (this.props !== nextProps) {
+      this.setState({
+        upvoteLoading: false,
+        downvoteLoading: false,
+      });
+    }
+  }
+
   render() {
     return (
       <>
@@ -172,6 +178,15 @@ export class VoteButtons extends Component<VoteButtonsProps, VoteButtonsState> {
     super(props, context);
   }
 
+  componentWillReceiveProps(nextProps: VoteButtonsProps) {
+    if (this.props !== nextProps) {
+      this.setState({
+        upvoteLoading: false,
+        downvoteLoading: false,
+      });
+    }
+  }
+
   render() {
     return (
       <div className="vote-bar small text-center">