]> Untitled Git - lemmy-ui.git/blob - src/shared/components/post/post-listing.tsx
feat(post): Move post domain beneath post title (#1363)
[lemmy-ui.git] / src / shared / components / post / post-listing.tsx
1 import classNames from "classnames";
2 import { Component, linkEvent } from "inferno";
3 import { Link } from "inferno-router";
4 import {
5   AddAdmin,
6   AddModToCommunity,
7   BanFromCommunity,
8   BanPerson,
9   BlockPerson,
10   CommunityModeratorView,
11   CreatePostLike,
12   CreatePostReport,
13   DeletePost,
14   EditPost,
15   FeaturePost,
16   Language,
17   LockPost,
18   PersonView,
19   PostView,
20   PurgePerson,
21   PurgePost,
22   RemovePost,
23   SavePost,
24   TransferCommunity,
25 } from "lemmy-js-client";
26 import { getExternalHost, getHttpBase } from "../../env";
27 import { i18n } from "../../i18next";
28 import { BanType, PostFormParams, PurgeType, VoteType } from "../../interfaces";
29 import { UserService } from "../../services";
30 import {
31   amAdmin,
32   amCommunityCreator,
33   amMod,
34   canAdmin,
35   canMod,
36   canShare,
37   futureDaysToUnixTime,
38   hostname,
39   isAdmin,
40   isBanned,
41   isImage,
42   isMod,
43   isVideo,
44   mdNoImages,
45   mdToHtml,
46   mdToHtmlInline,
47   myAuthRequired,
48   newVote,
49   numToSI,
50   relTags,
51   setupTippy,
52   share,
53   showScores,
54 } from "../../utils";
55 import { Icon, PurgeWarning, Spinner } from "../common/icon";
56 import { MomentTime } from "../common/moment-time";
57 import { PictrsImage } from "../common/pictrs-image";
58 import { CommunityLink } from "../community/community-link";
59 import { PersonListing } from "../person/person-listing";
60 import { MetadataCard } from "./metadata-card";
61 import { PostForm } from "./post-form";
62
63 interface PostListingState {
64   showEdit: boolean;
65   showRemoveDialog: boolean;
66   showPurgeDialog: boolean;
67   purgeReason?: string;
68   purgeType?: PurgeType;
69   purgeLoading: boolean;
70   removeReason?: string;
71   showBanDialog: boolean;
72   banReason?: string;
73   banExpireDays?: number;
74   banType?: BanType;
75   removeData?: boolean;
76   showConfirmTransferSite: boolean;
77   showConfirmTransferCommunity: boolean;
78   imageExpanded: boolean;
79   viewSource: boolean;
80   showAdvanced: boolean;
81   showMoreMobile: boolean;
82   showBody: boolean;
83   showReportDialog: boolean;
84   reportReason?: string;
85   upvoteLoading: boolean;
86   downvoteLoading: boolean;
87   reportLoading: boolean;
88   blockLoading: boolean;
89   lockLoading: boolean;
90   deleteLoading: boolean;
91   removeLoading: boolean;
92   saveLoading: boolean;
93   featureCommunityLoading: boolean;
94   featureLocalLoading: boolean;
95   banLoading: boolean;
96   addModLoading: boolean;
97   addAdminLoading: boolean;
98   transferLoading: boolean;
99 }
100
101 interface PostListingProps {
102   post_view: PostView;
103   crossPosts?: PostView[];
104   moderators?: CommunityModeratorView[];
105   admins?: PersonView[];
106   allLanguages: Language[];
107   siteLanguages: number[];
108   showCommunity?: boolean;
109   showBody?: boolean;
110   hideImage?: boolean;
111   enableDownvotes?: boolean;
112   enableNsfw?: boolean;
113   viewOnly?: boolean;
114   onPostEdit(form: EditPost): void;
115   onPostVote(form: CreatePostLike): void;
116   onPostReport(form: CreatePostReport): void;
117   onBlockPerson(form: BlockPerson): void;
118   onLockPost(form: LockPost): void;
119   onDeletePost(form: DeletePost): void;
120   onRemovePost(form: RemovePost): void;
121   onSavePost(form: SavePost): void;
122   onFeaturePost(form: FeaturePost): void;
123   onPurgePerson(form: PurgePerson): void;
124   onPurgePost(form: PurgePost): void;
125   onBanPersonFromCommunity(form: BanFromCommunity): void;
126   onBanPerson(form: BanPerson): void;
127   onAddModToCommunity(form: AddModToCommunity): void;
128   onAddAdmin(form: AddAdmin): void;
129   onTransferCommunity(form: TransferCommunity): void;
130 }
131
132 export class PostListing extends Component<PostListingProps, PostListingState> {
133   state: PostListingState = {
134     showEdit: false,
135     showRemoveDialog: false,
136     showPurgeDialog: false,
137     purgeType: PurgeType.Person,
138     showBanDialog: false,
139     banType: BanType.Community,
140     removeData: false,
141     showConfirmTransferSite: false,
142     showConfirmTransferCommunity: false,
143     imageExpanded: false,
144     viewSource: false,
145     showAdvanced: false,
146     showMoreMobile: false,
147     showBody: false,
148     showReportDialog: false,
149     upvoteLoading: false,
150     downvoteLoading: false,
151     purgeLoading: false,
152     reportLoading: false,
153     blockLoading: false,
154     lockLoading: false,
155     deleteLoading: false,
156     removeLoading: false,
157     saveLoading: false,
158     featureCommunityLoading: false,
159     featureLocalLoading: false,
160     banLoading: false,
161     addModLoading: false,
162     addAdminLoading: false,
163     transferLoading: false,
164   };
165
166   constructor(props: any, context: any) {
167     super(props, context);
168
169     this.handleEditPost = this.handleEditPost.bind(this);
170     this.handleEditCancel = this.handleEditCancel.bind(this);
171   }
172
173   componentWillReceiveProps(nextProps: PostListingProps) {
174     if (this.props !== nextProps) {
175       this.setState({
176         upvoteLoading: false,
177         downvoteLoading: false,
178         purgeLoading: false,
179         reportLoading: false,
180         blockLoading: false,
181         lockLoading: false,
182         deleteLoading: false,
183         removeLoading: false,
184         saveLoading: false,
185         featureCommunityLoading: false,
186         featureLocalLoading: false,
187         banLoading: false,
188         addModLoading: false,
189         addAdminLoading: false,
190         transferLoading: false,
191         imageExpanded: false,
192       });
193     }
194   }
195
196   get postView(): PostView {
197     return this.props.post_view;
198   }
199
200   render() {
201     const post = this.postView.post;
202
203     return (
204       <div className="post-listing mt-2">
205         {!this.state.showEdit ? (
206           <>
207             {this.listing()}
208             {this.state.imageExpanded && !this.props.hideImage && this.img}
209             {post.url && this.state.showBody && post.embed_title && (
210               <MetadataCard post={post} />
211             )}
212             {this.showBody && this.body()}
213           </>
214         ) : (
215           <PostForm
216             post_view={this.postView}
217             crossPosts={this.props.crossPosts}
218             onEdit={this.handleEditPost}
219             onCancel={this.handleEditCancel}
220             enableNsfw={this.props.enableNsfw}
221             enableDownvotes={this.props.enableDownvotes}
222             allLanguages={this.props.allLanguages}
223             siteLanguages={this.props.siteLanguages}
224           />
225         )}
226       </div>
227     );
228   }
229
230   body() {
231     const body = this.postView.post.body;
232     return body ? (
233       <article id="postContent" className="col-12 card my-2 p-2">
234         {this.state.viewSource ? (
235           <pre>{body}</pre>
236         ) : (
237           <div className="md-div" dangerouslySetInnerHTML={mdToHtml(body)} />
238         )}
239       </article>
240     ) : (
241       <></>
242     );
243   }
244
245   get img() {
246     return this.imageSrc ? (
247       <>
248         <div className="offset-sm-3 my-2 d-none d-sm-block">
249           <a href={this.imageSrc} className="d-inline-block">
250             <PictrsImage src={this.imageSrc} />
251           </a>
252         </div>
253         <div className="my-2 d-block d-sm-none">
254           <a
255             className="d-inline-block"
256             onClick={linkEvent(this, this.handleImageExpandClick)}
257           >
258             <PictrsImage src={this.imageSrc} />
259           </a>
260         </div>
261       </>
262     ) : (
263       <></>
264     );
265   }
266
267   imgThumb(src: string) {
268     const post_view = this.postView;
269     return (
270       <PictrsImage
271         src={src}
272         thumbnail
273         alt=""
274         nsfw={post_view.post.nsfw || post_view.community.nsfw}
275       />
276     );
277   }
278
279   get imageSrc(): string | undefined {
280     const post = this.postView.post;
281     const url = post.url;
282     const thumbnail = post.thumbnail_url;
283
284     if (url && isImage(url)) {
285       if (url.includes("pictrs")) {
286         return url;
287       } else if (thumbnail) {
288         return thumbnail;
289       } else {
290         return url;
291       }
292     } else if (thumbnail) {
293       return thumbnail;
294     } else {
295       return undefined;
296     }
297   }
298
299   thumbnail() {
300     const post = this.postView.post;
301     const url = post.url;
302     const thumbnail = post.thumbnail_url;
303
304     if (!this.props.hideImage && url && isImage(url) && this.imageSrc) {
305       return (
306         <a
307           href={this.imageSrc}
308           className="text-body d-inline-block position-relative mb-2"
309           data-tippy-content={i18n.t("expand_here")}
310           onClick={linkEvent(this, this.handleImageExpandClick)}
311           aria-label={i18n.t("expand_here")}
312         >
313           {this.imgThumb(this.imageSrc)}
314           <Icon icon="image" classes="mini-overlay" />
315         </a>
316       );
317     } else if (!this.props.hideImage && url && thumbnail && this.imageSrc) {
318       return (
319         <a
320           className="text-body d-inline-block position-relative mb-2"
321           href={url}
322           rel={relTags}
323           title={url}
324         >
325           {this.imgThumb(this.imageSrc)}
326           <Icon icon="external-link" classes="mini-overlay" />
327         </a>
328       );
329     } else if (url) {
330       if (!this.props.hideImage && isVideo(url)) {
331         return (
332           <div className="embed-responsive embed-responsive-16by9">
333             <video
334               playsInline
335               muted
336               loop
337               controls
338               className="embed-responsive-item"
339             >
340               <source src={url} type="video/mp4" />
341             </video>
342           </div>
343         );
344       } else {
345         return (
346           <a className="text-body" href={url} title={url} rel={relTags}>
347             <div className="thumbnail rounded bg-light d-flex justify-content-center">
348               <Icon icon="external-link" classes="d-flex align-items-center" />
349             </div>
350           </a>
351         );
352       }
353     } else {
354       return (
355         <Link
356           className="text-body"
357           to={`/post/${post.id}`}
358           title={i18n.t("comments")}
359         >
360           <div className="thumbnail rounded bg-light d-flex justify-content-center">
361             <Icon icon="message-square" classes="d-flex align-items-center" />
362           </div>
363         </Link>
364       );
365     }
366   }
367
368   createdLine() {
369     const post_view = this.postView;
370     return (
371       <ul className="list-inline mb-1 text-muted small mt-2">
372         <li className="list-inline-item">
373           <PersonListing person={post_view.creator} />
374
375           {this.creatorIsMod_ && (
376             <span className="mx-1 badge">{i18n.t("mod")}</span>
377           )}
378           {this.creatorIsAdmin_ && (
379             <span className="mx-1 badge">{i18n.t("admin")}</span>
380           )}
381           {post_view.creator.bot_account && (
382             <span className="mx-1 badge">
383               {i18n.t("bot_account").toLowerCase()}
384             </span>
385           )}
386           {this.props.showCommunity && (
387             <>
388               {" "}
389               {i18n.t("to")} <CommunityLink community={post_view.community} />
390             </>
391           )}
392         </li>
393         {post_view.post.language_id !== 0 && (
394           <span className="mx-1 badge">
395             {
396               this.props.allLanguages.find(
397                 lang => lang.id === post_view.post.language_id
398               )?.name
399             }
400           </span>
401         )}
402         <li className="list-inline-item">•</li>
403         <li className="list-inline-item">
404           <span>
405             <MomentTime
406               published={post_view.post.published}
407               updated={post_view.post.updated}
408             />
409           </span>
410         </li>
411       </ul>
412     );
413   }
414
415   voteBar() {
416     return (
417       <div className={`vote-bar col-1 pr-0 small text-center`}>
418         <button
419           className={`btn-animate btn btn-link p-0 ${
420             this.postView.my_vote == 1 ? "text-info" : "text-muted"
421           }`}
422           onClick={linkEvent(this, this.handleUpvote)}
423           data-tippy-content={i18n.t("upvote")}
424           aria-label={i18n.t("upvote")}
425           aria-pressed={this.postView.my_vote === 1}
426         >
427           {this.state.upvoteLoading ? (
428             <Spinner />
429           ) : (
430             <Icon icon="arrow-up1" classes="upvote" />
431           )}
432         </button>
433         {showScores() ? (
434           <div
435             className={`unselectable pointer font-weight-bold text-muted px-1 post-score`}
436             data-tippy-content={this.pointsTippy}
437           >
438             {numToSI(this.postView.counts.score)}
439           </div>
440         ) : (
441           <div className="p-1"></div>
442         )}
443         {this.props.enableDownvotes && (
444           <button
445             className={`btn-animate btn btn-link p-0 ${
446               this.postView.my_vote == -1 ? "text-danger" : "text-muted"
447             }`}
448             onClick={linkEvent(this, this.handleDownvote)}
449             data-tippy-content={i18n.t("downvote")}
450             aria-label={i18n.t("downvote")}
451             aria-pressed={this.postView.my_vote === -1}
452           >
453             {this.state.downvoteLoading ? (
454               <Spinner />
455             ) : (
456               <Icon icon="arrow-down1" classes="downvote" />
457             )}
458           </button>
459         )}
460       </div>
461     );
462   }
463
464   get postLink() {
465     const post = this.postView.post;
466     return (
467       <Link
468         className={`d-inline ${
469           !post.featured_community && !post.featured_local
470             ? "text-body"
471             : "text-primary"
472         }`}
473         to={`/post/${post.id}`}
474         title={i18n.t("comments")}
475       >
476         <span
477           className="d-inline"
478           dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
479         />
480       </Link>
481     );
482   }
483
484   postTitleLine() {
485     const post = this.postView.post;
486     const url = post.url;
487
488     return (
489       <>
490         <div className="post-title overflow-hidden">
491           <h5 className="d-inline">
492             {url && this.props.showBody ? (
493               <a
494                 className={
495                   !post.featured_community && !post.featured_local
496                     ? "text-body"
497                     : "text-primary"
498                 }
499                 href={url}
500                 title={url}
501                 rel={relTags}
502                 dangerouslySetInnerHTML={mdToHtmlInline(post.name)}
503               ></a>
504             ) : (
505               this.postLink
506             )}
507           </h5>
508           {(url && isImage(url)) ||
509             (post.thumbnail_url && (
510               <button
511                 className="btn btn-link text-monospace text-muted small d-inline-block"
512                 data-tippy-content={i18n.t("expand_here")}
513                 onClick={linkEvent(this, this.handleImageExpandClick)}
514               >
515                 <Icon
516                   icon={
517                     !this.state.imageExpanded ? "plus-square" : "minus-square"
518                   }
519                   classes="icon-inline"
520                 />
521               </button>
522             ))}
523           {post.removed && (
524             <small className="ml-2 badge text-bg-secondary">
525               {i18n.t("removed")}
526             </small>
527           )}
528           {post.deleted && (
529             <small
530               className="unselectable pointer ml-2 text-muted font-italic"
531               data-tippy-content={i18n.t("deleted")}
532             >
533               <Icon icon="trash" classes="icon-inline text-danger" />
534             </small>
535           )}
536           {post.locked && (
537             <small
538               className="unselectable pointer ml-2 text-muted font-italic"
539               data-tippy-content={i18n.t("locked")}
540             >
541               <Icon icon="lock" classes="icon-inline text-danger" />
542             </small>
543           )}
544           {post.featured_community && (
545             <small
546               className="unselectable pointer ml-2 text-muted font-italic"
547               data-tippy-content={i18n.t("featured")}
548             >
549               <Icon icon="pin" classes="icon-inline text-primary" />
550             </small>
551           )}
552           {post.featured_local && (
553             <small
554               className="unselectable pointer ml-2 text-muted font-italic"
555               data-tippy-content={i18n.t("featured")}
556             >
557               <Icon icon="pin" classes="icon-inline text-secondary" />
558             </small>
559           )}
560           {post.nsfw && (
561             <small className="ml-2 badge text-bg-danger">
562               {i18n.t("nsfw")}
563             </small>
564           )}
565         </div>
566         {url && this.urlLine()}
567       </>
568     );
569   }
570
571   urlLine() {
572     const post = this.postView.post;
573     const url = post.url;
574
575     return (
576       <p className="d-flex text-muted align-items-center gap-1 small m-0">
577         {url && !(hostname(url) === getExternalHost()) && (
578           <a
579             className="text-muted font-italic"
580             href={url}
581             title={url}
582             rel={relTags}
583           >
584             {hostname(url)}
585           </a>
586         )}
587       </p>
588     );
589   }
590
591   duplicatesLine() {
592     const dupes = this.props.crossPosts;
593     return dupes && dupes.length > 0 ? (
594       <ul className="list-inline mb-1 small text-muted">
595         <>
596           <li className="list-inline-item mr-2">{i18n.t("cross_posted_to")}</li>
597           {dupes.map(pv => (
598             <li key={pv.post.id} className="list-inline-item mr-2">
599               <Link to={`/post/${pv.post.id}`}>
600                 {pv.community.local
601                   ? pv.community.name
602                   : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
603               </Link>
604             </li>
605           ))}
606         </>
607       </ul>
608     ) : (
609       <></>
610     );
611   }
612
613   commentsLine(mobile = false) {
614     const post = this.postView.post;
615
616     return (
617       <div className="d-flex align-items-center justify-content-start flex-wrap text-muted font-weight-bold">
618         {this.commentsButton}
619         {canShare() && (
620           <button
621             className="btn btn-sm btn-link"
622             onClick={linkEvent(this, this.handleShare)}
623             type="button"
624           >
625             <Icon icon="share" inline />
626           </button>
627         )}
628         {!post.local && (
629           <a
630             className="btn btn-link btn-animate text-muted py-0"
631             title={i18n.t("link")}
632             href={post.ap_id}
633           >
634             <Icon icon="fedilink" inline />
635           </a>
636         )}
637         {mobile && !this.props.viewOnly && this.mobileVotes}
638         {UserService.Instance.myUserInfo &&
639           !this.props.viewOnly &&
640           this.postActions()}
641       </div>
642     );
643   }
644
645   get hasAdvancedButtons() {
646     return (
647       this.myPost ||
648       (this.showBody && this.postView.post.body) ||
649       amMod(this.props.moderators) ||
650       amAdmin() ||
651       this.canMod_ ||
652       this.canAdmin_
653     );
654   }
655
656   showPreviewButton() {
657     const post_view = this.postView;
658     const body = post_view.post.body;
659
660     return (
661       <button
662         className="btn btn-link btn-animate text-muted py-0"
663         data-tippy-content={body && mdNoImages.render(body)}
664         data-tippy-allowHtml={true}
665         onClick={linkEvent(this, this.handleShowBody)}
666       >
667         <Icon
668           icon="book-open"
669           classes={classNames("icon-inline mr-1", {
670             "text-success": this.state.showBody,
671           })}
672         />
673       </button>
674     );
675   }
676
677   postActions() {
678     // Possible enhancement: Priority+ pattern instead of just hard coding which get hidden behind the show more button.
679     // Possible enhancement: Make each button a component.
680     const post_view = this.postView;
681     const post = post_view.post;
682
683     return (
684       <>
685         {this.saveButton}
686         {this.crossPostButton}
687
688         {/**
689          * If there is a URL, or if the post has a body and we were told not to
690          * show the body, show the MetadataCard/body toggle.
691          */}
692         {(post.url || (post.body && !this.props.showBody)) &&
693           this.showPreviewButton()}
694
695         {this.showBody && post_view.post.body && this.viewSourceButton}
696
697         {this.hasAdvancedButtons && (
698           <div className="dropdown">
699             <button
700               className="btn btn-link btn-animate text-muted py-0 dropdown-toggle"
701               onClick={linkEvent(this, this.handleShowAdvanced)}
702               data-tippy-content={i18n.t("more")}
703               data-bs-toggle="dropdown"
704               aria-expanded="false"
705               aria-controls="advancedButtonsDropdown"
706               aria-label={i18n.t("more")}
707             >
708               <Icon icon="more-vertical" inline />
709             </button>
710
711             <ul className="dropdown-menu" id="advancedButtonsDropdown">
712               {!this.myPost ? (
713                 <>
714                   <li>{this.reportButton}</li>
715                   <li>{this.blockButton}</li>
716                 </>
717               ) : (
718                 <>
719                   <li>{this.editButton}</li>
720                   <li>{this.deleteButton}</li>
721                 </>
722               )}
723
724               {/* Any mod can do these, not limited to hierarchy*/}
725               {(amMod(this.props.moderators) || amAdmin()) && (
726                 <>
727                   <li>
728                     <hr className="dropdown-divider" />
729                   </li>
730                   <li>{this.lockButton}</li>
731                   {this.featureButtons}
732                 </>
733               )}
734
735               {(this.canMod_ || this.canAdmin_) && (
736                 <li>{this.modRemoveButton}</li>
737               )}
738             </ul>
739           </div>
740         )}
741       </>
742     );
743   }
744
745   get commentsButton() {
746     const post_view = this.postView;
747     return (
748       <Link
749         className="btn btn-link text-muted pl-0 text-muted"
750         title={i18n.t("number_of_comments", {
751           count: Number(post_view.counts.comments),
752           formattedCount: Number(post_view.counts.comments),
753         })}
754         to={`/post/${post_view.post.id}?scrollToComments=true`}
755       >
756         <Icon icon="message-square" classes="mr-1" inline />
757         <span className="mr-2">
758           {i18n.t("number_of_comments", {
759             count: Number(post_view.counts.comments),
760             formattedCount: numToSI(post_view.counts.comments),
761           })}
762         </span>
763         {this.unreadCount && (
764           <span className="small text-warning">
765             ({this.unreadCount} {i18n.t("new")})
766           </span>
767         )}
768       </Link>
769     );
770   }
771
772   get unreadCount(): number | undefined {
773     const pv = this.postView;
774     return pv.unread_comments == pv.counts.comments || pv.unread_comments == 0
775       ? undefined
776       : pv.unread_comments;
777   }
778
779   get mobileVotes() {
780     // TODO: make nicer
781     const tippy = showScores()
782       ? { "data-tippy-content": this.pointsTippy }
783       : {};
784     return (
785       <>
786         <div>
787           <button
788             className={`btn-animate btn py-0 px-1 ${
789               this.postView.my_vote === 1 ? "text-info" : "text-muted"
790             }`}
791             {...tippy}
792             onClick={linkEvent(this, this.handleUpvote)}
793             aria-label={i18n.t("upvote")}
794             aria-pressed={this.postView.my_vote === 1}
795           >
796             {this.state.upvoteLoading ? (
797               <Spinner />
798             ) : (
799               <>
800                 <Icon icon="arrow-up1" classes="icon-inline small" />
801                 {showScores() && (
802                   <span className="ml-2">
803                     {numToSI(this.postView.counts.upvotes)}
804                   </span>
805                 )}
806               </>
807             )}
808           </button>
809           {this.props.enableDownvotes && (
810             <button
811               className={`ml-2 btn-animate btn py-0 px-1 ${
812                 this.postView.my_vote === -1 ? "text-danger" : "text-muted"
813               }`}
814               onClick={linkEvent(this, this.handleDownvote)}
815               {...tippy}
816               aria-label={i18n.t("downvote")}
817               aria-pressed={this.postView.my_vote === -1}
818             >
819               {this.state.downvoteLoading ? (
820                 <Spinner />
821               ) : (
822                 <>
823                   <Icon icon="arrow-down1" classes="icon-inline small" />
824                   {showScores() && (
825                     <span
826                       className={classNames("ml-2", {
827                         invisible: this.postView.counts.downvotes === 0,
828                       })}
829                     >
830                       {numToSI(this.postView.counts.downvotes)}
831                     </span>
832                   )}
833                 </>
834               )}
835             </button>
836           )}
837         </div>
838       </>
839     );
840   }
841
842   get saveButton() {
843     const saved = this.postView.saved;
844     const label = saved ? i18n.t("unsave") : i18n.t("save");
845     return (
846       <button
847         className="btn btn-link btn-animate text-muted py-0"
848         onClick={linkEvent(this, this.handleSavePostClick)}
849         data-tippy-content={label}
850         aria-label={label}
851       >
852         {this.state.saveLoading ? (
853           <Spinner />
854         ) : (
855           <Icon
856             icon="star"
857             classes={classNames({ "text-warning": saved })}
858             inline
859           />
860         )}
861       </button>
862     );
863   }
864
865   get crossPostButton() {
866     return (
867       <Link
868         className="btn btn-link btn-animate text-muted py-0"
869         to={{
870           /* Empty string properties are required to satisfy type*/
871           pathname: "/create_post",
872           state: { ...this.crossPostParams },
873           hash: "",
874           key: "",
875           search: "",
876         }}
877         title={i18n.t("cross_post")}
878         data-tippy-content={i18n.t("cross_post")}
879         aria-label={i18n.t("cross_post")}
880       >
881         <Icon icon="copy" inline />
882       </Link>
883     );
884   }
885
886   get reportButton() {
887     return (
888       <button
889         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
890         onClick={linkEvent(this, this.handleShowReportDialog)}
891         aria-label={i18n.t("show_report_dialog")}
892       >
893         <Icon classes="mr-1" icon="flag" inline />
894         {i18n.t("create_report")}
895       </button>
896     );
897   }
898
899   get blockButton() {
900     return (
901       <button
902         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
903         onClick={linkEvent(this, this.handleBlockPersonClick)}
904         aria-label={i18n.t("block_user")}
905       >
906         {this.state.blockLoading ? (
907           <Spinner />
908         ) : (
909           <Icon classes="mr-1" icon="slash" inline />
910         )}
911         {i18n.t("block_user")}
912       </button>
913     );
914   }
915
916   get editButton() {
917     return (
918       <button
919         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
920         onClick={linkEvent(this, this.handleEditClick)}
921         aria-label={i18n.t("edit")}
922       >
923         <Icon classes="mr-1" icon="edit" inline />
924         {i18n.t("edit")}
925       </button>
926     );
927   }
928
929   get deleteButton() {
930     const deleted = this.postView.post.deleted;
931     const label = !deleted ? i18n.t("delete") : i18n.t("restore");
932     return (
933       <button
934         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
935         onClick={linkEvent(this, this.handleDeleteClick)}
936         aria-label={label}
937       >
938         {this.state.deleteLoading ? (
939           <Spinner />
940         ) : (
941           <>
942             <Icon
943               icon="trash"
944               classes={classNames("mr-1", { "text-danger": deleted })}
945               inline
946             />
947             {label}
948           </>
949         )}
950       </button>
951     );
952   }
953
954   get viewSourceButton() {
955     return (
956       <button
957         className="btn btn-link btn-animate text-muted py-0"
958         onClick={linkEvent(this, this.handleViewSource)}
959         data-tippy-content={i18n.t("view_source")}
960         aria-label={i18n.t("view_source")}
961       >
962         <Icon
963           icon="file-text"
964           classes={classNames({ "text-success": this.state.viewSource })}
965           inline
966         />
967       </button>
968     );
969   }
970
971   get lockButton() {
972     const locked = this.postView.post.locked;
973     const label = locked ? i18n.t("unlock") : i18n.t("lock");
974     return (
975       <button
976         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
977         onClick={linkEvent(this, this.handleModLock)}
978         aria-label={label}
979       >
980         {this.state.lockLoading ? (
981           <Spinner />
982         ) : (
983           <>
984             <Icon
985               icon="lock"
986               classes={classNames("mr-1", { "text-danger": locked })}
987               inline
988             />
989             {label}
990           </>
991         )}
992       </button>
993     );
994   }
995
996   get featureButtons() {
997     const featuredCommunity = this.postView.post.featured_community;
998     const labelCommunity = featuredCommunity
999       ? i18n.t("unfeature_from_community")
1000       : i18n.t("feature_in_community");
1001
1002     const featuredLocal = this.postView.post.featured_local;
1003     const labelLocal = featuredLocal
1004       ? i18n.t("unfeature_from_local")
1005       : i18n.t("feature_in_local");
1006     return (
1007       <>
1008         <li>
1009           <button
1010             className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1011             onClick={linkEvent(this, this.handleModFeaturePostCommunity)}
1012             data-tippy-content={labelCommunity}
1013             aria-label={labelCommunity}
1014           >
1015             {this.state.featureCommunityLoading ? (
1016               <Spinner />
1017             ) : (
1018               <>
1019                 <Icon
1020                   icon="pin"
1021                   classes={classNames("mr-1", {
1022                     "text-success": featuredCommunity,
1023                   })}
1024                   inline
1025                 />
1026                 {i18n.t("community")}
1027               </>
1028             )}
1029           </button>
1030         </li>
1031         <li>
1032           {amAdmin() && (
1033             <button
1034               className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1035               onClick={linkEvent(this, this.handleModFeaturePostLocal)}
1036               data-tippy-content={labelLocal}
1037               aria-label={labelLocal}
1038             >
1039               {this.state.featureLocalLoading ? (
1040                 <Spinner />
1041               ) : (
1042                 <>
1043                   <Icon
1044                     icon="pin"
1045                     classes={classNames("mr-1", {
1046                       "text-success": featuredLocal,
1047                     })}
1048                     inline
1049                   />
1050                   {i18n.t("local")}
1051                 </>
1052               )}
1053             </button>
1054           )}
1055         </li>
1056       </>
1057     );
1058   }
1059
1060   get modRemoveButton() {
1061     const removed = this.postView.post.removed;
1062     return (
1063       <button
1064         className="btn btn-link btn-sm d-flex align-items-center rounded-0 dropdown-item"
1065         onClick={linkEvent(
1066           this,
1067           !removed ? this.handleModRemoveShow : this.handleModRemoveSubmit
1068         )}
1069       >
1070         {/* TODO: Find an icon for this. */}
1071         {this.state.removeLoading ? (
1072           <Spinner />
1073         ) : !removed ? (
1074           i18n.t("remove")
1075         ) : (
1076           i18n.t("restore")
1077         )}
1078       </button>
1079     );
1080   }
1081
1082   /**
1083    * Mod/Admin actions to be taken against the author.
1084    */
1085   userActionsLine() {
1086     // TODO: make nicer
1087     const post_view = this.postView;
1088     return (
1089       this.state.showAdvanced && (
1090         <>
1091           {this.canMod_ && (
1092             <>
1093               {!this.creatorIsMod_ &&
1094                 (!post_view.creator_banned_from_community ? (
1095                   <button
1096                     className="btn btn-link btn-animate text-muted py-0"
1097                     onClick={linkEvent(
1098                       this,
1099                       this.handleModBanFromCommunityShow
1100                     )}
1101                     aria-label={i18n.t("ban_from_community")}
1102                   >
1103                     {i18n.t("ban_from_community")}
1104                   </button>
1105                 ) : (
1106                   <button
1107                     className="btn btn-link btn-animate text-muted py-0"
1108                     onClick={linkEvent(
1109                       this,
1110                       this.handleModBanFromCommunitySubmit
1111                     )}
1112                     aria-label={i18n.t("unban")}
1113                   >
1114                     {this.state.banLoading ? <Spinner /> : i18n.t("unban")}
1115                   </button>
1116                 ))}
1117               {!post_view.creator_banned_from_community && (
1118                 <button
1119                   className="btn btn-link btn-animate text-muted py-0"
1120                   onClick={linkEvent(this, this.handleAddModToCommunity)}
1121                   aria-label={
1122                     this.creatorIsMod_
1123                       ? i18n.t("remove_as_mod")
1124                       : i18n.t("appoint_as_mod")
1125                   }
1126                 >
1127                   {this.state.addModLoading ? (
1128                     <Spinner />
1129                   ) : this.creatorIsMod_ ? (
1130                     i18n.t("remove_as_mod")
1131                   ) : (
1132                     i18n.t("appoint_as_mod")
1133                   )}
1134                 </button>
1135               )}
1136             </>
1137           )}
1138           {/* Community creators and admins can transfer community to another mod */}
1139           {(amCommunityCreator(post_view.creator.id, this.props.moderators) ||
1140             this.canAdmin_) &&
1141             this.creatorIsMod_ &&
1142             (!this.state.showConfirmTransferCommunity ? (
1143               <button
1144                 className="btn btn-link btn-animate text-muted py-0"
1145                 onClick={linkEvent(
1146                   this,
1147                   this.handleShowConfirmTransferCommunity
1148                 )}
1149                 aria-label={i18n.t("transfer_community")}
1150               >
1151                 {i18n.t("transfer_community")}
1152               </button>
1153             ) : (
1154               <>
1155                 <button
1156                   className="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
1157                   aria-label={i18n.t("are_you_sure")}
1158                 >
1159                   {i18n.t("are_you_sure")}
1160                 </button>
1161                 <button
1162                   className="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
1163                   aria-label={i18n.t("yes")}
1164                   onClick={linkEvent(this, this.handleTransferCommunity)}
1165                 >
1166                   {this.state.transferLoading ? <Spinner /> : i18n.t("yes")}
1167                 </button>
1168                 <button
1169                   className="btn btn-link btn-animate text-muted py-0 d-inline-block"
1170                   onClick={linkEvent(
1171                     this,
1172                     this.handleCancelShowConfirmTransferCommunity
1173                   )}
1174                   aria-label={i18n.t("no")}
1175                 >
1176                   {i18n.t("no")}
1177                 </button>
1178               </>
1179             ))}
1180           {/* Admins can ban from all, and appoint other admins */}
1181           {this.canAdmin_ && (
1182             <>
1183               {!this.creatorIsAdmin_ && (
1184                 <>
1185                   {!isBanned(post_view.creator) ? (
1186                     <button
1187                       className="btn btn-link btn-animate text-muted py-0"
1188                       onClick={linkEvent(this, this.handleModBanShow)}
1189                       aria-label={i18n.t("ban_from_site")}
1190                     >
1191                       {i18n.t("ban_from_site")}
1192                     </button>
1193                   ) : (
1194                     <button
1195                       className="btn btn-link btn-animate text-muted py-0"
1196                       onClick={linkEvent(this, this.handleModBanSubmit)}
1197                       aria-label={i18n.t("unban_from_site")}
1198                     >
1199                       {this.state.banLoading ? (
1200                         <Spinner />
1201                       ) : (
1202                         i18n.t("unban_from_site")
1203                       )}
1204                     </button>
1205                   )}
1206                   <button
1207                     className="btn btn-link btn-animate text-muted py-0"
1208                     onClick={linkEvent(this, this.handlePurgePersonShow)}
1209                     aria-label={i18n.t("purge_user")}
1210                   >
1211                     {i18n.t("purge_user")}
1212                   </button>
1213                   <button
1214                     className="btn btn-link btn-animate text-muted py-0"
1215                     onClick={linkEvent(this, this.handlePurgePostShow)}
1216                     aria-label={i18n.t("purge_post")}
1217                   >
1218                     {i18n.t("purge_post")}
1219                   </button>
1220                 </>
1221               )}
1222               {!isBanned(post_view.creator) && post_view.creator.local && (
1223                 <button
1224                   className="btn btn-link btn-animate text-muted py-0"
1225                   onClick={linkEvent(this, this.handleAddAdmin)}
1226                   aria-label={
1227                     this.creatorIsAdmin_
1228                       ? i18n.t("remove_as_admin")
1229                       : i18n.t("appoint_as_admin")
1230                   }
1231                 >
1232                   {this.state.addAdminLoading ? (
1233                     <Spinner />
1234                   ) : this.creatorIsAdmin_ ? (
1235                     i18n.t("remove_as_admin")
1236                   ) : (
1237                     i18n.t("appoint_as_admin")
1238                   )}
1239                 </button>
1240               )}
1241             </>
1242           )}
1243         </>
1244       )
1245     );
1246   }
1247
1248   removeAndBanDialogs() {
1249     const post = this.postView;
1250     const purgeTypeText =
1251       this.state.purgeType == PurgeType.Post
1252         ? i18n.t("purge_post")
1253         : `${i18n.t("purge")} ${post.creator.name}`;
1254     return (
1255       <>
1256         {this.state.showRemoveDialog && (
1257           <form
1258             className="form-inline"
1259             onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
1260           >
1261             <label className="sr-only" htmlFor="post-listing-remove-reason">
1262               {i18n.t("reason")}
1263             </label>
1264             <input
1265               type="text"
1266               id="post-listing-remove-reason"
1267               className="form-control mr-2"
1268               placeholder={i18n.t("reason")}
1269               value={this.state.removeReason}
1270               onInput={linkEvent(this, this.handleModRemoveReasonChange)}
1271             />
1272             <button
1273               type="submit"
1274               className="btn btn-secondary"
1275               aria-label={i18n.t("remove_post")}
1276             >
1277               {this.state.removeLoading ? <Spinner /> : i18n.t("remove_post")}
1278             </button>
1279           </form>
1280         )}
1281         {this.state.showBanDialog && (
1282           <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
1283             <div className="form-group row col-12">
1284               <label
1285                 className="col-form-label"
1286                 htmlFor="post-listing-ban-reason"
1287               >
1288                 {i18n.t("reason")}
1289               </label>
1290               <input
1291                 type="text"
1292                 id="post-listing-ban-reason"
1293                 className="form-control mr-2"
1294                 placeholder={i18n.t("reason")}
1295                 value={this.state.banReason}
1296                 onInput={linkEvent(this, this.handleModBanReasonChange)}
1297               />
1298               <label className="col-form-label" htmlFor={`mod-ban-expires`}>
1299                 {i18n.t("expires")}
1300               </label>
1301               <input
1302                 type="number"
1303                 id={`mod-ban-expires`}
1304                 className="form-control mr-2"
1305                 placeholder={i18n.t("number_of_days")}
1306                 value={this.state.banExpireDays}
1307                 onInput={linkEvent(this, this.handleModBanExpireDaysChange)}
1308               />
1309               <div className="form-group">
1310                 <div className="form-check">
1311                   <input
1312                     className="form-check-input"
1313                     id="mod-ban-remove-data"
1314                     type="checkbox"
1315                     checked={this.state.removeData}
1316                     onChange={linkEvent(this, this.handleModRemoveDataChange)}
1317                   />
1318                   <label
1319                     className="form-check-label"
1320                     htmlFor="mod-ban-remove-data"
1321                     title={i18n.t("remove_content_more")}
1322                   >
1323                     {i18n.t("remove_content")}
1324                   </label>
1325                 </div>
1326               </div>
1327             </div>
1328             {/* TODO hold off on expires until later */}
1329             {/* <div class="form-group row"> */}
1330             {/*   <label class="col-form-label">Expires</label> */}
1331             {/*   <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
1332             {/* </div> */}
1333             <div className="form-group row">
1334               <button
1335                 type="submit"
1336                 className="btn btn-secondary"
1337                 aria-label={i18n.t("ban")}
1338               >
1339                 {this.state.banLoading ? (
1340                   <Spinner />
1341                 ) : (
1342                   <span>
1343                     {i18n.t("ban")} {post.creator.name}
1344                   </span>
1345                 )}
1346               </button>
1347             </div>
1348           </form>
1349         )}
1350         {this.state.showReportDialog && (
1351           <form
1352             className="form-inline"
1353             onSubmit={linkEvent(this, this.handleReportSubmit)}
1354           >
1355             <label className="sr-only" htmlFor="post-report-reason">
1356               {i18n.t("reason")}
1357             </label>
1358             <input
1359               type="text"
1360               id="post-report-reason"
1361               className="form-control mr-2"
1362               placeholder={i18n.t("reason")}
1363               required
1364               value={this.state.reportReason}
1365               onInput={linkEvent(this, this.handleReportReasonChange)}
1366             />
1367             <button
1368               type="submit"
1369               className="btn btn-secondary"
1370               aria-label={i18n.t("create_report")}
1371             >
1372               {this.state.reportLoading ? <Spinner /> : i18n.t("create_report")}
1373             </button>
1374           </form>
1375         )}
1376         {this.state.showPurgeDialog && (
1377           <form
1378             className="form-inline"
1379             onSubmit={linkEvent(this, this.handlePurgeSubmit)}
1380           >
1381             <PurgeWarning />
1382             <label className="sr-only" htmlFor="purge-reason">
1383               {i18n.t("reason")}
1384             </label>
1385             <input
1386               type="text"
1387               id="purge-reason"
1388               className="form-control mr-2"
1389               placeholder={i18n.t("reason")}
1390               value={this.state.purgeReason}
1391               onInput={linkEvent(this, this.handlePurgeReasonChange)}
1392             />
1393             {this.state.purgeLoading ? (
1394               <Spinner />
1395             ) : (
1396               <button
1397                 type="submit"
1398                 className="btn btn-secondary"
1399                 aria-label={purgeTypeText}
1400               >
1401                 {this.state.purgeLoading ? <Spinner /> : { purgeTypeText }}
1402               </button>
1403             )}
1404           </form>
1405         )}
1406       </>
1407     );
1408   }
1409
1410   mobileThumbnail() {
1411     const post = this.postView.post;
1412     return post.thumbnail_url || (post.url && isImage(post.url)) ? (
1413       <div className="row">
1414         <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1415           {this.postTitleLine()}
1416         </div>
1417         <div className="col-4">
1418           {/* Post body prev or thumbnail */}
1419           {!this.state.imageExpanded && this.thumbnail()}
1420         </div>
1421       </div>
1422     ) : (
1423       this.postTitleLine()
1424     );
1425   }
1426
1427   showMobilePreview() {
1428     const { body, id } = this.postView.post;
1429
1430     return !this.showBody && body ? (
1431       <Link className="text-body" to={`/post/${id}`}>
1432         <div className="md-div mb-1 preview-lines">{body}</div>
1433       </Link>
1434     ) : (
1435       <></>
1436     );
1437   }
1438
1439   listing() {
1440     return (
1441       <>
1442         {/* The mobile view*/}
1443         <div className="d-block d-sm-none">
1444           <article className="row post-container">
1445             <div className="col-12">
1446               {this.createdLine()}
1447
1448               {/* If it has a thumbnail, do a right aligned thumbnail */}
1449               {this.mobileThumbnail()}
1450
1451               {/* Show a preview of the post body */}
1452               {this.showMobilePreview()}
1453
1454               {this.commentsLine(true)}
1455               {this.userActionsLine()}
1456               {this.duplicatesLine()}
1457               {this.removeAndBanDialogs()}
1458             </div>
1459           </article>
1460         </div>
1461
1462         {/* The larger view*/}
1463         <div className="d-none d-sm-block">
1464           <article className="row post-container">
1465             {!this.props.viewOnly && this.voteBar()}
1466             <div className="col-sm-2 pr-0 post-media">
1467               <div className="">{this.thumbnail()}</div>
1468             </div>
1469             <div className="col-12 col-sm-9">
1470               <div className="row">
1471                 <div className="col-12">
1472                   {this.postTitleLine()}
1473                   {this.createdLine()}
1474                   {this.commentsLine()}
1475                   {this.duplicatesLine()}
1476                   {this.userActionsLine()}
1477                   {this.removeAndBanDialogs()}
1478                 </div>
1479               </div>
1480             </div>
1481           </article>
1482         </div>
1483       </>
1484     );
1485   }
1486
1487   private get myPost(): boolean {
1488     return (
1489       this.postView.creator.id ==
1490       UserService.Instance.myUserInfo?.local_user_view.person.id
1491     );
1492   }
1493   handleEditClick(i: PostListing) {
1494     i.setState({ showEdit: true });
1495   }
1496
1497   handleEditCancel() {
1498     this.setState({ showEdit: false });
1499   }
1500
1501   // The actual editing is done in the receive for post
1502   handleEditPost(form: EditPost) {
1503     this.setState({ showEdit: false });
1504     this.props.onPostEdit(form);
1505   }
1506
1507   handleShare(i: PostListing) {
1508     const { name, body, id } = i.props.post_view.post;
1509     share({
1510       title: name,
1511       text: body?.slice(0, 50),
1512       url: `${getHttpBase()}/post/${id}`,
1513     });
1514   }
1515
1516   handleShowReportDialog(i: PostListing) {
1517     i.setState({ showReportDialog: !i.state.showReportDialog });
1518   }
1519
1520   handleReportReasonChange(i: PostListing, event: any) {
1521     i.setState({ reportReason: event.target.value });
1522   }
1523
1524   handleReportSubmit(i: PostListing, event: any) {
1525     event.preventDefault();
1526     i.setState({ reportLoading: true });
1527     i.props.onPostReport({
1528       post_id: i.postView.post.id,
1529       reason: i.state.reportReason ?? "",
1530       auth: myAuthRequired(),
1531     });
1532   }
1533
1534   handleBlockPersonClick(i: PostListing) {
1535     i.setState({ blockLoading: true });
1536     i.props.onBlockPerson({
1537       person_id: i.postView.creator.id,
1538       block: true,
1539       auth: myAuthRequired(),
1540     });
1541   }
1542
1543   handleDeleteClick(i: PostListing) {
1544     i.setState({ deleteLoading: true });
1545     i.props.onDeletePost({
1546       post_id: i.postView.post.id,
1547       deleted: !i.postView.post.deleted,
1548       auth: myAuthRequired(),
1549     });
1550   }
1551
1552   handleSavePostClick(i: PostListing) {
1553     i.setState({ saveLoading: true });
1554     i.props.onSavePost({
1555       post_id: i.postView.post.id,
1556       save: !i.postView.saved,
1557       auth: myAuthRequired(),
1558     });
1559   }
1560
1561   get crossPostParams(): PostFormParams {
1562     const queryParams: PostFormParams = {};
1563     const { name, url } = this.postView.post;
1564
1565     queryParams.name = name;
1566
1567     if (url) {
1568       queryParams.url = url;
1569     }
1570
1571     const crossPostBody = this.crossPostBody();
1572     if (crossPostBody) {
1573       queryParams.body = crossPostBody;
1574     }
1575
1576     return queryParams;
1577   }
1578
1579   crossPostBody(): string | undefined {
1580     const post = this.postView.post;
1581     const body = post.body;
1582
1583     return body
1584       ? `${i18n.t("cross_posted_from")} ${post.ap_id}\n\n${body.replace(
1585           /^/gm,
1586           "> "
1587         )}`
1588       : undefined;
1589   }
1590
1591   get showBody(): boolean {
1592     return this.props.showBody || this.state.showBody;
1593   }
1594
1595   handleModRemoveShow(i: PostListing) {
1596     i.setState({
1597       showRemoveDialog: !i.state.showRemoveDialog,
1598       showBanDialog: false,
1599     });
1600   }
1601
1602   handleModRemoveReasonChange(i: PostListing, event: any) {
1603     i.setState({ removeReason: event.target.value });
1604   }
1605
1606   handleModRemoveDataChange(i: PostListing, event: any) {
1607     i.setState({ removeData: event.target.checked });
1608   }
1609
1610   handleModRemoveSubmit(i: PostListing, event: any) {
1611     event.preventDefault();
1612     i.setState({ removeLoading: true });
1613     i.props.onRemovePost({
1614       post_id: i.postView.post.id,
1615       removed: !i.postView.post.removed,
1616       auth: myAuthRequired(),
1617     });
1618   }
1619
1620   handleModLock(i: PostListing) {
1621     i.setState({ lockLoading: true });
1622     i.props.onLockPost({
1623       post_id: i.postView.post.id,
1624       locked: !i.postView.post.locked,
1625       auth: myAuthRequired(),
1626     });
1627   }
1628
1629   handleModFeaturePostLocal(i: PostListing) {
1630     i.setState({ featureLocalLoading: true });
1631     i.props.onFeaturePost({
1632       post_id: i.postView.post.id,
1633       featured: !i.postView.post.featured_local,
1634       feature_type: "Local",
1635       auth: myAuthRequired(),
1636     });
1637   }
1638
1639   handleModFeaturePostCommunity(i: PostListing) {
1640     i.setState({ featureCommunityLoading: true });
1641     i.props.onFeaturePost({
1642       post_id: i.postView.post.id,
1643       featured: !i.postView.post.featured_community,
1644       feature_type: "Community",
1645       auth: myAuthRequired(),
1646     });
1647   }
1648
1649   handleModBanFromCommunityShow(i: PostListing) {
1650     i.setState({
1651       showBanDialog: true,
1652       banType: BanType.Community,
1653       showRemoveDialog: false,
1654     });
1655   }
1656
1657   handleModBanShow(i: PostListing) {
1658     i.setState({
1659       showBanDialog: true,
1660       banType: BanType.Site,
1661       showRemoveDialog: false,
1662     });
1663   }
1664
1665   handlePurgePersonShow(i: PostListing) {
1666     i.setState({
1667       showPurgeDialog: true,
1668       purgeType: PurgeType.Person,
1669       showRemoveDialog: false,
1670     });
1671   }
1672
1673   handlePurgePostShow(i: PostListing) {
1674     i.setState({
1675       showPurgeDialog: true,
1676       purgeType: PurgeType.Post,
1677       showRemoveDialog: false,
1678     });
1679   }
1680
1681   handlePurgeReasonChange(i: PostListing, event: any) {
1682     i.setState({ purgeReason: event.target.value });
1683   }
1684
1685   handlePurgeSubmit(i: PostListing, event: any) {
1686     event.preventDefault();
1687     i.setState({ purgeLoading: true });
1688     if (i.state.purgeType == PurgeType.Person) {
1689       i.props.onPurgePerson({
1690         person_id: i.postView.creator.id,
1691         reason: i.state.purgeReason,
1692         auth: myAuthRequired(),
1693       });
1694     } else if (i.state.purgeType == PurgeType.Post) {
1695       i.props.onPurgePost({
1696         post_id: i.postView.post.id,
1697         reason: i.state.purgeReason,
1698         auth: myAuthRequired(),
1699       });
1700     }
1701   }
1702
1703   handleModBanReasonChange(i: PostListing, event: any) {
1704     i.setState({ banReason: event.target.value });
1705   }
1706
1707   handleModBanExpireDaysChange(i: PostListing, event: any) {
1708     i.setState({ banExpireDays: event.target.value });
1709   }
1710
1711   handleModBanFromCommunitySubmit(i: PostListing, event: any) {
1712     i.setState({ banType: BanType.Community });
1713     i.handleModBanBothSubmit(i, event);
1714   }
1715
1716   handleModBanSubmit(i: PostListing, event: any) {
1717     i.setState({ banType: BanType.Site });
1718     i.handleModBanBothSubmit(i, event);
1719   }
1720
1721   handleModBanBothSubmit(i: PostListing, event: any) {
1722     event.preventDefault();
1723     i.setState({ banLoading: true });
1724
1725     const ban = !i.props.post_view.creator_banned_from_community;
1726     // If its an unban, restore all their data
1727     if (ban == false) {
1728       i.setState({ removeData: false });
1729     }
1730     const person_id = i.props.post_view.creator.id;
1731     const remove_data = i.state.removeData;
1732     const reason = i.state.banReason;
1733     const expires = futureDaysToUnixTime(i.state.banExpireDays);
1734
1735     if (i.state.banType == BanType.Community) {
1736       const community_id = i.postView.community.id;
1737       i.props.onBanPersonFromCommunity({
1738         community_id,
1739         person_id,
1740         ban,
1741         remove_data,
1742         reason,
1743         expires,
1744         auth: myAuthRequired(),
1745       });
1746     } else {
1747       i.props.onBanPerson({
1748         person_id,
1749         ban,
1750         remove_data,
1751         reason,
1752         expires,
1753         auth: myAuthRequired(),
1754       });
1755     }
1756   }
1757
1758   handleAddModToCommunity(i: PostListing) {
1759     i.setState({ addModLoading: true });
1760     i.props.onAddModToCommunity({
1761       community_id: i.postView.community.id,
1762       person_id: i.postView.creator.id,
1763       added: !i.creatorIsMod_,
1764       auth: myAuthRequired(),
1765     });
1766   }
1767
1768   handleAddAdmin(i: PostListing) {
1769     i.setState({ addAdminLoading: true });
1770     i.props.onAddAdmin({
1771       person_id: i.postView.creator.id,
1772       added: !i.creatorIsAdmin_,
1773       auth: myAuthRequired(),
1774     });
1775   }
1776
1777   handleShowConfirmTransferCommunity(i: PostListing) {
1778     i.setState({ showConfirmTransferCommunity: true });
1779   }
1780
1781   handleCancelShowConfirmTransferCommunity(i: PostListing) {
1782     i.setState({ showConfirmTransferCommunity: false });
1783   }
1784
1785   handleTransferCommunity(i: PostListing) {
1786     i.setState({ transferLoading: true });
1787     i.props.onTransferCommunity({
1788       community_id: i.postView.community.id,
1789       person_id: i.postView.creator.id,
1790       auth: myAuthRequired(),
1791     });
1792   }
1793
1794   handleShowConfirmTransferSite(i: PostListing) {
1795     i.setState({ showConfirmTransferSite: true });
1796   }
1797
1798   handleCancelShowConfirmTransferSite(i: PostListing) {
1799     i.setState({ showConfirmTransferSite: false });
1800   }
1801
1802   handleImageExpandClick(i: PostListing, event: any) {
1803     event.preventDefault();
1804     i.setState({ imageExpanded: !i.state.imageExpanded });
1805     setupTippy();
1806   }
1807
1808   handleViewSource(i: PostListing) {
1809     i.setState({ viewSource: !i.state.viewSource });
1810   }
1811
1812   handleShowAdvanced(i: PostListing) {
1813     i.setState({ showAdvanced: !i.state.showAdvanced });
1814     setupTippy();
1815   }
1816
1817   handleShowMoreMobile(i: PostListing) {
1818     i.setState({
1819       showMoreMobile: !i.state.showMoreMobile,
1820       showAdvanced: !i.state.showAdvanced,
1821     });
1822     setupTippy();
1823   }
1824
1825   handleShowBody(i: PostListing) {
1826     i.setState({ showBody: !i.state.showBody });
1827     setupTippy();
1828   }
1829
1830   handleUpvote(i: PostListing) {
1831     i.setState({ upvoteLoading: true });
1832     i.props.onPostVote({
1833       post_id: i.postView.post.id,
1834       score: newVote(VoteType.Upvote, i.props.post_view.my_vote),
1835       auth: myAuthRequired(),
1836     });
1837   }
1838
1839   handleDownvote(i: PostListing) {
1840     i.setState({ downvoteLoading: true });
1841     i.props.onPostVote({
1842       post_id: i.postView.post.id,
1843       score: newVote(VoteType.Downvote, i.props.post_view.my_vote),
1844       auth: myAuthRequired(),
1845     });
1846   }
1847
1848   get pointsTippy(): string {
1849     const points = i18n.t("number_of_points", {
1850       count: Number(this.postView.counts.score),
1851       formattedCount: Number(this.postView.counts.score),
1852     });
1853
1854     const upvotes = i18n.t("number_of_upvotes", {
1855       count: Number(this.postView.counts.upvotes),
1856       formattedCount: Number(this.postView.counts.upvotes),
1857     });
1858
1859     const downvotes = i18n.t("number_of_downvotes", {
1860       count: Number(this.postView.counts.downvotes),
1861       formattedCount: Number(this.postView.counts.downvotes),
1862     });
1863
1864     return `${points} • ${upvotes} • ${downvotes}`;
1865   }
1866
1867   get canModOnSelf_(): boolean {
1868     return canMod(
1869       this.postView.creator.id,
1870       this.props.moderators,
1871       this.props.admins,
1872       undefined,
1873       true
1874     );
1875   }
1876
1877   get canMod_(): boolean {
1878     return canMod(
1879       this.postView.creator.id,
1880       this.props.moderators,
1881       this.props.admins
1882     );
1883   }
1884
1885   get canAdmin_(): boolean {
1886     return canAdmin(this.postView.creator.id, this.props.admins);
1887   }
1888
1889   get creatorIsMod_(): boolean {
1890     return isMod(this.postView.creator.id, this.props.moderators);
1891   }
1892
1893   get creatorIsAdmin_(): boolean {
1894     return isAdmin(this.postView.creator.id, this.props.admins);
1895   }
1896 }