]> Untitled Git - lemmy-ui.git/blobdiff - src/shared/components/post/post-listing.tsx
Merge remote-tracking branch 'lemmy/main' into fix/fix-long-words-in-titles-overflow
[lemmy-ui.git] / src / shared / components / post / post-listing.tsx
index 64b9a7a8a68880c7126a520deac0a1b24cf1e9ed..5dcff2fce1407ddb4a8e4f0673ca2ac990283e58 100644 (file)
@@ -1,4 +1,4 @@
-import { getRoleLabelPill, myAuthRequired } from "@utils/app";
+import { myAuthRequired } from "@utils/app";
 import { canShare, share } from "@utils/browser";
 import { getExternalHost, getHttpBase } from "@utils/env";
 import {
@@ -55,6 +55,7 @@ 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";
@@ -331,27 +332,33 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
 
     if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
       return (
-        <a
-          href={this.imageSrc}
-          className="text-body d-inline-block position-relative mb-2"
+        <button
+          type="button"
+          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")}
         >
           {this.imgThumb(this.imageSrc)}
-          <Icon icon="image" classes="mini-overlay" />
-        </a>
+          <Icon
+            icon="image"
+            classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
+          />
+        </button>
       );
     } 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}
         >
           {this.imgThumb(this.imageSrc)}
-          <Icon icon="external-link" classes="mini-overlay" />
+          <Icon
+            icon="external-link"
+            classes="d-block text-white position-absolute end-0 top-0 mini-overlay text-opacity-75 text-opacity-100-hover"
+          />
         </a>
       );
     } else if (url) {
@@ -397,28 +404,16 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
 
   createdLine() {
     const post_view = this.postView;
+
     return (
-      <div className="small">
-        <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 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"),
-          })}
+      <div className="small mb-1 mb-md-0">
+        <PersonListing person={post_view.creator} />
+        <UserBadges
+          classNames="ms-1"
+          isMod={this.creatorIsMod_}
+          isAdmin={this.creatorIsAdmin_}
+          isBot={post_view.creator.bot_account}
+        />
         {this.props.showCommunity && (
           <>
             {" "}
@@ -470,8 +465,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
 
     return (
       <>
-        <div className="post-title overflow-hidden">
-          <h5 className="d-inline">
+        <div className="post-title">
+          <h1 className="h5 d-inline text-break">
             {url && this.props.showBody ? (
               <a
                 className={
@@ -487,15 +482,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             ) : (
               this.postLink
             )}
-          </h5>
+          </h1>
 
           {/**
-           * If there is a URL, an embed title, and we were not told to show the
-           * body by the parent component, 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.
            */}
           {!this.props.showBody &&
-            post.url &&
-            post.embed_title &&
+            ((post.url && post.embed_title) || post.body) &&
             this.showPreviewButton()}
 
           {post.removed && (
@@ -696,6 +691,50 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             {(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>
       </>
@@ -963,9 +1002,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
@@ -975,9 +1013,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
@@ -987,20 +1024,15 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
     );
@@ -1009,11 +1041,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
     );
   }
@@ -1021,14 +1052,13 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
     );
@@ -1037,11 +1067,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
     );
   }
@@ -1049,11 +1078,10 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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>
     );
   }
@@ -1061,20 +1089,31 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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 (
@@ -1089,102 +1128,17 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
         {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 =
@@ -1212,11 +1166,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
               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 />
               ) : (
@@ -1225,6 +1175,33 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             </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">
@@ -1278,11 +1255,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             {/*   <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 />
                 ) : (
@@ -1311,11 +1284,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
               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 />
               ) : (
@@ -1344,11 +1313,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             {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>
             )}
@@ -1403,7 +1368,6 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
               {this.mobileThumbnail()}
 
               {this.commentsLine(true)}
-              {this.userActionsLine()}
               {this.duplicatesLine()}
               {this.removeAndBanDialogs()}
             </div>
@@ -1427,15 +1391,14 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
             )}
             <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>
@@ -1452,6 +1415,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
       UserService.Instance.myUserInfo?.local_user_view.person.id
     );
   }
+
   handleEditClick(i: PostListing) {
     i.setState({ showEdit: true });
   }
@@ -1575,6 +1539,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
       post_id: i.postView.post.id,
       removed: !i.postView.post.removed,
       auth: myAuthRequired(),
+      reason: i.state.removeReason,
     });
   }
 
@@ -1646,13 +1611,13 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   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,