From 9afadfb9c4c5db1796848ec4af9756fe03d51ee3 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 19 Apr 2019 21:06:25 -0700 Subject: Saving replies, the actual fixes will be in the merge to dev. --- ui/src/components/post.tsx | 50 +++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'ui/src/components/post.tsx') diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index d79a6c97..64f56d88 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -1,7 +1,7 @@ import { Component, linkEvent } from 'inferno'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, AddModToCommunityResponse } from '../interfaces'; +import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView } from '../interfaces'; import { WebSocketService } from '../services'; import { msgOp, hotRank } from '../utils'; import { PostListing } from './post-listing'; @@ -17,6 +17,7 @@ interface PostState { commentSort: CommentSortType; community: Community; moderators: Array; + admins: Array; scrolled?: boolean; scrolled_comment_id?: number; loading: boolean; @@ -31,6 +32,7 @@ export class Post extends Component { commentSort: CommentSortType.Hot, community: null, moderators: [], + admins: [], scrolled: false, loading: true } @@ -77,7 +79,7 @@ export class Post extends Component { return (
{this.state.loading ? -

: +
:
@@ -123,9 +125,15 @@ export class Post extends Component { newComments() { return (
-

New Comments

+
New Comments
{this.state.comments.map(comment => - + )}
) @@ -187,8 +195,13 @@ export class Post extends Component { commentsTree() { let nodes = this.buildCommentsTree(); return ( -
- +
+
); } @@ -202,9 +215,11 @@ export class Post extends Component { } else if (op == UserOperation.GetPost) { let res: GetPostResponse = msg; this.state.post = res.post; + this.state.post = res.post; this.state.comments = res.comments; this.state.community = res.community; this.state.moderators = res.moderators; + this.state.admins = res.admins; this.state.loading = false; this.setState(this.state); } else if (op == UserOperation.CreateComment) { @@ -222,8 +237,12 @@ export class Post extends Component { found.score = res.comment.score; this.setState(this.state); - } - else if (op == UserOperation.CreateCommentLike) { + } else if (op == UserOperation.SaveComment) { + let res: CommentResponse = msg; + let found = this.state.comments.find(c => c.id == res.comment.id); + found.saved = res.comment.saved; + this.setState(this.state); + } else if (op == UserOperation.CreateCommentLike) { let res: CommentResponse = msg; let found: Comment = this.state.comments.find(c => c.id === res.comment.id); found.score = res.comment.score; @@ -243,6 +262,10 @@ export class Post extends Component { let res: PostResponse = msg; this.state.post = res.post; this.setState(this.state); + } else if (op == UserOperation.SavePost) { + let res: PostResponse = msg; + this.state.post = res.post; + this.setState(this.state); } else if (op == UserOperation.EditCommunity) { let res: CommunityResponse = msg; this.state.community = res.community; @@ -257,12 +280,21 @@ export class Post extends Component { } else if (op == UserOperation.BanFromCommunity) { let res: BanFromCommunityResponse = msg; this.state.comments.filter(c => c.creator_id == res.user.id) - .forEach(c => c.banned = res.banned); + .forEach(c => c.banned_from_community = res.banned); this.setState(this.state); } else if (op == UserOperation.AddModToCommunity) { let res: AddModToCommunityResponse = msg; this.state.moderators = res.moderators; this.setState(this.state); + } else if (op == UserOperation.BanUser) { + let res: BanUserResponse = msg; + this.state.comments.filter(c => c.creator_id == res.user.id) + .forEach(c => c.banned = res.banned); + this.setState(this.state); + } else if (op == UserOperation.AddAdmin) { + let res: AddAdminResponse = msg; + this.state.admins = res.admins; + this.setState(this.state); } } -- cgit v1.2.3