]> Untitled Git - lemmy.git/blobdiff - ui/src/components/post-listing.tsx
routes.api: fix get_captcha endpoint (#1135)
[lemmy.git] / ui / src / components / post-listing.tsx
index f4ea0e56ea24b7e7d57d114bc361c2c0b937660c..fa4bf391177359df89f823244b21e72c6a925c5e 100644 (file)
@@ -11,14 +11,14 @@ import {
   SavePostForm,
   CommunityUser,
   UserView,
-  BanType,
   BanFromCommunityForm,
   BanUserForm,
   AddModToCommunityForm,
   AddAdminForm,
   TransferSiteForm,
   TransferCommunityForm,
-} from '../interfaces';
+} from 'lemmy-js-client';
+import { BanType } from '../interfaces';
 import { MomentTime } from './moment-time';
 import { PostForm } from './post-form';
 import { IFramelyCard } from './iframely-card';
@@ -44,6 +44,7 @@ interface PostListingState {
   showRemoveDialog: boolean;
   removeReason: string;
   showBanDialog: boolean;
+  removeData: boolean;
   banReason: string;
   banExpires: string;
   banType: BanType;
@@ -74,6 +75,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     showRemoveDialog: false,
     removeReason: null,
     showBanDialog: false,
+    removeData: null,
     banReason: null,
     banExpires: null,
     banType: BanType.Community,
@@ -191,7 +193,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     if (isImage(post.url)) {
       return (
         <div
-          class="text-body pointer d-inline-block position-relative"
+          class="float-right text-body pointer d-inline-block position-relative"
           data-tippy-content={i18n.t('expand_here')}
           onClick={linkEvent(this, this.handleImageExpandClick)}
         >
@@ -204,7 +206,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     } else if (post.thumbnail_url) {
       return (
         <a
-          class="text-body d-inline-block position-relative"
+          class="float-right text-body d-inline-block position-relative"
           href={post.url}
           target="_blank"
           rel="noopener"
@@ -515,9 +517,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
         </li>
         {(showVotes || this.state.upvotes !== this.state.score) && (
           <>
-            <li className="list-inline-item">•</li>
             <span
-              class="unselectable pointer mr-2"
+              class="unselectable pointer ml-3"
               data-tippy-content={this.pointsTippy}
             >
               <li className="list-inline-item">
@@ -527,8 +528,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                   }`}
                   onClick={linkEvent(this, this.handlePostLike)}
                 >
-                  <svg class="small icon icon-inline mr-1">
-                    <use xlinkHref="#icon-arrow-up"></use>
+                  <svg class="small icon icon-inline mx-1">
+                    <use xlinkHref="#icon-arrow-up1"></use>
                   </svg>
                   {this.state.upvotes}
                 </a>
@@ -540,8 +541,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                   }`}
                   onClick={linkEvent(this, this.handlePostDisLike)}
                 >
-                  <svg class="small icon icon-inline mr-1">
-                    <use xlinkHref="#icon-arrow-down"></use>
+                  <svg class="small icon icon-inline mx-1">
+                    <use xlinkHref="#icon-arrow-down1"></use>
                   </svg>
                   {this.state.downvotes}
                 </a>
@@ -757,7 +758,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                         )}
                       </li>
                     )}
