diff options
author | Dessalines <tyhou13@gmx.com> | 2020-02-05 14:24:35 -0500 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2020-02-05 14:24:35 -0500 |
commit | 716ce0f77934f71c2104cf24d3cd5c17d6298cac (patch) | |
tree | 056dfd956ee07530adc6e0b973ad55f59986682f /ui/src/components/post.tsx | |
parent | 8405f0ee5366ff2b1b80e5387169f59d3adbde26 (diff) |
Adding if found to catch errors.
Diffstat (limited to 'ui/src/components/post.tsx')
-rw-r--r-- | ui/src/components/post.tsx | 42 |
1 files changed, 24 insertions, 18 deletions
diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index b399d3b2..922fc01e 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -409,33 +409,39 @@ export class Post extends Component<any, PostState> { } else if (res.op == UserOperation.EditComment) { let data = res.data as CommentResponse; let found = this.state.comments.find(c => c.id == data.comment.id); - found.content = data.comment.content; - found.updated = data.comment.updated; - found.removed = data.comment.removed; - found.deleted = data.comment.deleted; - found.upvotes = data.comment.upvotes; - found.downvotes = data.comment.downvotes; - found.score = data.comment.score; - found.read = data.comment.read; + if (found) { + found.content = data.comment.content; + found.updated = data.comment.updated; + found.removed = data.comment.removed; + found.deleted = data.comment.deleted; + found.upvotes = data.comment.upvotes; + found.downvotes = data.comment.downvotes; + found.score = data.comment.score; + found.read = data.comment.read; - this.setState(this.state); + this.setState(this.state); + } } else if (res.op == UserOperation.SaveComment) { let data = res.data as CommentResponse; let found = this.state.comments.find(c => c.id == data.comment.id); - found.saved = data.comment.saved; - this.setState(this.state); + if (found) { + found.saved = data.comment.saved; + this.setState(this.state); + } } else if (res.op == UserOperation.CreateCommentLike) { let data = res.data as CommentResponse; let found: Comment = this.state.comments.find( c => c.id === data.comment.id ); - found.score = data.comment.score; - found.upvotes = data.comment.upvotes; - found.downvotes = data.comment.downvotes; - if (data.comment.my_vote !== null) { - found.my_vote = data.comment.my_vote; - found.upvoteLoading = false; - found.downvoteLoading = false; + if (found) { + found.score = data.comment.score; + found.upvotes = data.comment.upvotes; + found.downvotes = data.comment.downvotes; + if (data.comment.my_vote !== null) { + found.my_vote = data.comment.my_vote; + found.upvoteLoading = false; + found.downvoteLoading = false; + } } this.setState(this.state); } else if (res.op == UserOperation.CreatePostLike) { |