X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fpost%2Fpost-listing.tsx;h=5dcff2fce1407ddb4a8e4f0673ca2ac990283e58;hb=976812a44665e6a1f7fbf75d94c3383d820c1294;hp=1c305e8f1bd49d7be6acb1c576936e7d01dca462;hpb=a29cb0e83be264d1726b15fee313778b737e8444;p=lemmy-ui.git diff --git a/src/shared/components/post/post-listing.tsx b/src/shared/components/post/post-listing.tsx index 1c305e8..5dcff2f 100644 --- a/src/shared/components/post/post-listing.tsx +++ b/src/shared/components/post/post-listing.tsx @@ -49,12 +49,13 @@ import { PurgeType, VoteContentType, } from "../../interfaces"; -import { mdNoImages, mdToHtml, mdToHtmlInline } from "../../markdown"; +import { mdToHtml, mdToHtmlInline } 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 { PictrsImage } from "../common/pictrs-image"; +import { UserBadges } from "../common/user-badges"; import { VoteButtons, VoteButtonsCompact } from "../common/vote-buttons"; import { CommunityLink } from "../community/community-link"; import { PersonListing } from "../person/person-listing"; @@ -105,6 +106,9 @@ interface PostListingProps { allLanguages: Language[]; siteLanguages: number[]; showCommunity?: boolean; + /** + * Controls whether to show both the body *and* the metadata preview card + */ showBody?: boolean; hideImage?: boolean; enableDownvotes?: boolean; @@ -167,6 +171,26 @@ export class PostListing extends Component { this.handleEditCancel = this.handleEditCancel.bind(this); } + componentWillReceiveProps(nextProps: PostListingProps) { + if (this.props !== nextProps) { + this.setState({ + purgeLoading: false, + reportLoading: false, + blockLoading: false, + lockLoading: false, + deleteLoading: false, + removeLoading: false, + saveLoading: false, + featureCommunityLoading: false, + featureLocalLoading: false, + banLoading: false, + addModLoading: false, + addAdminLoading: false, + transferLoading: false, + }); + } + } + get postView(): PostView { return this.props.post_view; } @@ -180,7 +204,7 @@ export class PostListing extends Component { <> {this.listing()} {this.state.imageExpanded && !this.props.hideImage && this.img} - {post.url && this.state.showBody && post.embed_title && ( + {this.showBody && post.url && post.embed_title && ( )} {this.showBody && this.body()} @@ -308,27 +332,33 @@ export class PostListing extends Component { if (!this.props.hideImage && url && isImage(url) && this.imageSrc) { return ( - {this.imgThumb(this.imageSrc)} - - + + ); } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) { return ( {this.imgThumb(this.imageSrc)} - + ); } else if (url) { @@ -374,24 +404,16 @@ 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.props.showCommunity && ( <> {" "} @@ -413,7 +435,7 @@ export class PostListing extends Component { published={post_view.post.published} updated={post_view.post.updated} /> - +
); } @@ -443,8 +465,8 @@ export class PostListing extends Component { return ( <> -
-
+
{/** - * If there is a URL, or if the post has a body and we were told not to - * show the body, show the MetadataCard/body toggle. + * If there is (a) a URL and an embed title, or (b) a post body, and + * we were not told to show the body by the parent component, show the + * MetadataCard/body toggle. */} - {(post.url || (post.body && !this.props.showBody)) && ( - - )} + {!this.props.showBody && + ((post.url && post.embed_title) || post.body) && + this.showPreviewButton()} {post.removed && ( {I18NextService.i18n.t("removed")} )} + {post.deleted && ( { )} + {post.locked && ( { )} + {post.featured_community && ( { )} + {post.featured_local && ( { )} + {post.nsfw && ( {I18NextService.i18n.t("nsfw")} @@ -688,6 +691,50 @@ export class PostListing extends Component { {(this.canMod_ || this.canAdmin_) && (
  • {this.modRemoveButton}
  • )} + + {this.canMod_ && ( + <> +
  • +
    +
  • + {!this.creatorIsMod_ && + (!post_view.creator_banned_from_community ? ( +
  • {this.modBanFromCommunityButton}
  • + ) : ( +
  • {this.modUnbanFromCommunityButton}
  • + ))} + {!post_view.creator_banned_from_community && ( +
  • {this.addModToCommunityButton}
  • + )} + + )} + + {(amCommunityCreator(post_view.creator.id, this.props.moderators) || + this.canAdmin_) && + this.creatorIsMod_ &&
  • {this.transferCommunityButton}
  • } + + {/* Admins can ban from all, and appoint other admins */} + {this.canAdmin_ && ( + <> +
  • +
    +
  • + {!this.creatorIsAdmin_ && ( + <> + {!isBanned(post_view.creator) ? ( +
  • {this.modBanButton}
  • + ) : ( +
  • {this.modUnbanButton}
  • + )} +
  • {this.purgePersonButton}
  • +
  • {this.purgePostButton}
  • + + )} + {!isBanned(post_view.creator) && post_view.creator.local && ( +
  • {this.toggleAdminButton}
  • + )} + + )}
    @@ -952,6 +999,121 @@ export class PostListing extends Component { ); } + get modBanFromCommunityButton() { + return ( + + ); + } + + get modUnbanFromCommunityButton() { + return ( + + ); + } + + get addModToCommunityButton() { + return ( + + ); + } + + get modBanButton() { + return ( + + ); + } + + get modUnbanButton() { + return ( + + ); + } + + get purgePersonButton() { + return ( + + ); + } + + get purgePostButton() { + return ( + + ); + } + + get toggleAdminButton() { + return ( + + ); + } + + get transferCommunityButton() { + return ( + + ); + } + get modRemoveButton() { const removed = this.postView.post.removed; return ( @@ -966,188 +1128,17 @@ export class PostListing extends Component { {this.state.removeLoading ? ( ) : !removed ? ( - I18NextService.i18n.t("remove") + capitalizeFirstLetter(I18NextService.i18n.t("remove_post")) ) : ( - I18NextService.i18n.t("restore") + <> + {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "} + {I18NextService.i18n.t("post")} + )} ); } - /** - * Mod/Admin actions to be taken against the author. - */ - userActionsLine() { - // TODO: make nicer - const post_view = this.postView; - return ( - this.state.showAdvanced && ( -
    - {this.canMod_ && ( - <> - {!this.creatorIsMod_ && - (!post_view.creator_banned_from_community ? ( - - ) : ( - - ))} - {!post_view.creator_banned_from_community && ( - - )} - - )} - {/* Community creators and admins can transfer community to another mod */} - {(amCommunityCreator(post_view.creator.id, this.props.moderators) || - this.canAdmin_) && - this.creatorIsMod_ && - (!this.state.showConfirmTransferCommunity ? ( - - ) : ( - <> - - - - - ))} - {/* Admins can ban from all, and appoint other admins */} - {this.canAdmin_ && ( - <> - {!this.creatorIsAdmin_ && ( - <> - {!isBanned(post_view.creator) ? ( - - ) : ( - - )} - - - - )} - {!isBanned(post_view.creator) && post_view.creator.local && ( - - )} - - )} -
    - ) - ); - } - removeAndBanDialogs() { const post = this.postView; const purgeTypeText = @@ -1175,11 +1166,7 @@ export class PostListing extends Component { value={this.state.removeReason} onInput={linkEvent(this, this.handleModRemoveReasonChange)} /> - )} + {this.state.showConfirmTransferCommunity && ( + <> + + + + + )} {this.state.showBanDialog && (
    @@ -1241,11 +1255,7 @@ export class PostListing extends Component { {/* */} {/*
    */}
    - )} @@ -1338,6 +1340,21 @@ export class PostListing extends Component { ); } + showPreviewButton() { + return ( + + ); + } + listing() { return ( <> @@ -1351,7 +1368,6 @@ export class PostListing extends Component { {this.mobileThumbnail()} {this.commentsLine(true)} - {this.userActionsLine()} {this.duplicatesLine()} {this.removeAndBanDialogs()}
    @@ -1362,26 +1378,27 @@ export class PostListing extends Component {
    {!this.props.viewOnly && ( - +
    + +
    )} -
    -
    {this.thumbnail()}
    -
    -
    +
    -
    +
    +
    {this.thumbnail()}
    +
    +
    {this.postTitleLine()} {this.createdLine()} {this.commentsLine()} {this.duplicatesLine()} - {this.userActionsLine()} {this.removeAndBanDialogs()}
    @@ -1398,6 +1415,7 @@ export class PostListing extends Component { UserService.Instance.myUserInfo?.local_user_view.person.id ); } + handleEditClick(i: PostListing) { i.setState({ showEdit: true }); } @@ -1521,6 +1539,7 @@ export class PostListing extends Component { post_id: i.postView.post.id, removed: !i.postView.post.removed, auth: myAuthRequired(), + reason: i.state.removeReason, }); } @@ -1592,13 +1611,13 @@ export class PostListing extends Component { handlePurgeSubmit(i: PostListing, event: any) { event.preventDefault(); i.setState({ purgeLoading: true }); - if (i.state.purgeType == PurgeType.Person) { + if (i.state.purgeType === PurgeType.Person) { i.props.onPurgePerson({ person_id: i.postView.creator.id, reason: i.state.purgeReason, auth: myAuthRequired(), }); - } else if (i.state.purgeType == PurgeType.Post) { + } else if (i.state.purgeType === PurgeType.Post) { i.props.onPurgePost({ post_id: i.postView.post.id, reason: i.state.purgeReason,