]> Untitled Git - lemmy.git/commitdiff
Fixing new comments and posts voting issue. Fixes #422
authorDessalines <tyhou13@gmx.com>
Mon, 20 Jan 2020 00:48:34 +0000 (19:48 -0500)
committerDessalines <tyhou13@gmx.com>
Mon, 20 Jan 2020 00:48:34 +0000 (19:48 -0500)
ui/src/components/comment-node.tsx
ui/src/components/community.tsx
ui/src/components/main.tsx
ui/src/components/post-listing.tsx

index 21a82954b297a7a728db107abc33a36959772058..e6efcf9f1f406ab5e52010f43e739b348091315a 100644 (file)
@@ -91,6 +91,18 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
     this.handleCommentDisLike = this.handleCommentDisLike.bind(this);
   }
 
+  componentDidUpdate(prevProps: CommentNodeProps) {
+    if (
+      prevProps.node.comment.my_vote !== this.props.node.comment.my_vote ||
+      this.state.score !== this.props.node.comment.score
+    ) {
+      this.setState({
+        my_vote: this.props.node.comment.my_vote,
+        score: this.props.node.comment.score,
+      });
+    }
+  }
+
   render() {
     let node = this.props.node;
     return (
index 03766bdcd4c22c56b5122e13a451de1bc6c953c6..873b5a8a82b757dad333ffd18288e54a94fec520 100644 (file)
@@ -147,7 +147,7 @@ export class Community extends Component<any, State> {
                 )}
               </h5>
               {this.selects()}
-              {this.state.posts && <PostListings posts={this.state.posts} />}
+              <PostListings posts={this.state.posts} />
               {this.paginator()}
             </div>
             <div class="col-12 col-md-4">
@@ -280,11 +280,6 @@ export class Community extends Component<any, State> {
       this.setState(this.state);
     } else if (op == UserOperation.GetPosts) {
       let res: GetPostsResponse = msg;
-
-      // This is needed to refresh the view
-      this.state.posts = undefined;
-      this.setState(this.state);
-
       this.state.posts = res.posts;
       this.state.loading = false;
       this.setState(this.state);
index 95eeb1df54f101f7d71bcb9aa71c6dc0279c3f6e..5fdf23bbf3fee6c0dfdd494f602a56d09df5c416 100644 (file)
@@ -422,9 +422,7 @@ export class Main extends Component<any, MainState> {
         ) : (
           <div>
             {this.selects()}
-            {this.state.posts && (
-              <PostListings posts={this.state.posts} showCommunity />
-            )}
+            <PostListings posts={this.state.posts} showCommunity />
             {this.paginator()}
           </div>
         )}
@@ -598,11 +596,6 @@ export class Main extends Component<any, MainState> {
       this.setState(this.state);
     } else if (op == UserOperation.GetPosts) {
       let res: GetPostsResponse = msg;
-
-      // This is needed to refresh the view
-      this.state.posts = undefined;
-      this.setState(this.state);
-
       this.state.posts = res.posts;
       this.state.loading = false;
       this.setState(this.state);
index c945806bdfa305ed5a89fd92ffcf07af2cd16dc7..0c6d44b491f5adb0fc3cda258ff8cf7143814e2b 100644 (file)
@@ -84,6 +84,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     this.handleEditCancel = this.handleEditCancel.bind(this);
   }
 
+  componentDidUpdate(prevProps: PostListingProps) {
+    if (prevProps.post.my_vote !== this.props.post.my_vote) {
+      this.setState({
+        my_vote: this.props.post.my_vote,
+        score: this.props.post.score,
+      });
+    }
+  }
+
   render() {
     return (
       <div class="row">