From ecd10482a6815fc3b51b2da7cd5f494c01c385e6 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 7 Feb 2020 23:05:15 -0500 Subject: Add new comments views to main and community pages. Fixes #480 --- ui/src/components/user.tsx | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'ui/src/components/user.tsx') diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index da6aa8ce..effc9e1d 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -1034,20 +1034,24 @@ export class User extends Component { 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; - - this.setState(this.state); + 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; + this.setState(this.state); + } } else if (res.op == UserOperation.CreateComment) { - // let res: CommentResponse = msg; - toast(i18n.t('reply_sent')); - // this.state.comments.unshift(res.comment); // TODO do this right - // this.setState(this.state); + let data = res.data as CommentResponse; + if ( + UserService.Instance.user && + data.comment.creator_id == UserService.Instance.user.id + ) { + toast(i18n.t('reply_sent')); + } } else if (res.op == UserOperation.SaveComment) { let data = res.data as CommentResponse; let found = this.state.comments.find(c => c.id == data.comment.id); -- cgit v1.2.3