From f020e89a8c8b5a8dafc41cf40dc9fb6f881778fb Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 19 Jan 2020 19:48:34 -0500 Subject: [PATCH] Fixing new comments and posts voting issue. Fixes #422 --- ui/src/components/comment-node.tsx | 12 ++++++++++++ ui/src/components/community.tsx | 7 +------ ui/src/components/main.tsx | 9 +-------- ui/src/components/post-listing.tsx | 9 +++++++++ 4 files changed, 23 insertions(+), 14 deletions(-) diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 21a82954b..e6efcf9f1 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -91,6 +91,18 @@ export class CommentNode extends Component { 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 ( diff --git a/ui/src/components/community.tsx b/ui/src/components/community.tsx index 03766bdcd..873b5a8a8 100644 --- a/ui/src/components/community.tsx +++ b/ui/src/components/community.tsx @@ -147,7 +147,7 @@ export class Community extends Component { )} {this.selects()} - {this.state.posts && } + {this.paginator()}
@@ -280,11 +280,6 @@ export class Community extends Component { 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); diff --git a/ui/src/components/main.tsx b/ui/src/components/main.tsx index 95eeb1df5..5fdf23bbf 100644 --- a/ui/src/components/main.tsx +++ b/ui/src/components/main.tsx @@ -422,9 +422,7 @@ export class Main extends Component { ) : (
{this.selects()} - {this.state.posts && ( - - )} + {this.paginator()}
)} @@ -598,11 +596,6 @@ export class Main extends Component { 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); diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index c945806bd..0c6d44b49 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -84,6 +84,15 @@ export class PostListing extends Component { 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 (