diff options
author | Dessalines <tyhou13@gmx.com> | 2019-04-19 21:06:25 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-04-19 21:06:25 -0700 |
commit | 9afadfb9c4c5db1796848ec4af9756fe03d51ee3 (patch) | |
tree | 22a2ea818d6bfcdb390e398c4c9bd5e05595587c /ui/src/components/post.tsx | |
parent | 6f801bb819169060abcf1d8e901759f133dc6987 (diff) |
Saving replies, the actual fixes will be in the merge to dev.
Diffstat (limited to 'ui/src/components/post.tsx')
-rw-r--r-- | ui/src/components/post.tsx | 50 |
1 files changed, 41 insertions, 9 deletions
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<CommunityUser>; + admins: Array<UserView>; scrolled?: boolean; scrolled_comment_id?: number; loading: boolean; @@ -31,6 +32,7 @@ export class Post extends Component<any, PostState> { commentSort: CommentSortType.Hot, community: null, moderators: [], + admins: [], scrolled: false, loading: true } @@ -77,7 +79,7 @@ export class Post extends Component<any, PostState> { return ( <div class="container"> {this.state.loading ? - <h4><svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg></h4> : + <h5><svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg></h5> : <div class="row"> <div class="col-12 col-md-8 col-lg-7 mb-3"> <PostListing post={this.state.post} showBody showCommunity editable /> @@ -123,9 +125,15 @@ export class Post extends Component<any, PostState> { newComments() { return ( <div class="sticky-top"> - <h4>New Comments</h4> + <h5>New Comments</h5> {this.state.comments.map(comment => - <CommentNodes nodes={[{comment: comment}]} noIndent locked={this.state.post.locked} moderators={this.state.moderators} /> + <CommentNodes + nodes={[{comment: comment}]} + noIndent + locked={this.state.post.locked} + moderators={this.state.moderators} + admins={this.state.admins} + /> )} </div> ) @@ -187,8 +195,13 @@ export class Post extends Component<any, PostState> { commentsTree() { let nodes = this.buildCommentsTree(); return ( - <div className=""> - <CommentNodes nodes={nodes} locked={this.state.post.locked} moderators={this.state.moderators} /> + <div> + <CommentNodes + nodes={nodes} + locked={this.state.post.locked} + moderators={this.state.moderators} + admins={this.state.admins} + /> </div> ); } @@ -202,9 +215,11 @@ export class Post extends Component<any, PostState> { } 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<any, PostState> { 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<any, PostState> { 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<any, PostState> { } 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); } } |