X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fcomment%2Fcomment-node.tsx;h=8559f38baa1355d0809ed3766d34f328a35dc639;hb=2b1af707c3df6126b3e6890106c03c60ad49b1be;hp=f80cc8b595d0919035477710e0a6e6eab7f3df01;hpb=f61037f5d89f12818c8100f907a98b74e980112a;p=lemmy-ui.git diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index f80cc8b..8559f38 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,5 +1,5 @@ import classNames from "classnames"; -import { Component, linkEvent } from "inferno"; +import { Component, InfernoNode, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { AddAdmin, @@ -7,13 +7,16 @@ import { BanFromCommunity, BanPerson, BlockPerson, + CommentId, CommentReplyView, CommentView, CommunityModeratorView, + CreateComment, CreateCommentLike, CreateCommentReport, DeleteComment, DistinguishComment, + EditComment, GetComments, Language, MarkCommentReplyAsRead, @@ -33,8 +36,9 @@ import { CommentNodeI, CommentViewType, PurgeType, + VoteType, } from "../../interfaces"; -import { UserService, WebSocketService } from "../../services"; +import { UserService } from "../../services"; import { amCommunityCreator, canAdmin, @@ -49,10 +53,11 @@ import { mdToHtml, mdToHtmlNoImages, myAuth, + myAuthRequired, + newVote, numToSI, setupTippy, showScores, - wsClient, } from "../../utils"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; @@ -74,7 +79,6 @@ interface CommentNodeState { showPurgeDialog: boolean; purgeReason?: string; purgeType: PurgeType; - purgeLoading: boolean; showConfirmTransferSite: boolean; showConfirmTransferCommunity: boolean; showConfirmAppointAsMod: boolean; @@ -84,12 +88,22 @@ interface CommentNodeState { showAdvanced: boolean; showReportDialog: boolean; reportReason?: string; - my_vote?: number; - score: number; - upvotes: number; - downvotes: number; - readLoading: boolean; + createOrEditCommentLoading: boolean; + upvoteLoading: boolean; + downvoteLoading: boolean; saveLoading: boolean; + readLoading: boolean; + blockPersonLoading: boolean; + deleteLoading: boolean; + removeLoading: boolean; + distinguishLoading: boolean; + banLoading: boolean; + addModLoading: boolean; + addAdminLoading: boolean; + transferCommunityLoading: boolean; + fetchChildrenLoading: boolean; + reportLoading: boolean; + purgeLoading: boolean; } interface CommentNodeProps { @@ -108,6 +122,26 @@ interface CommentNodeProps { allLanguages: Language[]; siteLanguages: number[]; hideImages?: boolean; + finished: Map; + onSaveComment(form: SaveComment): void; + onCommentReplyRead(form: MarkCommentReplyAsRead): void; + onPersonMentionRead(form: MarkPersonMentionAsRead): void; + onCreateComment(form: EditComment | CreateComment): void; + onEditComment(form: EditComment | CreateComment): void; + onCommentVote(form: CreateCommentLike): void; + onBlockPerson(form: BlockPerson): void; + onDeleteComment(form: DeleteComment): void; + onRemoveComment(form: RemoveComment): void; + onDistinguishComment(form: DistinguishComment): void; + onAddModToCommunity(form: AddModToCommunity): void; + onAddAdmin(form: AddAdmin): void; + onBanPersonFromCommunity(form: BanFromCommunity): void; + onBanPerson(form: BanPerson): void; + onTransferCommunity(form: TransferCommunity): void; + onFetchChildren?(form: GetComments): void; + onCommentReport(form: CreateCommentReport): void; + onPurgePerson(form: PurgePerson): void; + onPurgeComment(form: PurgeComment): void; } export class CommentNode extends Component { @@ -119,7 +153,6 @@ export class CommentNode extends Component { removeData: false, banType: BanType.Community, showPurgeDialog: false, - purgeLoading: false, purgeType: PurgeType.Person, collapsed: false, viewSource: false, @@ -129,67 +162,109 @@ export class CommentNode extends Component { showConfirmAppointAsMod: false, showConfirmAppointAsAdmin: false, showReportDialog: false, - my_vote: this.props.node.comment_view.my_vote, - score: this.props.node.comment_view.counts.score, - upvotes: this.props.node.comment_view.counts.upvotes, - downvotes: this.props.node.comment_view.counts.downvotes, - readLoading: false, + createOrEditCommentLoading: false, + upvoteLoading: false, + downvoteLoading: false, saveLoading: false, + readLoading: false, + blockPersonLoading: false, + deleteLoading: false, + removeLoading: false, + distinguishLoading: false, + banLoading: false, + addModLoading: false, + addAdminLoading: false, + transferCommunityLoading: false, + fetchChildrenLoading: false, + reportLoading: false, + purgeLoading: false, }; constructor(props: any, context: any) { super(props, context); this.handleReplyCancel = this.handleReplyCancel.bind(this); - this.handleCommentUpvote = this.handleCommentUpvote.bind(this); - this.handleCommentDownvote = this.handleCommentDownvote.bind(this); } - // TODO see if there's a better way to do this, and all willReceiveProps - componentWillReceiveProps(nextProps: CommentNodeProps) { - const cv = nextProps.node.comment_view; - this.setState({ - my_vote: cv.my_vote, - upvotes: cv.counts.upvotes, - downvotes: cv.counts.downvotes, - score: cv.counts.score, - readLoading: false, - saveLoading: false, - }); + get commentView(): CommentView { + return this.props.node.comment_view; + } + + get commentId(): CommentId { + return this.commentView.comment.id; + } + + componentWillReceiveProps( + nextProps: Readonly<{ children?: InfernoNode } & CommentNodeProps> + ): void { + if (this.props != nextProps) { + this.setState({ + showReply: false, + showEdit: false, + showRemoveDialog: false, + showBanDialog: false, + removeData: false, + banType: BanType.Community, + showPurgeDialog: false, + purgeType: PurgeType.Person, + collapsed: false, + viewSource: false, + showAdvanced: false, + showConfirmTransferSite: false, + showConfirmTransferCommunity: false, + showConfirmAppointAsMod: false, + showConfirmAppointAsAdmin: false, + showReportDialog: false, + createOrEditCommentLoading: false, + upvoteLoading: false, + downvoteLoading: false, + saveLoading: false, + readLoading: false, + blockPersonLoading: false, + deleteLoading: false, + removeLoading: false, + distinguishLoading: false, + banLoading: false, + addModLoading: false, + addAdminLoading: false, + transferCommunityLoading: false, + fetchChildrenLoading: false, + reportLoading: false, + purgeLoading: false, + }); + } } render() { const node = this.props.node; - const cv = this.props.node.comment_view; + const cv = this.commentView; const purgeTypeText = this.state.purgeType == PurgeType.Comment ? i18n.t("purge_comment") : `${i18n.t("purge")} ${cv.creator.name}`; - const canMod_ = - canMod(cv.creator.id, this.props.moderators, this.props.admins) && - cv.community.local; - const canModOnSelf = - canMod( - cv.creator.id, - this.props.moderators, - this.props.admins, - UserService.Instance.myUserInfo, - true - ) && cv.community.local; - const canAdmin_ = - canAdmin(cv.creator.id, this.props.admins) && cv.community.local; - const canAdminOnSelf = - canAdmin( - cv.creator.id, - this.props.admins, - UserService.Instance.myUserInfo, - true - ) && cv.community.local; + const canMod_ = canMod( + cv.creator.id, + this.props.moderators, + this.props.admins + ); + const canModOnSelf = canMod( + cv.creator.id, + this.props.moderators, + this.props.admins, + UserService.Instance.myUserInfo, + true + ); + const canAdmin_ = canAdmin(cv.creator.id, this.props.admins); + const canAdminOnSelf = canAdmin( + cv.creator.id, + this.props.admins, + UserService.Instance.myUserInfo, + true + ); const isMod_ = isMod(cv.creator.id, this.props.moderators); - const isAdmin_ = - isAdmin(cv.creator.id, this.props.admins) && cv.community.local; + const isAdmin_ = isAdmin(cv.creator.id, this.props.admins); const amCommunityCreator_ = amCommunityCreator( cv.creator.id, this.props.moderators @@ -218,9 +293,7 @@ export class CommentNode extends Component { id={`comment-${cv.comment.id}`} className={classNames(`details comment-node py-2`, { "border-top border-light": !this.props.noBorder, - mark: - this.isCommentNew || - this.props.node.comment_view.comment.distinguished, + mark: this.isCommentNew || this.commentView.comment.distinguished, })} style={ !this.props.noIndent && this.props.node.depth @@ -297,18 +370,24 @@ export class CommentNode extends Component { <> - - {numToSI(this.state.score)} - + {this.state.upvoteLoading ? ( + + ) : ( + + {numToSI(this.commentView.counts.score)} + + )} • @@ -327,9 +406,13 @@ export class CommentNode extends Component { edit onReplyCancel={this.handleReplyCancel} disabled={this.props.locked} + finished={this.props.finished.get( + this.props.node.comment_view.comment.id + )} focus allLanguages={this.props.allLanguages} siteLanguages={this.props.siteLanguages} + onUpsertComment={this.props.onEditComment} /> )} {!this.state.showEdit && !this.state.collapsed && ( @@ -351,7 +434,7 @@ export class CommentNode extends Component { {this.props.markable && ( {this.props.enableDownvotes && ( )} )} {(canModOnSelf || canAdminOnSelf) && ( @@ -546,7 +650,7 @@ export class CommentNode extends Component { className="btn btn-link btn-animate text-muted" onClick={linkEvent( this, - this.handleDistinguishClick + this.handleDistinguishComment )} data-tippy-content={ !cv.comment.distinguished @@ -588,11 +692,15 @@ export class CommentNode extends Component { className="btn btn-link btn-animate text-muted" onClick={linkEvent( this, - this.handleModRemoveSubmit + this.handleRemoveComment )} aria-label={i18n.t("restore")} > - {i18n.t("restore")} + {this.state.removeLoading ? ( + + ) : ( + i18n.t("restore") + )} )} @@ -617,11 +725,15 @@ export class CommentNode extends Component { className="btn btn-link btn-animate text-muted" onClick={linkEvent( this, - this.handleModBanFromCommunitySubmit + this.handleBanPersonFromCommunity )} aria-label={i18n.t("unban")} > - {i18n.t("unban")} + {this.state.banLoading ? ( + + ) : ( + i18n.t("unban") + )} ))} {!cv.creator_banned_from_community && @@ -658,7 +770,11 @@ export class CommentNode extends Component { )} aria-label={i18n.t("yes")} > - {i18n.t("yes")} + {this.state.addModLoading ? ( + + ) : ( + i18n.t("yes") + )} )} @@ -803,7 +927,11 @@ export class CommentNode extends Component { )} aria-label={i18n.t("yes")} > - {i18n.t("yes")} + {this.state.addAdminLoading ? ( + + ) : ( + i18n.t("yes") + )} )} @@ -852,7 +988,7 @@ export class CommentNode extends Component { {this.state.showRemoveDialog && (