-                    {!post.banned_from_community && (
+                    {!post.banned_from_community && post.creator_local && (
                       <li className="list-inline-item">
                         <span
                           class="pointer"
@@ -775,45 +776,47 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                   </>
                 )}
                 {/* Community creators and admins can transfer community to another mod */}
-                {(this.amCommunityCreator || this.canAdmin) && this.isMod && (
-                  <li className="list-inline-item">
-                    {!this.state.showConfirmTransferCommunity ? (
-                      <span
-                        class="pointer"
-                        onClick={linkEvent(
-                          this,
-                          this.handleShowConfirmTransferCommunity
-                        )}
-                      >
-                        {i18n.t('transfer_community')}
-                      </span>
-                    ) : (
-                      <>
-                        <span class="d-inline-block mr-1">
-                          {i18n.t('are_you_sure')}
-                        </span>
-                        <span
-                          class="pointer d-inline-block mr-1"
-                          onClick={linkEvent(
-                            this,
-                            this.handleTransferCommunity
-                          )}
-                        >
-                          {i18n.t('yes')}
-                        </span>
+                {(this.amCommunityCreator || this.canAdmin) &&
+                  this.isMod &&
+                  post.creator_local && (
+                    <li className="list-inline-item">
+                      {!this.state.showConfirmTransferCommunity ? (
                         <span
-                          class="pointer d-inline-block"
+                          class="pointer"
                           onClick={linkEvent(
                             this,
-                            this.handleCancelShowConfirmTransferCommunity
+                            this.handleShowConfirmTransferCommunity
                           )}
                         >
-                          {i18n.t('no')}
+                          {i18n.t('transfer_community')}
                         </span>
-                      </>
-                    )}
-                  </li>
-                )}
+                      ) : (
+                        <>
+                          <span class="d-inline-block mr-1">
+                            {i18n.t('are_you_sure')}
+                          </span>
+                          <span
+                            class="pointer d-inline-block mr-1"
+                            onClick={linkEvent(
+                              this,
+                              this.handleTransferCommunity
+                            )}
+                          >
+                            {i18n.t('yes')}
+                          </span>
+                          <span
+                            class="pointer d-inline-block"
+                            onClick={linkEvent(
+                              this,
+                              this.handleCancelShowConfirmTransferCommunity
+                            )}
+                          >
+                            {i18n.t('no')}
+                          </span>
+                        </>
+                      )}
+                    </li>
+                  )}
                 {/* Admins can ban from all, and appoint other admins */}
                 {this.canAdmin && (
                   <>
@@ -836,7 +839,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                         )}
                       </li>
                     )}
-                    {!post.banned && (
+                    {!post.banned && post.creator_local && (
                       <li className="list-inline-item">
                         <span
                           class="pointer"
@@ -930,6 +933,20 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
                 value={this.state.banReason}
                 onInput={linkEvent(this, this.handleModBanReasonChange)}
               />
+              <div class="form-group">
+                <div class="form-check">
+                  <input
+                    class="form-check-input"
+                    id="mod-ban-remove-data"
+                    type="checkbox"
+                    checked={this.state.removeData}
+                    onChange={linkEvent(this, this.handleModRemoveDataChange)}
+                  />
+                  <label class="form-check-label" htmlFor="mod-ban-remove-data">
+                    {i18n.t('remove_posts_comments')}
+                  </label>
+                </div>
+              </div>
             </div>
             {/* TODO hold off on expires until later */}
             {/* <div class="form-group row"> */}
@@ -950,7 +967,9 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
   mobileThumbnail() {
     return this.props.post.thumbnail_url || isImage(this.props.post.url) ? (
       <div class="row">
-        <div class="col-8">{this.postTitleLine()}</div>
+        <div className={`${this.state.imageExpanded ? 'col-12' : 'col-8'}`}>
+          {this.postTitleLine()}
+        </div>
         <div class="col-4">
           {/* Post body prev or thumbnail */}
           {!this.state.imageExpanded && this.thumbnail()}
@@ -1220,7 +1239,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     let post = this.props.post;
 
     if (post.url) {
-      params += `&url=${post.url}`;
+      params += `&url=${encodeURIComponent(post.url)}`;
     }
     if (this.props.post.body) {
       params += `&body=${this.props.post.body}`;
@@ -1238,6 +1257,11 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     i.setState(i.state);
   }
 
+  handleModRemoveDataChange(i: PostListing, event: any) {
+    i.state.removeData = event.target.checked;
+    i.setState(i.state);
+  }
+
   handleModRemoveSubmit(i: PostListing) {
     event.preventDefault();
     let form: RemovePostForm = {
@@ -1308,18 +1332,30 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
     event.preventDefault();
 
     if (i.state.banType == BanType.Community) {
+      // If its an unban, restore all their data
+      let ban = !i.props.post.banned_from_community;
+      if (ban == false) {
+        i.state.removeData = false;
+      }
       let form: BanFromCommunityForm = {
         user_id: i.props.post.creator_id,
         community_id: i.props.post.community_id,
-        ban: !i.props.post.banned_from_community,
+        ban,
+        remove_data: i.state.removeData,
         reason: i.state.banReason,
         expires: getUnixTime(i.state.banExpires),
       };
       WebSocketService.Instance.banFromCommunity(form);
     } else {
+      // If its an unban, restore all their data
+      let ban = !i.props.post.banned;
+      if (ban == false) {
+        i.state.removeData = false;
+      }
       let form: BanUserForm = {
         user_id: i.props.post.creator_id,
-        ban: !i.props.post.banned,
+        ban,
+        remove_data: i.state.removeData,
         reason: i.state.banReason,
         expires: getUnixTime(i.state.banExpires),
       };