diff options
author | Dessalines <tyhou13@gmx.com> | 2019-08-23 19:40:41 -0700 |
---|---|---|
committer | Dessalines <tyhou13@gmx.com> | 2019-08-23 19:40:41 -0700 |
commit | 3561ef93a08742c74f36609754b87f2cd4a84e1c (patch) | |
tree | d6a1a5a6823bfee68a3e6bbbea9031f597bdb79b /ui/src/components | |
parent | d5b9ba724dbab8ac1b17ca52d3f85309e5f22497 (diff) |
Adding Community and Site transfer
- Fixes #139
Diffstat (limited to 'ui/src/components')
-rw-r--r-- | ui/src/components/comment-node.tsx | 45 | ||||
-rw-r--r-- | ui/src/components/post.tsx | 13 |
2 files changed, 56 insertions, 2 deletions
diff --git a/ui/src/components/comment-node.tsx b/ui/src/components/comment-node.tsx index 610252ea..f518da90 100644 --- a/ui/src/components/comment-node.tsx +++ b/ui/src/components/comment-node.tsx @@ -1,6 +1,6 @@ import { Component, linkEvent } from 'inferno'; import { Link } from 'inferno-router'; -import { CommentNode as CommentNodeI, CommentLikeForm, CommentForm as CommentFormI, SaveCommentForm, BanFromCommunityForm, BanUserForm, CommunityUser, UserView, AddModToCommunityForm, AddAdminForm } from '../interfaces'; +import { CommentNode as CommentNodeI, CommentLikeForm, CommentForm as CommentFormI, SaveCommentForm, BanFromCommunityForm, BanUserForm, CommunityUser, UserView, AddModToCommunityForm, AddAdminForm, TransferCommunityForm, TransferSiteForm } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { mdToHtml, getUnixTime, canMod, isMod } from '../utils'; import * as moment from 'moment'; @@ -148,6 +148,12 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { } </> } + {/* Community creators can transfer community to another mod */} + {this.amCommunityCreator && this.isMod && + <li className="list-inline-item"> + <span class="pointer" onClick={linkEvent(this, this.handleTransferCommunity)}><T i18nKey="transfer_community">#</T></span> + </li> + } {/* Admins can ban from all, and appoint other admins */} {this.canAdmin && <> @@ -166,6 +172,12 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { } </> } + {/* Site Creator can transfer to another admin */} + {this.amSiteCreator && this.isAdmin && + <li className="list-inline-item"> + <span class="pointer" onClick={linkEvent(this, this.handleTransferSite)}><T i18nKey="transfer_site">#</T></span> + </li> + } </> } <li className="list-inline-item"> @@ -251,6 +263,20 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id); } + get amCommunityCreator(): boolean { + return this.props.moderators && + UserService.Instance.user && + (this.props.node.comment.creator_id != UserService.Instance.user.id) && + (UserService.Instance.user.id == this.props.moderators[0].user_id); + } + + get amSiteCreator(): boolean { + return this.props.admins && + UserService.Instance.user && + (this.props.node.comment.creator_id != UserService.Instance.user.id) && + (UserService.Instance.user.id == this.props.admins[0].id); + } + handleReplyClick(i: CommentNode) { i.state.showReply = true; i.setState(i.state); @@ -431,6 +457,23 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> { i.setState(i.state); } + handleTransferCommunity(i: CommentNode) { + let form: TransferCommunityForm = { + community_id: i.props.node.comment.community_id, + user_id: i.props.node.comment.creator_id, + }; + WebSocketService.Instance.transferCommunity(form); + i.setState(i.state); + } + + handleTransferSite(i: CommentNode) { + let form: TransferSiteForm = { + user_id: i.props.node.comment.creator_id, + }; + WebSocketService.Instance.transferSite(form); + i.setState(i.state); + } + get isCommentNew(): boolean { let now = moment.utc().subtract(10, 'minutes'); let then = moment.utc(this.props.node.comment.published); diff --git a/ui/src/components/post.tsx b/ui/src/components/post.tsx index ab82ca4f..a6df4105 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, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse } from '../interfaces'; +import { UserOperation, Community, Post as PostI, GetPostResponse, PostResponse, Comment, CommentForm as CommentFormI, CommentResponse, CommentSortType, CreatePostLikeResponse, CommunityUser, CommunityResponse, CommentNode as CommentNodeI, BanFromCommunityResponse, BanUserResponse, AddModToCommunityResponse, AddAdminResponse, UserView, SearchType, SortType, SearchForm, SearchResponse, GetSiteResponse, GetCommunityResponse } from '../interfaces'; import { WebSocketService, UserService } from '../services'; import { msgOp, hotRank } from '../utils'; import { PostListing } from './post-listing'; @@ -370,6 +370,17 @@ export class Post extends Component<any, PostState> { let res: SearchResponse = msg; this.state.crossPosts = res.posts.filter(p => p.id != this.state.post.id); this.setState(this.state); + } else if (op == UserOperation.TransferSite) { + let res: GetSiteResponse = msg; + + this.state.admins = res.admins; + this.setState(this.state); + } else if (op == UserOperation.TransferCommunity) { + let res: GetCommunityResponse = msg; + this.state.community = res.community; + this.state.moderators = res.moderators; + this.state.admins = res.admins; + this.setState(this.state); } } |