diff options
author | Dessalines <tyhou13@gmx.com> | 2019-04-22 11:32:50 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-04-22 11:32:50 -0700 |
commit | bd3302317e222b4961dd0ccf8cd26ed858787929 (patch) | |
tree | 0e8f7230f69bcfbd5ef5d6a3faa1574c845539b2 /ui/src | |
parent | 2e361aa7364b81a245115a298301a753a808b3fd (diff) |
Comment actions from inbox and user pages working.
- Fixes #93
Diffstat (limited to 'ui/src')
-rw-r--r-- | ui/src/components/comment-node.tsx | 11 | ||||
-rw-r--r-- | ui/src/components/inbox.tsx | 31 | ||||
-rw-r--r-- | ui/src/components/user.tsx | 37 |
3 files changed, 71 insertions, 8 deletions
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index badbcd12..af44e41e 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -220,10 +220,15 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { } get canMod(): boolean { - let adminsThenMods = this.props.admins.map(a => a.id) - .concat(this.props.moderators.map(m => m.user_id)); - return canMod(UserService.Instance.user, adminsThenMods, this.props.node.comment.creator_id); + if (this.props.admins && this.props.moderators) { + let adminsThenMods = this.props.admins.map(a => a.id) + .concat(this.props.moderators.map(m => m.user_id)); + + return canMod(UserService.Instance.user, adminsThenMods, this.props.node.comment.creator_id); + } else { + return false; + } } get canAdmin(): boolean { diff --git a/ui/src/components/inbox.tsx b/ui/src/components/inbox.tsx index e386aa1a..50fd47c2 100644 --- a/ui/src/components/inbox.tsx +++ b/ui/src/components/inbox.tsx @@ -94,7 +94,7 @@ export class Inbox extends Component<any, InboxState> { return ( <div> {this.state.replies.map(reply => - <CommentNodes nodes={[{comment: reply}]} noIndent viewOnly markable /> + <CommentNodes nodes={[{comment: reply}]} noIndent markable /> )} </div> ); @@ -161,6 +161,14 @@ export class Inbox extends Component<any, InboxState> { } else if (op == UserOperation.EditComment) { let res: CommentResponse = msg; + let found = this.state.replies.find(c => c.id == res.comment.id); + found.content = res.comment.content; + found.updated = res.comment.updated; + found.removed = res.comment.removed; + found.upvotes = res.comment.upvotes; + found.downvotes = res.comment.downvotes; + found.score = res.comment.score; + // If youre in the unread view, just remove it from the list if (this.state.unreadType == UnreadType.Unread && res.comment.read) { this.state.replies = this.state.replies.filter(r => r.id !== res.comment.id); @@ -168,8 +176,27 @@ export class Inbox extends Component<any, InboxState> { let found = this.state.replies.find(c => c.id == res.comment.id); found.read = res.comment.read; } - this.sendRepliesCount(); + + this.setState(this.state); + } else if (op == UserOperation.CreateComment) { + // let res: CommentResponse = msg; + alert('Reply sent'); + // this.state.replies.unshift(res.comment); // TODO do this right + // this.setState(this.state); + } else if (op == UserOperation.SaveComment) { + let res: CommentResponse = msg; + let found = this.state.replies.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.replies.find(c => c.id === res.comment.id); + found.score = res.comment.score; + found.upvotes = res.comment.upvotes; + found.downvotes = res.comment.downvotes; + if (res.comment.my_vote !== null) + found.my_vote = res.comment.my_vote; this.setState(this.state); } } diff --git a/ui/src/components/user.tsx b/ui/src/components/user.tsx index b530e41e..1131428b 100644 --- a/ui/src/components/user.tsx +++ b/ui/src/components/user.tsx @@ -2,7 +2,7 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { Subscription } from "rxjs"; import { retryWhen, delay, take } from 'rxjs/operators'; -import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView } from '../interfaces'; +import { UserOperation, Post, Comment, CommunityUser, GetUserDetailsForm, SortType, UserDetailsResponse, UserView, CommentResponse } from '../interfaces'; import { WebSocketService } from '../services'; import { msgOp, fetchLimit } from '../utils'; import { PostListing } from './post-listing'; @@ -148,7 +148,7 @@ export class User extends Component<any, UserState> { <div> {i.type_ == "posts" ? <PostListing post={i.data as Post} showCommunity viewOnly /> - : <CommentNodes nodes={[{comment: i.data as Comment}]} noIndent viewOnly /> + : <CommentNodes nodes={[{comment: i.data as Comment}]} noIndent /> } </div> ) @@ -296,7 +296,38 @@ export class User extends Component<any, UserState> { this.state.posts = res.posts; document.title = `/u/${this.state.user.name} - Lemmy`; this.setState(this.state); - } + } else if (op == UserOperation.EditComment) { + let res: CommentResponse = msg; + + let found = this.state.comments.find(c => c.id == res.comment.id); + found.content = res.comment.content; + found.updated = res.comment.updated; + found.removed = res.comment.removed; + found.upvotes = res.comment.upvotes; + found.downvotes = res.comment.downvotes; + found.score = res.comment.score; + + this.setState(this.state); + } else if (op == UserOperation.CreateComment) { + // let res: CommentResponse = msg; + alert('Reply sent'); + // this.state.comments.unshift(res.comment); // TODO do this right + // this.setState(this.state); + } 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; + found.upvotes = res.comment.upvotes; + found.downvotes = res.comment.downvotes; + if (res.comment.my_vote !== null) + found.my_vote = res.comment.my_vote; + this.setState(this.state); + } } } |