diff options
author | Dessalines <tyhou13@gmx.com> | 2019-04-20 00:24:59 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-04-20 00:24:59 -0700 |
commit | e14e6e53cd969039087df17bc4407d1b7444e05d (patch) | |
tree | 117ee3fad0961ebf7459c780ad361ff315c36c63 /ui | |
parent | 9afadfb9c4c5db1796848ec4af9756fe03d51ee3 (diff) |
More moderation fixed
Diffstat (limited to 'ui')
-rw-r--r-- | ui/src/components/comment-node.tsx | 7 | ||||
-rw-r--r-- | ui/src/components/post-listing.tsx | 41 | ||||
-rw-r--r-- | ui/src/components/post.tsx | 9 | ||||
-rw-r--r-- | ui/src/interfaces.ts | 6 |
4 files changed, 48 insertions, 15 deletions
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index c1fc059b..90cf5a54 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -212,15 +212,15 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { } get isMod(): boolean { - return isMod(this.props.moderators.map(m => m.user_id), this.props.node.comment.creator_id); + return this.props.moderators && isMod(this.props.moderators.map(m => m.user_id), this.props.node.comment.creator_id); } get isAdmin(): boolean { - return isMod(this.props.admins.map(a => a.id), this.props.node.comment.creator_id); + return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.node.comment.creator_id); } get canAdmin(): boolean { - return canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id); + return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id); } handleReplyClick(i: CommentNode) { @@ -240,7 +240,6 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { creator_id: i.props.node.comment.creator_id, post_id: i.props.node.comment.post_id, parent_id: i.props.node.comment.parent_id, - removed: i.props.node.comment.removed, auth: null }; WebSocketService.Instance.editComment(deleteForm); diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index da375aee..7103a8cf 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -1,10 +1,10 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; import { WebSocketService, UserService } from '../services'; -import { Post, CreatePostLikeForm, PostForm as PostFormI, SavePostForm } from '../interfaces'; +import { Post, CreatePostLikeForm, PostForm as PostFormI, SavePostForm, CommunityUser, UserView } from '../interfaces'; import { MomentTime } from './moment-time'; import { PostForm } from './post-form'; -import { mdToHtml } from '../utils'; +import { mdToHtml, canMod, isMod } from '../utils'; interface PostListingState { showEdit: boolean; @@ -19,6 +19,8 @@ interface PostListingProps { showCommunity?: boolean; showBody?: boolean; viewOnly?: boolean; + moderators?: Array<CommunityUser>; + admins?: Array<UserView>; } export class PostListing extends Component<PostListingProps, PostListingState> { @@ -98,6 +100,12 @@ export class PostListing extends Component<PostListingProps, PostListingState> { <li className="list-inline-item"> <span>by </span> <Link className="text-info" to={`/user/${post.creator_id}`}>{post.creator_name}</Link> + {this.isMod && + <span className="mx-1 badge badge-secondary">mod</span> + } + {this.isAdmin && + <span className="mx-1 badge badge-secondary">admin</span> + } {this.props.showCommunity && <span> <span> to </span> @@ -135,7 +143,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> { </li> </> } - {this.props.post.am_mod && + {this.canMod && <span> <li className="list-inline-item"> {!this.props.post.removed ? @@ -166,6 +174,29 @@ export class PostListing extends Component<PostListingProps, PostListingState> { return UserService.Instance.user && this.props.post.creator_id == UserService.Instance.user.id; } + get canMod(): boolean { + + if (this.props.editable) { + 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.post.creator_id); + + } else return false; + } + + get isMod(): boolean { + return this.props.moderators && isMod(this.props.moderators.map(m => m.user_id), this.props.post.creator_id); + } + + get isAdmin(): boolean { + return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.post.creator_id); + } + + get canAdmin(): boolean { + return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.post.creator_id); + } + handlePostLike(i: PostListing) { let form: CreatePostLikeForm = { @@ -207,8 +238,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> { url: '', edit_id: i.props.post.id, creator_id: i.props.post.creator_id, - removed: !i.props.post.removed, - locked: !i.props.post.locked, auth: null }; WebSocketService.Instance.editPost(deleteForm); @@ -242,7 +271,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> { edit_id: i.props.post.id, creator_id: i.props.post.creator_id, removed: !i.props.post.removed, - locked: !i.props.post.locked, reason: i.state.removeReason, auth: null, }; @@ -258,7 +286,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> { community_id: i.props.post.community_id, edit_id: i.props.post.id, creator_id: i.props.post.creator_id, - removed: !i.props.post.removed, locked: !i.props.post.locked, auth: null, }; diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index 64f56d88..56b73f6e 100644 --- a/ui/src/components/post.tsx +++ b/ui/src/components/post.tsx @@ -82,7 +82,14 @@ export class Post extends Component<any, PostState> { <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 /> + <PostListing + post={this.state.post} + showBody + showCommunity + editable + moderators={this.state.moderators} + admins={this.state.admins} + /> <div className="mb-2" /> <CommentForm postId={this.state.post.id} disabled={this.state.post.locked} /> {this.sortRadios()} diff --git a/ui/src/interfaces.ts b/ui/src/interfaces.ts index 4a4ee643..8927a171 100644 --- a/ui/src/interfaces.ts +++ b/ui/src/interfaces.ts @@ -370,8 +370,8 @@ export interface PostForm { updated?: number; edit_id?: number; creator_id: number; - removed: boolean; - locked: boolean; + removed?: boolean; + locked?: boolean; reason?: string; auth: string; } @@ -402,7 +402,7 @@ export interface CommentForm { parent_id?: number; edit_id?: number; creator_id: number; - removed: boolean; + removed?: boolean; reason?: string; auth: string; } |