From 3561ef93a08742c74f36609754b87f2cd4a84e1c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Fri, 23 Aug 2019 19:40:41 -0700 Subject: Adding Community and Site transfer - Fixes #139 --- ui/src/components/comment-node.tsx | 45 +++++++++++++++++++++++++++++++++++++- ui/src/components/post.tsx | 13 ++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) (limited to 'ui/src/components') 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 { } } + {/* Community creators can transfer community to another mod */} + {this.amCommunityCreator && this.isMod && +
  • + # +
  • + } {/* Admins can ban from all, and appoint other admins */} {this.canAdmin && <> @@ -166,6 +172,12 @@ export class CommentNode extends Component { } } + {/* Site Creator can transfer to another admin */} + {this.amSiteCreator && this.isAdmin && +
  • + # +
  • + } }
  • @@ -251,6 +263,20 @@ export class CommentNode extends Component { 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 { 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 { 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); } } -- cgit v1.2.3