-import { myAuthRequired } from "@utils/app";
+import { getRoleLabelPill, myAuthRequired } from "@utils/app";
import { canShare, share } from "@utils/browser";
import { getExternalHost, getHttpBase } from "@utils/env";
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";
allLanguages: Language[];
siteLanguages: number[];
showCommunity?: boolean;
+ /**
+ * Controls whether to show both the body *and* the metadata preview card
+ */
showBody?: boolean;
hideImage?: boolean;
enableDownvotes?: boolean;
<>
{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 && (
<MetadataCard post={post} />
)}
{this.showBody && this.body()}
return (
<button
type="button"
- className="d-inline-block position-relative mb-2 p-0 border-0"
+ className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0 bg-transparent"
data-tippy-content={I18NextService.i18n.t("expand_here")}
onClick={linkEvent(this, this.handleImageExpandClick)}
aria-label={I18NextService.i18n.t("expand_here")}
} else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
return (
<a
- className="text-body d-inline-block position-relative mb-2"
+ className="thumbnail rounded overflow-hidden d-inline-block position-relative p-0 border-0"
href={url}
rel={relTags}
title={url}
createdLine() {
const post_view = this.postView;
+
return (
- <span className="small">
- <PersonListing person={post_view.creator} />
- {this.creatorIsMod_ && (
- <span className="mx-1 badge text-bg-light">
- {I18NextService.i18n.t("mod")}
- </span>
- )}
- {this.creatorIsAdmin_ && (
- <span className="mx-1 badge text-bg-light">
- {I18NextService.i18n.t("admin")}
- </span>
- )}
- {post_view.creator.bot_account && (
- <span className="mx-1 badge text-bg-light">
- {I18NextService.i18n.t("bot_account").toLowerCase()}
- </span>
- )}
+ <div className="small mb-1 mb-md-0">
+ <span className="me-1">
+ <PersonListing person={post_view.creator} />
+ </span>
+ {this.creatorIsMod_ &&
+ getRoleLabelPill({
+ label: I18NextService.i18n.t("mod"),
+ tooltip: I18NextService.i18n.t("mod"),
+ classes: "text-bg-primary",
+ })}
+ {this.creatorIsAdmin_ &&
+ getRoleLabelPill({
+ label: I18NextService.i18n.t("admin"),
+ tooltip: I18NextService.i18n.t("admin"),
+ classes: "text-bg-danger",
+ })}
+ {post_view.creator.bot_account &&
+ getRoleLabelPill({
+ label: I18NextService.i18n.t("bot_account").toLowerCase(),
+ tooltip: I18NextService.i18n.t("bot_account"),
+ })}
{this.props.showCommunity && (
<>
{" "}
published={post_view.post.published}
updated={post_view.post.updated}
/>
- </span>
+ </div>
);
}
)}
</h5>
+ {/**
+ * 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.
+ */}
+ {!this.props.showBody &&
+ ((post.url && post.embed_title) || post.body) &&
+ this.showPreviewButton()}
+
{post.removed && (
<small className="ms-2 badge text-bg-secondary">
{I18NextService.i18n.t("removed")}
);
}
- showPreviewButton() {
- const post_view = this.postView;
- const body = post_view.post.body;
-
- return (
- <button
- className="btn btn-sm btn-animate text-muted py-0"
- data-tippy-content={body && mdNoImages.render(body)}
- data-tippy-allowHtml={true}
- onClick={linkEvent(this, this.handleShowBody)}
- >
- <Icon
- icon="book-open"
- classes={classNames("icon-inline me-1", {
- "text-success": this.state.showBody,
- })}
- />
- </button>
- );
- }
-
postActions() {
// Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
// Possible enhancement: Make each button a component.
{this.saveButton}
{this.crossPostButton}
- {/**
- * 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.
- */}
- {(post.url || (post.body && !this.props.showBody)) &&
- this.showPreviewButton()}
-
- {this.showBody && post_view.post.body && this.viewSourceButton}
+ {this.props.showBody && post_view.post.body && this.viewSourceButton}
<div className="dropdown">
<button
{(this.canMod_ || this.canAdmin_) && (
<li>{this.modRemoveButton}</li>
)}
+
+ {this.canMod_ && (
+ <>
+ <li>
+ <hr className="dropdown-divider" />
+ </li>
+ {!this.creatorIsMod_ &&
+ (!post_view.creator_banned_from_community ? (
+ <li>{this.modBanFromCommunityButton}</li>
+ ) : (
+ <li>{this.modUnbanFromCommunityButton}</li>
+ ))}
+ {!post_view.creator_banned_from_community && (
+ <li>{this.addModToCommunityButton}</li>
+ )}
+ </>
+ )}
+
+ {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
+ this.canAdmin_) &&
+ this.creatorIsMod_ && <li>{this.transferCommunityButton}</li>}
+
+ {/* Admins can ban from all, and appoint other admins */}
+ {this.canAdmin_ && (
+ <>
+ <li>
+ <hr className="dropdown-divider" />
+ </li>
+ {!this.creatorIsAdmin_ && (
+ <>
+ {!isBanned(post_view.creator) ? (
+ <li>{this.modBanButton}</li>
+ ) : (
+ <li>{this.modUnbanButton}</li>
+ )}
+ <li>{this.purgePersonButton}</li>
+ <li>{this.purgePostButton}</li>
+ </>
+ )}
+ {!isBanned(post_view.creator) && post_view.creator.local && (
+ <li>{this.toggleAdminButton}</li>
+ )}
+ </>
+ )}
</ul>
</div>
</>
get modBanFromCommunityButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleModBanFromCommunityShow)}
- aria-label={I18NextService.i18n.t("ban_from_community")}
>
{I18NextService.i18n.t("ban_from_community")}
</button>
get modUnbanFromCommunityButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleModBanFromCommunitySubmit)}
- aria-label={I18NextService.i18n.t("unban")}
>
{this.state.banLoading ? <Spinner /> : I18NextService.i18n.t("unban")}
</button>
get addModToCommunityButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleAddModToCommunity)}
- aria-label={
- this.creatorIsMod_
- ? I18NextService.i18n.t("remove_as_mod")
- : I18NextService.i18n.t("appoint_as_mod")
- }
>
{this.state.addModLoading ? (
<Spinner />
) : this.creatorIsMod_ ? (
- I18NextService.i18n.t("remove_as_mod")
+ capitalizeFirstLetter(I18NextService.i18n.t("remove_as_mod"))
) : (
- I18NextService.i18n.t("appoint_as_mod")
+ capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_mod"))
)}
</button>
);
get modBanButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleModBanShow)}
- aria-label={I18NextService.i18n.t("ban_from_site")}
>
- {I18NextService.i18n.t("ban_from_site")}
+ {capitalizeFirstLetter(I18NextService.i18n.t("ban_from_site"))}
</button>
);
}
get modUnbanButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleModBanSubmit)}
- aria-label={I18NextService.i18n.t("unban_from_site")}
>
{this.state.banLoading ? (
<Spinner />
) : (
- I18NextService.i18n.t("unban_from_site")
+ capitalizeFirstLetter(I18NextService.i18n.t("unban_from_site"))
)}
</button>
);
get purgePersonButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handlePurgePersonShow)}
- aria-label={I18NextService.i18n.t("purge_user")}
>
- {I18NextService.i18n.t("purge_user")}
+ {capitalizeFirstLetter(I18NextService.i18n.t("purge_user"))}
</button>
);
}
get purgePostButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handlePurgePostShow)}
- aria-label={I18NextService.i18n.t("purge_post")}
>
- {I18NextService.i18n.t("purge_post")}
+ {capitalizeFirstLetter(I18NextService.i18n.t("purge_post"))}
</button>
);
}
get toggleAdminButton() {
return (
<button
- className="btn btn-link btn-animate text-muted py-0"
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
onClick={linkEvent(this, this.handleAddAdmin)}
>
{this.state.addAdminLoading ? (
<Spinner />
) : this.creatorIsAdmin_ ? (
- I18NextService.i18n.t("remove_as_admin")
+ capitalizeFirstLetter(I18NextService.i18n.t("remove_as_admin"))
) : (
- I18NextService.i18n.t("appoint_as_admin")
+ capitalizeFirstLetter(I18NextService.i18n.t("appoint_as_admin"))
)}
</button>
);
}
+ get transferCommunityButton() {
+ return (
+ <button
+ className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
+ onClick={linkEvent(this, this.handleShowConfirmTransferCommunity)}
+ >
+ {capitalizeFirstLetter(I18NextService.i18n.t("transfer_community"))}
+ </button>
+ );
+ }
+
get modRemoveButton() {
const removed = this.postView.post.removed;
return (
{this.state.removeLoading ? (
<Spinner />
) : !removed ? (
- I18NextService.i18n.t("remove")
+ capitalizeFirstLetter(I18NextService.i18n.t("remove_post"))
) : (
- I18NextService.i18n.t("restore")
+ <>
+ {capitalizeFirstLetter(I18NextService.i18n.t("restore"))}{" "}
+ {I18NextService.i18n.t("post")}
+ </>
)}
</button>
);
}
- /**
- * Mod/Admin actions to be taken against the author.
- */
- userActionsLine() {
- // TODO: make nicer
- const post_view = this.postView;
- return (
- this.state.showAdvanced && (
- <div className="mt-3">
- {this.canMod_ && (
- <>
- {!this.creatorIsMod_ &&
- (!post_view.creator_banned_from_community
- ? this.modBanFromCommunityButton
- : this.modUnbanFromCommunityButton)}
- {!post_view.creator_banned_from_community &&
- this.addModToCommunityButton}
- </>
- )}
-
- {/* 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 ? (
- <button
- className="btn btn-link btn-animate text-muted py-0"
- onClick={linkEvent(
- this,
- this.handleShowConfirmTransferCommunity
- )}
- aria-label={I18NextService.i18n.t("transfer_community")}
- >
- {I18NextService.i18n.t("transfer_community")}
- </button>
- ) : (
- <>
- <button
- className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0"
- aria-label={I18NextService.i18n.t("are_you_sure")}
- >
- {I18NextService.i18n.t("are_you_sure")}
- </button>
- <button
- className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
- aria-label={I18NextService.i18n.t("yes")}
- onClick={linkEvent(this, this.handleTransferCommunity)}
- >
- {this.state.transferLoading ? (
- <Spinner />
- ) : (
- I18NextService.i18n.t("yes")
- )}
- </button>
- <button
- className="btn btn-link btn-animate text-muted py-0 d-inline-block"
- onClick={linkEvent(
- this,
- this.handleCancelShowConfirmTransferCommunity
- )}
- aria-label={I18NextService.i18n.t("no")}
- >
- {I18NextService.i18n.t("no")}
- </button>
- </>
- ))}
- {/* 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}
- </>
- )}
- </div>
- )
- );
- }
-
removeAndBanDialogs() {
const post = this.postView;
const purgeTypeText =
value={this.state.removeReason}
onInput={linkEvent(this, this.handleModRemoveReasonChange)}
/>
- <button
- type="submit"
- className="btn btn-secondary"
- aria-label={I18NextService.i18n.t("remove_post")}
- >
+ <button type="submit" className="btn btn-secondary">
{this.state.removeLoading ? (
<Spinner />
) : (
</button>
</form>
)}
+ {this.state.showConfirmTransferCommunity && (
+ <>
+ <button className="d-inline-block me-1 btn btn-link btn-animate text-muted py-0">
+ {I18NextService.i18n.t("are_you_sure")}
+ </button>
+ <button
+ className="btn btn-link btn-animate text-muted py-0 d-inline-block me-1"
+ onClick={linkEvent(this, this.handleTransferCommunity)}
+ >
+ {this.state.transferLoading ? (
+ <Spinner />
+ ) : (
+ I18NextService.i18n.t("yes")
+ )}
+ </button>
+ <button
+ className="btn btn-link btn-animate text-muted py-0 d-inline-block"
+ onClick={linkEvent(
+ this,
+ this.handleCancelShowConfirmTransferCommunity
+ )}
+ aria-label={I18NextService.i18n.t("no")}
+ >
+ {I18NextService.i18n.t("no")}
+ </button>
+ </>
+ )}
{this.state.showBanDialog && (
<form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
<div className="mb-3 row col-12">
{/* <input type="date" class="form-control me-2" placeholder={I18NextService.i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
{/* </div> */}
<div className="mb-3 row">
- <button
- type="submit"
- className="btn btn-secondary"
- aria-label={I18NextService.i18n.t("ban")}
- >
+ <button type="submit" className="btn btn-secondary">
{this.state.banLoading ? (
<Spinner />
) : (
value={this.state.reportReason}
onInput={linkEvent(this, this.handleReportReasonChange)}
/>
- <button
- type="submit"
- className="btn btn-secondary"
- aria-label={I18NextService.i18n.t("create_report")}
- >
+ <button type="submit" className="btn btn-secondary">
{this.state.reportLoading ? (
<Spinner />
) : (
{this.state.purgeLoading ? (
<Spinner />
) : (
- <button
- type="submit"
- className="btn btn-secondary"
- aria-label={purgeTypeText}
- >
+ <button type="submit" className="btn btn-secondary">
{this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
</button>
)}
);
}
- showBodyPreview() {
- const { body, id } = this.postView.post;
-
- return !this.showBody && body ? (
- <Link className="text-body mt-2 d-block" to={`/post/${id}`}>
- <div className="md-div mb-1 preview-lines">{body}</div>
- </Link>
- ) : (
- <></>
+ showPreviewButton() {
+ return (
+ <button
+ type="button"
+ className="btn btn-sm btn-link link-dark link-opacity-75 link-opacity-100-hover py-0 align-baseline"
+ onClick={linkEvent(this, this.handleShowBody)}
+ >
+ <Icon
+ icon={!this.state.showBody ? "plus-square" : "minus-square"}
+ classes="icon-inline"
+ />
+ </button>
);
}
{this.mobileThumbnail()}
{this.commentsLine(true)}
- {this.userActionsLine()}
{this.duplicatesLine()}
{this.removeAndBanDialogs()}
</div>
)}
<div className="col flex-grow-1">
<div className="row">
- <div className="col-sm-3 col-lg-2 pe-0 post-media">
+ <div className="col flex-grow-0 px-0">
<div className="">{this.thumbnail()}</div>
</div>
- <div className="col-12 col-sm-9 col-lg-10">
+ <div className="col flex-grow-1">
{this.postTitleLine()}
{this.createdLine()}
{this.commentsLine()}
{this.duplicatesLine()}
- {this.userActionsLine()}
{this.removeAndBanDialogs()}
</div>
</div>