X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fcomment%2Fcomment-node.tsx;h=c6b37fdb2636f8d1589704d5c3b687082c7236f6;hb=9869b911cf480ee88c7b1e7d2f689cc2e1c65157;hp=806d2c2f8e78faec10909bd5ee27769e133b1fda;hpb=5033d03ed20707738ff4dfcceac2f854ff484b35;p=lemmy-ui.git diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index 806d2c2..c6b37fd 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,4 +1,23 @@ +import { + colorList, + getCommentParentId, + myAuth, + myAuthRequired, + showScores, +} from "@utils/app"; +import { futureDaysToUnixTime, numToSI } from "@utils/helpers"; +import { + amCommunityCreator, + canAdmin, + canMod, + isAdmin, + isBanned, + isMod, +} from "@utils/roles"; import classNames from "classnames"; +import isBefore from "date-fns/isBefore"; +import parseISO from "date-fns/parseISO"; +import subMinutes from "date-fns/subMinutes"; import { Component, InfernoNode, linkEvent } from "inferno"; import { Link } from "inferno-router"; import { @@ -29,38 +48,22 @@ import { SaveComment, TransferCommunity, } from "lemmy-js-client"; -import moment from "moment"; -import { i18n } from "../../i18next"; +import deepEqual from "lodash.isequal"; +import { commentTreeMaxDepth } from "../../config"; import { BanType, CommentNodeI, CommentViewType, PurgeType, - VoteType, + VoteContentType, } from "../../interfaces"; -import { UserService } from "../../services"; -import { - amCommunityCreator, - canAdmin, - canMod, - colorList, - commentTreeMaxDepth, - futureDaysToUnixTime, - getCommentParentId, - isAdmin, - isBanned, - isMod, - mdToHtml, - mdToHtmlNoImages, - myAuth, - myAuthRequired, - newVote, - numToSI, - setupTippy, - showScores, -} from "../../utils"; +import { mdToHtml, mdToHtmlNoImages } from "../../markdown"; +import { I18NextService, UserService } from "../../services"; +import { setupTippy } from "../../tippy"; import { Icon, PurgeWarning, Spinner } from "../common/icon"; import { MomentTime } from "../common/moment-time"; +import { UserBadges } from "../common/user-badges"; +import { VoteButtonsCompact } from "../common/vote-buttons"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; import { CommentForm } from "./comment-form"; @@ -194,10 +197,21 @@ export class CommentNode extends Component { return this.commentView.comment.id; } + get hasBadges(): boolean { + const cv = this.commentView; + + return ( + this.isPostCreator || + isMod(cv.creator.id, this.props.moderators) || + isAdmin(cv.creator.id, this.props.admins) || + cv.creator.bot_account + ); + } + componentWillReceiveProps( nextProps: Readonly<{ children?: InfernoNode } & CommentNodeProps> ): void { - if (this.props != nextProps) { + if (!deepEqual(this.props, nextProps)) { this.setState({ showReply: false, showEdit: false, @@ -241,8 +255,8 @@ export class CommentNode extends Component { const purgeTypeText = this.state.purgeType == PurgeType.Comment - ? i18n.t("purge_comment") - : `${i18n.t("purge")} ${cv.creator.name}`; + ? I18NextService.i18n.t("purge_comment") + : `${I18NextService.i18n.t("purge")} ${cv.creator.name}`; const canMod_ = canMod( cv.creator.id, @@ -281,7 +295,7 @@ export class CommentNode extends Component { node.comment_view.counts.child_count > 0; return ( -
  • +
  • { >
    - - - + + + {cv.comment.distinguished && ( - - )} - {this.isPostCreator && ( -
    - {i18n.t("creator")} -
    - )} - {isMod_ && ( -
    - {i18n.t("mod")} -
    - )} - {isAdmin_ && ( -
    - {i18n.t("admin")} -
    - )} - {cv.creator.bot_account && ( -
    - {i18n.t("bot_account").toLowerCase()} -
    + )} + + + {this.props.showCommunity && ( <> - {i18n.t("to")} + {I18NextService.i18n.t("to")} • - + {cv.post.name} )} - {this.linkBtn(true)} + + {this.getLinkButton(true)} + {cv.comment.language_id !== 0 && ( - + { this.props.allLanguages.find( lang => lang.id === cv.comment.language_id @@ -353,31 +358,20 @@ export class CommentNode extends Component { )} {/* This is an expanding spacer for mobile */} -
    +
    + {showScores() && ( <> - - {this.state.upvoteLoading ? ( - - ) : ( - - {numToSI(this.commentView.counts.score)} - - )} - - • + {numToSI(this.commentView.counts.score)} + + • )} @@ -418,21 +412,21 @@ export class CommentNode extends Component { } /> )} -
    - {this.props.showContext && this.linkBtn()} +
    + {this.props.showContext && this.getLinkButton()} {this.props.markable && ( - {this.props.enableDownvotes && ( - - )} + @@ -515,8 +463,8 @@ export class CommentNode extends Component { @@ -527,7 +475,9 @@ export class CommentNode extends Component { @@ -537,10 +487,12 @@ export class CommentNode extends Component { this, this.handleShowReportDialog )} - data-tippy-content={i18n.t( + data-tippy-content={I18NextService.i18n.t( + "show_report_dialog" + )} + aria-label={I18NextService.i18n.t( "show_report_dialog" )} - aria-label={i18n.t("show_report_dialog")} > @@ -550,8 +502,10 @@ export class CommentNode extends Component { this, this.handleBlockPerson )} - data-tippy-content={i18n.t("block_user")} - aria-label={i18n.t("block_user")} + data-tippy-content={I18NextService.i18n.t( + "block_user" + )} + aria-label={I18NextService.i18n.t("block_user")} > {this.state.blockPersonLoading ? ( @@ -565,10 +519,14 @@ export class CommentNode extends Component { className="btn btn-link btn-animate text-muted" onClick={linkEvent(this, this.handleSaveComment)} data-tippy-content={ - cv.saved ? i18n.t("unsave") : i18n.t("save") + cv.saved + ? I18NextService.i18n.t("unsave") + : I18NextService.i18n.t("save") } aria-label={ - cv.saved ? i18n.t("unsave") : i18n.t("save") + cv.saved + ? I18NextService.i18n.t("unsave") + : I18NextService.i18n.t("save") } > {this.state.saveLoading ? ( @@ -585,8 +543,10 @@ export class CommentNode extends Component { @@ -613,13 +575,13 @@ export class CommentNode extends Component { )} data-tippy-content={ !cv.comment.deleted - ? i18n.t("delete") - : i18n.t("restore") + ? I18NextService.i18n.t("delete") + : I18NextService.i18n.t("restore") } aria-label={ !cv.comment.deleted - ? i18n.t("delete") - : i18n.t("restore") + ? I18NextService.i18n.t("delete") + : I18NextService.i18n.t("restore") } > {this.state.deleteLoading ? ( @@ -643,13 +605,13 @@ export class CommentNode extends Component { )} data-tippy-content={ !cv.comment.distinguished - ? i18n.t("distinguish") - : i18n.t("undistinguish") + ? I18NextService.i18n.t("distinguish") + : I18NextService.i18n.t("undistinguish") } aria-label={ !cv.comment.distinguished - ? i18n.t("distinguish") - : i18n.t("undistinguish") + ? I18NextService.i18n.t("distinguish") + : I18NextService.i18n.t("undistinguish") } > { this, this.handleModRemoveShow )} - aria-label={i18n.t("remove")} + aria-label={I18NextService.i18n.t("remove")} > - {i18n.t("remove")} + {I18NextService.i18n.t("remove")} ) : ( )} @@ -705,9 +667,13 @@ export class CommentNode extends Component { this, this.handleModBanFromCommunityShow )} - aria-label={i18n.t("ban_from_community")} + aria-label={I18NextService.i18n.t( + "ban_from_community" + )} > - {i18n.t("ban_from_community")} + {I18NextService.i18n.t( + "ban_from_community" + )} ) : ( ))} @@ -735,21 +701,25 @@ export class CommentNode extends Component { )} aria-label={ isMod_ - ? i18n.t("remove_as_mod") - : i18n.t("appoint_as_mod") + ? I18NextService.i18n.t("remove_as_mod") + : I18NextService.i18n.t( + "appoint_as_mod" + ) } > {isMod_ - ? i18n.t("remove_as_mod") - : i18n.t("appoint_as_mod")} + ? I18NextService.i18n.t("remove_as_mod") + : I18NextService.i18n.t("appoint_as_mod")} ) : ( <> ))} @@ -790,17 +760,21 @@ export class CommentNode extends Component { this, this.handleShowConfirmTransferCommunity )} - aria-label={i18n.t("transfer_community")} + aria-label={I18NextService.i18n.t( + "transfer_community" + )} > - {i18n.t("transfer_community")} + {I18NextService.i18n.t("transfer_community")} ) : ( <> ))} @@ -840,9 +814,11 @@ export class CommentNode extends Component { this, this.handlePurgePersonShow )} - aria-label={i18n.t("purge_user")} + aria-label={I18NextService.i18n.t( + "purge_user" + )} > - {i18n.t("purge_user")} + {I18NextService.i18n.t("purge_user")} {!isBanned(cv.creator) ? ( @@ -862,9 +840,11 @@ export class CommentNode extends Component { this, this.handleModBanShow )} - aria-label={i18n.t("ban_from_site")} + aria-label={I18NextService.i18n.t( + "ban_from_site" + )} > - {i18n.t("ban_from_site")} + {I18NextService.i18n.t("ban_from_site")} ) : ( )} @@ -895,18 +877,24 @@ export class CommentNode extends Component { )} aria-label={ isAdmin_ - ? i18n.t("remove_as_admin") - : i18n.t("appoint_as_admin") + ? I18NextService.i18n.t( + "remove_as_admin" + ) + : I18NextService.i18n.t( + "appoint_as_admin" + ) } > {isAdmin_ - ? i18n.t("remove_as_admin") - : i18n.t("appoint_as_admin")} + ? I18NextService.i18n.t("remove_as_admin") + : I18NextService.i18n.t( + "appoint_as_admin" + )} ) : ( <> ))} @@ -948,7 +936,7 @@ export class CommentNode extends Component {
    {showMoreChildren && (
    { ) : ( <> - {i18n.t("x_more_replies", { + {I18NextService.i18n.t("x_more_replies", { count: node.comment_view.counts.child_count, formattedCount: numToSI( node.comment_view.counts.child_count @@ -980,25 +968,25 @@ export class CommentNode extends Component { onSubmit={linkEvent(this, this.handleRemoveComment)} > )} @@ -1008,43 +996,43 @@ export class CommentNode extends Component { onSubmit={linkEvent(this, this.handleReportComment)} > )} {this.state.showBanDialog && (
    -
    +
    @@ -1052,17 +1040,17 @@ export class CommentNode extends Component { className="col-form-label" htmlFor={`mod-ban-expires-${cv.comment.id}`} > - {i18n.t("expires")} + {I18NextService.i18n.t("expires")} -
    +
    {
    {/* TODO hold off on expires until later */} - {/*
    */} + {/*
    */} {/* */} - {/* */} + {/* */} {/*
    */} -
    +
    @@ -1107,18 +1095,18 @@ export class CommentNode extends Component { {this.state.showPurgeDialog && ( -