From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Tue, 27 Jun 2023 19:49:14 +0000 (-0400) Subject: refactor X-Git-Url: http://these/git/%22https:/nerdica.net/%7Biframely.url%7D?a=commitdiff_plain;h=8f1b0ad55920f6756a88525d678983b83428459b;p=lemmy-ui.git refactor --- diff --git a/src/shared/components/comment/comment-node.tsx b/src/shared/components/comment/comment-node.tsx index ff03ddc..079edec 100644 --- a/src/shared/components/comment/comment-node.tsx +++ b/src/shared/components/comment/comment-node.tsx @@ -1,6 +1,7 @@ import { colorList, getCommentParentId, + getRoleLabelPill, myAuth, myAuthRequired, showScores, @@ -318,7 +319,7 @@ export class CommentNode extends Component { )} {this.isPostCreator && - this.getRoleLabelPill({ + getRoleLabelPill({ label: I18NextService.i18n.t("op").toUpperCase(), tooltip: I18NextService.i18n.t("creator"), classes: "text-bg-info text-black", @@ -326,21 +327,21 @@ export class CommentNode extends Component { })} {isMod_ && - this.getRoleLabelPill({ + getRoleLabelPill({ label: I18NextService.i18n.t("mod"), tooltip: I18NextService.i18n.t("mod"), classes: "text-bg-primary text-black", })} {isAdmin_ && - this.getRoleLabelPill({ + getRoleLabelPill({ label: I18NextService.i18n.t("admin"), tooltip: I18NextService.i18n.t("admin"), - classes: "text-bg-danger text-black", + classes: "text-bg-danger text-white", })} {cv.creator.bot_account && - this.getRoleLabelPill({ + getRoleLabelPill({ label: I18NextService.i18n.t("bot_account").toLowerCase(), tooltip: I18NextService.i18n.t("bot_account"), })} @@ -1199,28 +1200,6 @@ export class CommentNode extends Component { } } - getRoleLabelPill({ - label, - tooltip, - classes, - shrink = true, - }: { - label: string; - tooltip: string; - classes?: string; - shrink?: boolean; - }) { - return ( - - {shrink ? label[0].toUpperCase() : label} - - ); - } - getLinkButton(small = false) { const cv = this.commentView; diff --git a/src/shared/components/person/profile.tsx b/src/shared/components/person/profile.tsx index afd8818..4a8de02 100644 --- a/src/shared/components/person/profile.tsx +++ b/src/shared/components/person/profile.tsx @@ -5,6 +5,7 @@ import { enableDownvotes, enableNsfw, getCommentParentId, + getRoleLabelPill, myAuth, myAuthRequired, setIsoData, @@ -484,23 +485,43 @@ export class Profile extends Component< /> {isBanned(pv.person) && ( -
  • - {I18NextService.i18n.t("banned")} +
  • + {getRoleLabelPill({ + label: I18NextService.i18n.t("banned"), + tooltip: I18NextService.i18n.t("banned"), + classes: "text-bg-danger text-white", + shrink: false, + })}
  • )} {pv.person.deleted && ( -
  • - {I18NextService.i18n.t("deleted")} +
  • + {getRoleLabelPill({ + label: I18NextService.i18n.t("deleted"), + tooltip: I18NextService.i18n.t("deleted"), + classes: "text-bg-danger text-white", + shrink: false, + })}
  • )} {pv.person.admin && ( -
  • - {I18NextService.i18n.t("admin")} +
  • + {getRoleLabelPill({ + label: I18NextService.i18n.t("admin"), + tooltip: I18NextService.i18n.t("admin"), + shrink: false, + })}
  • )} {pv.person.bot_account && ( -
  • - {I18NextService.i18n.t("bot_account").toLowerCase()} +
  • + {getRoleLabelPill({ + label: I18NextService.i18n + .t("bot_account") + .toLowerCase(), + tooltip: I18NextService.i18n.t("bot_account"), + shrink: false, + })}
  • )} diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index b9a1913..64b9a7a 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -1,4 +1,4 @@ -import { myAuthRequired } from "@utils/app"; +import { getRoleLabelPill, myAuthRequired } from "@utils/app"; import { canShare, share } from "@utils/browser"; import { getExternalHost, getHttpBase } from "@utils/env"; import { @@ -398,23 +398,27 @@ export class PostListing extends Component { createdLine() { const post_view = this.postView; return ( - - - {this.creatorIsMod_ && ( - - {I18NextService.i18n.t("mod")} - - )} - {this.creatorIsAdmin_ && ( - - {I18NextService.i18n.t("admin")} - - )} - {post_view.creator.bot_account && ( - - {I18NextService.i18n.t("bot_account").toLowerCase()} - - )} +
    + + + + {this.creatorIsMod_ && + getRoleLabelPill({ + label: I18NextService.i18n.t("mod"), + tooltip: I18NextService.i18n.t("mod"), + classes: "text-bg-primary text-black", + })} + {this.creatorIsAdmin_ && + getRoleLabelPill({ + label: I18NextService.i18n.t("admin"), + tooltip: I18NextService.i18n.t("admin"), + classes: "text-bg-danger text-white", + })} + {post_view.creator.bot_account && + getRoleLabelPill({ + label: I18NextService.i18n.t("bot_account").toLowerCase(), + tooltip: I18NextService.i18n.t("bot_account"), + })} {this.props.showCommunity && ( <> {" "} @@ -436,7 +440,7 @@ export class PostListing extends Component { published={post_view.post.published} updated={post_view.post.updated} /> - +
    ); } diff --git a/src/shared/utils/app/get-role-label-pill.tsx b/src/shared/utils/app/get-role-label-pill.tsx new file mode 100644 index 0000000..0cb0a41 --- /dev/null +++ b/src/shared/utils/app/get-role-label-pill.tsx @@ -0,0 +1,21 @@ +export default function getRoleLabelPill({ + label, + tooltip, + classes, + shrink = true, +}: { + label: string; + tooltip: string; + classes?: string; + shrink?: boolean; +}) { + return ( + + {shrink ? label[0].toUpperCase() : label} + + ); +} diff --git a/src/shared/utils/app/index.ts b/src/shared/utils/app/index.ts index f98357d..12cf1ea 100644 --- a/src/shared/utils/app/index.ts +++ b/src/shared/utils/app/index.ts @@ -29,6 +29,7 @@ import getDataTypeString from "./get-data-type-string"; import getDepthFromComment from "./get-depth-from-comment"; import getIdFromProps from "./get-id-from-props"; import getRecipientIdFromProps from "./get-recipient-id-from-props"; +import getRoleLabelPill from "./get-role-label-pill"; import getUpdatedSearchId from "./get-updated-search-id"; import initializeSite from "./initialize-site"; import insertCommentIntoTree from "./insert-comment-into-tree"; @@ -87,6 +88,7 @@ export { getDepthFromComment, getIdFromProps, getRecipientIdFromProps, + getRoleLabelPill, getUpdatedSearchId, getUserInterfaceLangId, initializeSite,