1 import { Component, linkEvent } from "inferno";
2 import { Link } from "inferno-router";
3 import { WebSocketService, UserService } from "../services";
19 CommunityModeratorView,
20 } from "lemmy-js-client";
21 import { BanType } from "../interfaces";
22 import { MomentTime } from "./moment-time";
23 import { PostForm } from "./post-form";
24 import { IFramelyCard } from "./iframely-card";
25 import { PersonListing } from "./person-listing";
26 import { CommunityLink } from "./community-link";
27 import { PictrsImage } from "./pictrs-image";
28 import { Icon } from "./icon";
43 import { i18n } from "../i18next";
44 import { externalHost } from "../env";
46 interface PostListingState {
48 showRemoveDialog: boolean;
50 showBanDialog: boolean;
55 showConfirmTransferSite: boolean;
56 showConfirmTransferCommunity: boolean;
57 imageExpanded: boolean;
59 showAdvanced: boolean;
60 showMoreMobile: boolean;
67 interface PostListingProps {
69 duplicates?: PostView[];
70 showCommunity?: boolean;
72 moderators?: CommunityModeratorView[];
73 admins?: PersonViewSafe[];
74 enableDownvotes: boolean;
78 export class PostListing extends Component<PostListingProps, PostListingState> {
79 private emptyState: PostListingState = {
81 showRemoveDialog: false,
87 banType: BanType.Community,
88 showConfirmTransferSite: false,
89 showConfirmTransferCommunity: false,
93 showMoreMobile: false,
94 my_vote: this.props.post_view.my_vote,
95 score: this.props.post_view.counts.score,
96 upvotes: this.props.post_view.counts.upvotes,
97 downvotes: this.props.post_view.counts.downvotes,
100 constructor(props: any, context: any) {
101 super(props, context);
103 this.state = this.emptyState;
104 this.handlePostLike = this.handlePostLike.bind(this);
105 this.handlePostDisLike = this.handlePostDisLike.bind(this);
106 this.handleEditPost = this.handleEditPost.bind(this);
107 this.handleEditCancel = this.handleEditCancel.bind(this);
110 componentWillReceiveProps(nextProps: PostListingProps) {
111 this.state.my_vote = nextProps.post_view.my_vote;
112 this.state.upvotes = nextProps.post_view.counts.upvotes;
113 this.state.downvotes = nextProps.post_view.counts.downvotes;
114 this.state.score = nextProps.post_view.counts.score;
115 if (this.props.post_view.post.id !== nextProps.post_view.post.id) {
116 this.state.imageExpanded = false;
118 this.setState(this.state);
124 {!this.state.showEdit ? (
132 post_view={this.props.post_view}
133 onEdit={this.handleEditPost}
134 onCancel={this.handleEditCancel}
135 enableNsfw={this.props.enableNsfw}
136 enableDownvotes={this.props.enableDownvotes}
145 let post = this.props.post_view.post;
149 {post.url && this.props.showBody && post.embed_title && (
150 <IFramelyCard post={post} />
152 {this.props.showBody &&
154 (this.state.viewSource ? (
155 <pre>{post.body}</pre>
159 dangerouslySetInnerHTML={mdToHtml(post.body)}
167 imgThumb(src: string) {
168 let post_view = this.props.post_view;
174 nsfw={post_view.post.nsfw || post_view.community.nsfw}
179 getImageSrc(): string {
180 let post = this.props.post_view.post;
181 if (isImage(post.url)) {
182 if (post.url.includes("pictrs")) {
184 } else if (post.thumbnail_url) {
185 return post.thumbnail_url;
189 } else if (post.thumbnail_url) {
190 return post.thumbnail_url;
197 let post = this.props.post_view.post;
199 if (isImage(post.url)) {
202 class="float-right text-body pointer d-inline-block position-relative mb-2"
203 data-tippy-content={i18n.t("expand_here")}
204 onClick={linkEvent(this, this.handleImageExpandClick)}
206 aria-label={i18n.t("expand_here")}
208 {this.imgThumb(this.getImageSrc())}
209 <Icon icon="image" classes="mini-overlay" />
212 } else if (post.thumbnail_url) {
215 class="float-right text-body d-inline-block position-relative mb-2"
220 {this.imgThumb(this.getImageSrc())}
221 <Icon icon="external-link" classes="mini-overlay" />
224 } else if (post.url) {
225 if (isVideo(post.url)) {
227 <div class="embed-responsive embed-responsive-16by9">
233 class="embed-responsive-item"
235 <source src={post.url} type="video/mp4" />
242 className="text-body"
247 <div class="thumbnail rounded bg-light d-flex justify-content-center">
248 <Icon icon="external-link" classes="d-flex align-items-center" />
256 className="text-body"
257 to={`/post/${post.id}`}
258 title={i18n.t("comments")}
260 <div class="thumbnail rounded bg-light d-flex justify-content-center">
261 <Icon icon="message-square" classes="d-flex align-items-center" />
269 let post_view = this.props.post_view;
271 <ul class="list-inline mb-1 text-muted small">
272 <li className="list-inline-item">
273 <PersonListing person={post_view.creator} />
276 <span className="mx-1 badge badge-light">{i18n.t("mod")}</span>
279 <span className="mx-1 badge badge-light">{i18n.t("admin")}</span>
281 {(post_view.creator_banned_from_community ||
282 post_view.creator.banned) && (
283 <span className="mx-1 badge badge-danger">{i18n.t("banned")}</span>
285 {this.props.showCommunity && (
287 <span class="mx-1"> {i18n.t("to")} </span>
288 <CommunityLink community={post_view.community} />
292 <li className="list-inline-item">•</li>
293 {post_view.post.url && !(hostname(post_view.post.url) == externalHost) && (
295 <li className="list-inline-item">
297 className="text-muted font-italic"
298 href={post_view.post.url}
299 title={post_view.post.url}
302 {hostname(post_view.post.url)}
305 <li className="list-inline-item">•</li>
308 <li className="list-inline-item">
310 <MomentTime data={post_view.post} />
313 {post_view.post.body && (
315 <li className="list-inline-item">•</li>
316 <li className="list-inline-item">
317 {/* Using a link with tippy doesn't work on touch devices unfortunately */}
319 className="text-muted"
320 data-tippy-content={md.render(
321 previewLines(post_view.post.body)
323 data-tippy-allowHtml={true}
324 aria-label={i18n.t("upvote")}
325 to={`/post/${post_view.post.id}`}
327 <Icon icon="book-open" classes="icon-inline mr-1" />
338 <div className={`vote-bar col-1 pr-0 small text-center`}>
340 className={`btn-animate btn btn-link p-0 ${
341 this.state.my_vote == 1 ? "text-info" : "text-muted"
343 onClick={linkEvent(this, this.handlePostLike)}
344 data-tippy-content={i18n.t("upvote")}
345 aria-label={i18n.t("upvote")}
347 <Icon icon="arrow-up1" classes="upvote" />
350 class={`unselectable pointer font-weight-bold text-muted px-1`}
351 data-tippy-content={this.pointsTippy}
355 {this.props.enableDownvotes && (
357 className={`btn-animate btn btn-link p-0 ${
358 this.state.my_vote == -1 ? "text-danger" : "text-muted"
360 onClick={linkEvent(this, this.handlePostDisLike)}
361 data-tippy-content={i18n.t("downvote")}
362 aria-label={i18n.t("downvote")}
364 <Icon icon="arrow-down1" classes="downvote" />
372 let post = this.props.post_view.post;
374 <div className="post-title overflow-hidden">
376 {this.props.showBody && post.url ? (
378 className={!post.stickied ? "text-body" : "text-primary"}
387 className={!post.stickied ? "text-body" : "text-primary"}
388 to={`/post/${post.id}`}
389 title={i18n.t("comments")}
394 {(isImage(post.url) || post.thumbnail_url) &&
395 (!this.state.imageExpanded ? (
397 class="text-monospace unselectable pointer ml-2 text-muted small"
398 data-tippy-content={i18n.t("expand_here")}
399 onClick={linkEvent(this, this.handleImageExpandClick)}
401 <Icon icon="plus-square" classes="icon-inline" />
406 class="text-monospace unselectable pointer ml-2 text-muted small"
407 onClick={linkEvent(this, this.handleImageExpandClick)}
409 <Icon icon="minus-square" classes="icon-inline" />
414 onClick={linkEvent(this, this.handleImageExpandClick)}
416 <PictrsImage src={this.getImageSrc()} />
422 <small className="ml-2 text-muted font-italic">
428 className="unselectable pointer ml-2 text-muted font-italic"
429 data-tippy-content={i18n.t("deleted")}
431 <Icon icon="trash" classes="icon-inline text-danger" />
436 className="unselectable pointer ml-2 text-muted font-italic"
437 data-tippy-content={i18n.t("locked")}
439 <Icon icon="lock" classes="icon-inline text-danger" />
444 className="unselectable pointer ml-2 text-muted font-italic"
445 data-tippy-content={i18n.t("stickied")}
447 <Icon icon="pin" classes="icon-inline text-primary" />
451 <small className="ml-2 text-muted font-italic">
460 commentsLine(mobile = false) {
461 let post_view = this.props.post_view;
463 <div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold mb-1">
464 <button class="btn btn-link text-muted p-0">
466 className="text-muted small"
467 title={i18n.t("number_of_comments", {
468 count: post_view.counts.comments,
470 to={`/post/${post_view.post.id}`}
472 <Icon icon="message-square" classes="icon-inline mr-1" />
473 {i18n.t("number_of_comments", {
474 count: post_view.counts.comments,
480 {this.state.downvotes !== 0 && (
482 class="btn text-muted py-0 pr-0"
483 data-tippy-content={this.pointsTippy}
484 aria-label={i18n.t("downvote")}
487 <Icon icon="arrow-down1" classes="icon-inline mr-1" />
488 <span>{this.state.downvotes}</span>
492 {!this.props.showBody && (
494 class="btn btn-link btn-animate text-muted py-0"
495 onClick={linkEvent(this, this.handleSavePostClick)}
497 post_view.saved ? i18n.t("unsave") : i18n.t("save")
499 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
504 classes={`icon-inline ${post_view.saved && "text-warning"}`}
511 {/* This is an expanding spacer for mobile */}
512 <div className="flex-grow-1"></div>
517 className={`btn-animate btn py-0 px-1 ${
518 this.state.my_vote == 1 ? "text-info" : "text-muted"
520 data-tippy-content={this.pointsTippy}
521 onClick={linkEvent(this, this.handlePostLike)}
522 aria-label={i18n.t("upvote")}
524 <Icon icon="arrow-up1" classes="icon-inline small mr-2" />
527 {this.props.enableDownvotes && (
529 className={`ml-2 btn-animate btn py-0 pl-1 ${
530 this.state.my_vote == -1 ? "text-danger" : "text-muted"
532 onClick={linkEvent(this, this.handlePostDisLike)}
533 data-tippy-content={this.pointsTippy}
534 aria-label={i18n.t("downvote")}
536 <Icon icon="arrow-down1" classes="icon-inline small mr-2" />
537 {this.state.downvotes !== 0 && (
538 <span>{this.state.downvotes}</span>
544 class="btn btn-link btn-animate text-muted py-0 pl-1 pr-0"
545 onClick={linkEvent(this, this.handleSavePostClick)}
546 aria-label={post_view.saved ? i18n.t("unsave") : i18n.t("save")}
548 post_view.saved ? i18n.t("unsave") : i18n.t("save")
553 classes={`icon-inline ${post_view.saved && "text-warning"}`}
557 {!this.state.showMoreMobile && this.props.showBody && (
559 class="btn btn-link btn-animate text-muted py-0"
560 onClick={linkEvent(this, this.handleShowMoreMobile)}
561 aria-label={i18n.t("more")}
562 data-tippy-content={i18n.t("more")}
564 <Icon icon="more-vertical" classes="icon-inline" />
567 {this.state.showMoreMobile && this.postActions(mobile)}
575 let dupes = this.props.duplicates;
578 dupes.length > 0 && (
579 <ul class="list-inline mb-1 small text-muted">
581 <li className="list-inline-item mr-2">
582 {i18n.t("cross_posted_to")}
585 <li className="list-inline-item mr-2">
586 <Link to={`/post/${pv.post.id}`}>
589 : `${pv.community.name}@${hostname(pv.community.actor_id)}`}
599 postActions(mobile = false) {
600 let post_view = this.props.post_view;
602 UserService.Instance.localUserView && (
604 {this.props.showBody && (
608 class="btn btn-link btn-animate text-muted py-0 pl-0"
609 onClick={linkEvent(this, this.handleSavePostClick)}
611 post_view.saved ? i18n.t("unsave") : i18n.t("save")
614 post_view.saved ? i18n.t("unsave") : i18n.t("save")
619 classes={`icon-inline ${post_view.saved && "text-warning"}`}
624 className="btn btn-link btn-animate text-muted py-0"
625 to={`/create_post${this.crossPostParams}`}
626 title={i18n.t("cross_post")}
628 <Icon icon="copy" classes="icon-inline" />
632 {this.myPost && this.props.showBody && (
635 class="btn btn-link btn-animate text-muted py-0"
636 onClick={linkEvent(this, this.handleEditClick)}
637 data-tippy-content={i18n.t("edit")}
638 aria-label={i18n.t("edit")}
640 <Icon icon="edit" classes="icon-inline" />
643 class="btn btn-link btn-animate text-muted py-0"
644 onClick={linkEvent(this, this.handleDeleteClick)}
646 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
649 !post_view.post.deleted ? i18n.t("delete") : i18n.t("restore")
654 classes={`icon-inline ${
655 post_view.post.deleted && "text-danger"
662 {!this.state.showAdvanced && this.props.showBody ? (
664 class="btn btn-link btn-animate text-muted py-0"
665 onClick={linkEvent(this, this.handleShowAdvanced)}
666 data-tippy-content={i18n.t("more")}
667 aria-label={i18n.t("more")}
669 <Icon icon="more-vertical" classes="icon-inline" />
673 {this.props.showBody && post_view.post.body && (
675 class="btn btn-link btn-animate text-muted py-0"
676 onClick={linkEvent(this, this.handleViewSource)}
677 data-tippy-content={i18n.t("view_source")}
678 aria-label={i18n.t("view_source")}
682 classes={`icon-inline ${
683 this.state.viewSource && "text-success"
688 {this.canModOnSelf && (
691 class="btn btn-link btn-animate text-muted py-0"
692 onClick={linkEvent(this, this.handleModLock)}
694 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
697 post_view.post.locked ? i18n.t("unlock") : i18n.t("lock")
702 classes={`icon-inline ${
703 post_view.post.locked && "text-danger"
708 class="btn btn-link btn-animate text-muted py-0"
709 onClick={linkEvent(this, this.handleModSticky)}
711 post_view.post.stickied
716 post_view.post.stickied
723 classes={`icon-inline ${
724 post_view.post.stickied && "text-success"
730 {/* Mods can ban from community, and appoint as mods to community */}
731 {(this.canMod || this.canAdmin) &&
732 (!post_view.post.removed ? (
734 class="btn btn-link btn-animate text-muted py-0"
735 onClick={linkEvent(this, this.handleModRemoveShow)}
736 aria-label={i18n.t("remove")}
742 class="btn btn-link btn-animate text-muted py-0"
743 onClick={linkEvent(this, this.handleModRemoveSubmit)}
744 aria-label={i18n.t("restore")}
752 (!post_view.creator_banned_from_community ? (
754 class="btn btn-link btn-animate text-muted py-0"
757 this.handleModBanFromCommunityShow
759 aria-label={i18n.t("ban")}
765 class="btn btn-link btn-animate text-muted py-0"
768 this.handleModBanFromCommunitySubmit
770 aria-label={i18n.t("unban")}
775 {!post_view.creator_banned_from_community && (
777 class="btn btn-link btn-animate text-muted py-0"
778 onClick={linkEvent(this, this.handleAddModToCommunity)}
781 ? i18n.t("remove_as_mod")
782 : i18n.t("appoint_as_mod")
786 ? i18n.t("remove_as_mod")
787 : i18n.t("appoint_as_mod")}
792 {/* Community creators and admins can transfer community to another mod */}
793 {(this.amCommunityCreator || this.canAdmin) &&
795 (!this.state.showConfirmTransferCommunity ? (
797 class="btn btn-link btn-animate text-muted py-0"
800 this.handleShowConfirmTransferCommunity
802 aria-label={i18n.t("transfer_community")}
804 {i18n.t("transfer_community")}
809 class="d-inline-block mr-1 btn btn-link btn-animate text-muted py-0"
810 aria-label={i18n.t("are_you_sure")}
812 {i18n.t("are_you_sure")}
815 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
816 aria-label={i18n.t("yes")}
817 onClick={linkEvent(this, this.handleTransferCommunity)}
822 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
825 this.handleCancelShowConfirmTransferCommunity
827 aria-label={i18n.t("no")}
833 {/* Admins can ban from all, and appoint other admins */}
837 (!post_view.creator.banned ? (
839 class="btn btn-link btn-animate text-muted py-0"
840 onClick={linkEvent(this, this.handleModBanShow)}
841 aria-label={i18n.t("ban_from_site")}
843 {i18n.t("ban_from_site")}
847 class="btn btn-link btn-animate text-muted py-0"
848 onClick={linkEvent(this, this.handleModBanSubmit)}
849 aria-label={i18n.t("unban_from_site")}
851 {i18n.t("unban_from_site")}
854 {!post_view.creator.banned && post_view.creator.local && (
856 class="btn btn-link btn-animate text-muted py-0"
857 onClick={linkEvent(this, this.handleAddAdmin)}
860 ? i18n.t("remove_as_admin")
861 : i18n.t("appoint_as_admin")
865 ? i18n.t("remove_as_admin")
866 : i18n.t("appoint_as_admin")}
871 {/* Site Creator can transfer to another admin */}
872 {this.amSiteCreator &&
874 (!this.state.showConfirmTransferSite ? (
876 class="btn btn-link btn-animate text-muted py-0"
879 this.handleShowConfirmTransferSite
881 aria-label={i18n.t("transfer_site")}
883 {i18n.t("transfer_site")}
888 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
889 aria-label={i18n.t("are_you_sure")}
891 {i18n.t("are_you_sure")}
894 class="btn btn-link btn-animate text-muted py-0 d-inline-block mr-1"
895 onClick={linkEvent(this, this.handleTransferSite)}
896 aria-label={i18n.t("yes")}
901 class="btn btn-link btn-animate text-muted py-0 d-inline-block"
904 this.handleCancelShowConfirmTransferSite
906 aria-label={i18n.t("no")}
919 removeAndBanDialogs() {
920 let post = this.props.post_view;
923 {this.state.showRemoveDialog && (
926 onSubmit={linkEvent(this, this.handleModRemoveSubmit)}
928 <label class="sr-only" htmlFor="post-listing-remove-reason">
933 id="post-listing-remove-reason"
934 class="form-control mr-2"
935 placeholder={i18n.t("reason")}
936 value={this.state.removeReason}
937 onInput={linkEvent(this, this.handleModRemoveReasonChange)}
941 class="btn btn-secondary"
942 aria-label={i18n.t("remove_post")}
944 {i18n.t("remove_post")}
948 {this.state.showBanDialog && (
949 <form onSubmit={linkEvent(this, this.handleModBanBothSubmit)}>
950 <div class="form-group row">
951 <label class="col-form-label" htmlFor="post-listing-ban-reason">
956 id="post-listing-ban-reason"
957 class="form-control mr-2"
958 placeholder={i18n.t("reason")}
959 value={this.state.banReason}
960 onInput={linkEvent(this, this.handleModBanReasonChange)}
962 <div class="form-group">
963 <div class="form-check">
965 class="form-check-input"
966 id="mod-ban-remove-data"
968 checked={this.state.removeData}
969 onChange={linkEvent(this, this.handleModRemoveDataChange)}
971 <label class="form-check-label" htmlFor="mod-ban-remove-data">
972 {i18n.t("remove_posts_comments")}
977 {/* TODO hold off on expires until later */}
978 {/* <div class="form-group row"> */}
979 {/* <label class="col-form-label">Expires</label> */}
980 {/* <input type="date" class="form-control mr-2" placeholder={i18n.t('expires')} value={this.state.banExpires} onInput={linkEvent(this, this.handleModBanExpiresChange)} /> */}
982 <div class="form-group row">
985 class="btn btn-secondary"
986 aria-label={i18n.t("ban")}
988 {i18n.t("ban")} {post.creator.name}
998 let post = this.props.post_view.post;
999 return post.thumbnail_url || isImage(post.url) ? (
1001 <div className={`${this.state.imageExpanded ? "col-12" : "col-8"}`}>
1002 {this.postTitleLine()}
1005 {/* Post body prev or thumbnail */}
1006 {!this.state.imageExpanded && this.thumbnail()}
1010 this.postTitleLine()
1014 showMobilePreview() {
1015 let post = this.props.post_view.post;
1018 !this.props.showBody && (
1020 className="md-div mb-1"
1021 dangerouslySetInnerHTML={{
1022 __html: md.render(previewLines(post.body)),
1032 {/* The mobile view*/}
1033 <div class="d-block d-sm-none">
1035 <div class="col-12">
1036 {this.createdLine()}
1038 {/* If it has a thumbnail, do a right aligned thumbnail */}
1039 {this.mobileThumbnail()}
1041 {/* Show a preview of the post body */}
1042 {this.showMobilePreview()}
1044 {this.commentsLine(true)}
1045 {this.duplicatesLine()}
1046 {this.removeAndBanDialogs()}
1051 {/* The larger view*/}
1052 <div class="d-none d-sm-block">
1055 {!this.state.imageExpanded && (
1056 <div class="col-sm-2 pr-0">
1057 <div class="">{this.thumbnail()}</div>
1062 this.state.imageExpanded ? "col-12" : "col-12 col-sm-9"
1066 <div className="col-12">
1067 {this.postTitleLine()}
1068 {this.createdLine()}
1069 {this.commentsLine()}
1070 {this.duplicatesLine()}
1071 {this.postActions()}
1072 {this.removeAndBanDialogs()}
1082 private get myPost(): boolean {
1084 UserService.Instance.localUserView &&
1085 this.props.post_view.creator.id ==
1086 UserService.Instance.localUserView.person.id
1090 get isMod(): boolean {
1092 this.props.moderators &&
1094 this.props.moderators.map(m => m.moderator.id),
1095 this.props.post_view.creator.id
1100 get isAdmin(): boolean {
1102 this.props.admins &&
1104 this.props.admins.map(a => a.person.id),
1105 this.props.post_view.creator.id
1110 get canMod(): boolean {
1111 if (this.props.admins && this.props.moderators) {
1112 let adminsThenMods = this.props.admins
1113 .map(a => a.person.id)
1114 .concat(this.props.moderators.map(m => m.moderator.id));
1117 UserService.Instance.localUserView,
1119 this.props.post_view.creator.id
1126 get canModOnSelf(): boolean {
1127 if (this.props.admins && this.props.moderators) {
1128 let adminsThenMods = this.props.admins
1129 .map(a => a.person.id)
1130 .concat(this.props.moderators.map(m => m.moderator.id));
1133 UserService.Instance.localUserView,
1135 this.props.post_view.creator.id,
1143 get canAdmin(): boolean {
1145 this.props.admins &&
1147 UserService.Instance.localUserView,
1148 this.props.admins.map(a => a.person.id),
1149 this.props.post_view.creator.id
1154 get amCommunityCreator(): boolean {
1156 this.props.moderators &&
1157 UserService.Instance.localUserView &&
1158 this.props.post_view.creator.id !=
1159 UserService.Instance.localUserView.person.id &&
1160 UserService.Instance.localUserView.person.id ==
1161 this.props.moderators[0].moderator.id
1165 get amSiteCreator(): boolean {
1167 this.props.admins &&
1168 UserService.Instance.localUserView &&
1169 this.props.post_view.creator.id !=
1170 UserService.Instance.localUserView.person.id &&
1171 UserService.Instance.localUserView.person.id ==
1172 this.props.admins[0].person.id
1176 handlePostLike(i: PostListing, event: any) {
1177 event.preventDefault();
1178 if (!UserService.Instance.localUserView) {
1179 this.context.router.history.push(`/login`);
1182 let new_vote = i.state.my_vote == 1 ? 0 : 1;
1184 if (i.state.my_vote == 1) {
1187 } else if (i.state.my_vote == -1) {
1188 i.state.downvotes--;
1196 i.state.my_vote = new_vote;
1198 let form: CreatePostLike = {
1199 post_id: i.props.post_view.post.id,
1200 score: i.state.my_vote,
1204 WebSocketService.Instance.send(wsClient.likePost(form));
1205 i.setState(i.state);
1209 handlePostDisLike(i: PostListing, event: any) {
1210 event.preventDefault();
1211 if (!UserService.Instance.localUserView) {
1212 this.context.router.history.push(`/login`);
1215 let new_vote = i.state.my_vote == -1 ? 0 : -1;
1217 if (i.state.my_vote == 1) {
1220 i.state.downvotes++;
1221 } else if (i.state.my_vote == -1) {
1222 i.state.downvotes--;
1225 i.state.downvotes++;
1229 i.state.my_vote = new_vote;
1231 let form: CreatePostLike = {
1232 post_id: i.props.post_view.post.id,
1233 score: i.state.my_vote,
1237 WebSocketService.Instance.send(wsClient.likePost(form));
1238 i.setState(i.state);
1242 handleEditClick(i: PostListing) {
1243 i.state.showEdit = true;
1244 i.setState(i.state);
1247 handleEditCancel() {
1248 this.state.showEdit = false;
1249 this.setState(this.state);
1252 // The actual editing is done in the recieve for post
1254 this.state.showEdit = false;
1255 this.setState(this.state);
1258 handleDeleteClick(i: PostListing) {
1259 let deleteForm: DeletePost = {
1260 post_id: i.props.post_view.post.id,
1261 deleted: !i.props.post_view.post.deleted,
1264 WebSocketService.Instance.send(wsClient.deletePost(deleteForm));
1267 handleSavePostClick(i: PostListing) {
1269 i.props.post_view.saved == undefined ? true : !i.props.post_view.saved;
1270 let form: SavePost = {
1271 post_id: i.props.post_view.post.id,
1276 WebSocketService.Instance.send(wsClient.savePost(form));
1279 get crossPostParams(): string {
1280 let post = this.props.post_view.post;
1281 let params = `?title=${encodeURIComponent(post.name)}`;
1284 params += `&url=${encodeURIComponent(post.url)}`;
1287 params += `&body=${encodeURIComponent(post.body)}`;
1292 handleModRemoveShow(i: PostListing) {
1293 i.state.showRemoveDialog = true;
1294 i.setState(i.state);
1297 handleModRemoveReasonChange(i: PostListing, event: any) {
1298 i.state.removeReason = event.target.value;
1299 i.setState(i.state);
1302 handleModRemoveDataChange(i: PostListing, event: any) {
1303 i.state.removeData = event.target.checked;
1304 i.setState(i.state);
1307 handleModRemoveSubmit(i: PostListing, event: any) {
1308 event.preventDefault();
1309 let form: RemovePost = {
1310 post_id: i.props.post_view.post.id,
1311 removed: !i.props.post_view.post.removed,
1312 reason: i.state.removeReason,
1315 WebSocketService.Instance.send(wsClient.removePost(form));
1317 i.state.showRemoveDialog = false;
1318 i.setState(i.state);
1321 handleModLock(i: PostListing) {
1322 let form: LockPost = {
1323 post_id: i.props.post_view.post.id,
1324 locked: !i.props.post_view.post.locked,
1327 WebSocketService.Instance.send(wsClient.lockPost(form));
1330 handleModSticky(i: PostListing) {
1331 let form: StickyPost = {
1332 post_id: i.props.post_view.post.id,
1333 stickied: !i.props.post_view.post.stickied,
1336 WebSocketService.Instance.send(wsClient.stickyPost(form));
1339 handleModBanFromCommunityShow(i: PostListing) {
1340 i.state.showBanDialog = true;
1341 i.state.banType = BanType.Community;
1342 i.setState(i.state);
1345 handleModBanShow(i: PostListing) {
1346 i.state.showBanDialog = true;
1347 i.state.banType = BanType.Site;
1348 i.setState(i.state);
1351 handleModBanReasonChange(i: PostListing, event: any) {
1352 i.state.banReason = event.target.value;
1353 i.setState(i.state);
1356 handleModBanExpiresChange(i: PostListing, event: any) {
1357 i.state.banExpires = event.target.value;
1358 i.setState(i.state);
1361 handleModBanFromCommunitySubmit(i: PostListing) {
1362 i.state.banType = BanType.Community;
1363 i.setState(i.state);
1364 i.handleModBanBothSubmit(i);
1367 handleModBanSubmit(i: PostListing) {
1368 i.state.banType = BanType.Site;
1369 i.setState(i.state);
1370 i.handleModBanBothSubmit(i);
1373 handleModBanBothSubmit(i: PostListing, event?: any) {
1374 event.preventDefault();
1376 if (i.state.banType == BanType.Community) {
1377 // If its an unban, restore all their data
1378 let ban = !i.props.post_view.creator_banned_from_community;
1380 i.state.removeData = false;
1382 let form: BanFromCommunity = {
1383 person_id: i.props.post_view.creator.id,
1384 community_id: i.props.post_view.community.id,
1386 remove_data: i.state.removeData,
1387 reason: i.state.banReason,
1388 expires: getUnixTime(i.state.banExpires),
1391 WebSocketService.Instance.send(wsClient.banFromCommunity(form));
1393 // If its an unban, restore all their data
1394 let ban = !i.props.post_view.creator.banned;
1396 i.state.removeData = false;
1398 let form: BanPerson = {
1399 person_id: i.props.post_view.creator.id,
1401 remove_data: i.state.removeData,
1402 reason: i.state.banReason,
1403 expires: getUnixTime(i.state.banExpires),
1406 WebSocketService.Instance.send(wsClient.banPerson(form));
1409 i.state.showBanDialog = false;
1410 i.setState(i.state);
1413 handleAddModToCommunity(i: PostListing) {
1414 let form: AddModToCommunity = {
1415 person_id: i.props.post_view.creator.id,
1416 community_id: i.props.post_view.community.id,
1420 WebSocketService.Instance.send(wsClient.addModToCommunity(form));
1421 i.setState(i.state);
1424 handleAddAdmin(i: PostListing) {
1425 let form: AddAdmin = {
1426 person_id: i.props.post_view.creator.id,
1430 WebSocketService.Instance.send(wsClient.addAdmin(form));
1431 i.setState(i.state);
1434 handleShowConfirmTransferCommunity(i: PostListing) {
1435 i.state.showConfirmTransferCommunity = true;
1436 i.setState(i.state);
1439 handleCancelShowConfirmTransferCommunity(i: PostListing) {
1440 i.state.showConfirmTransferCommunity = false;
1441 i.setState(i.state);
1444 handleTransferCommunity(i: PostListing) {
1445 let form: TransferCommunity = {
1446 community_id: i.props.post_view.community.id,
1447 person_id: i.props.post_view.creator.id,
1450 WebSocketService.Instance.send(wsClient.transferCommunity(form));
1451 i.state.showConfirmTransferCommunity = false;
1452 i.setState(i.state);
1455 handleShowConfirmTransferSite(i: PostListing) {
1456 i.state.showConfirmTransferSite = true;
1457 i.setState(i.state);
1460 handleCancelShowConfirmTransferSite(i: PostListing) {
1461 i.state.showConfirmTransferSite = false;
1462 i.setState(i.state);
1465 handleTransferSite(i: PostListing) {
1466 let form: TransferSite = {
1467 person_id: i.props.post_view.creator.id,
1470 WebSocketService.Instance.send(wsClient.transferSite(form));
1471 i.state.showConfirmTransferSite = false;
1472 i.setState(i.state);
1475 handleImageExpandClick(i: PostListing) {
1476 i.state.imageExpanded = !i.state.imageExpanded;
1477 i.setState(i.state);
1480 handleViewSource(i: PostListing) {
1481 i.state.viewSource = !i.state.viewSource;
1482 i.setState(i.state);
1485 handleShowAdvanced(i: PostListing) {
1486 i.state.showAdvanced = !i.state.showAdvanced;
1487 i.setState(i.state);
1491 handleShowMoreMobile(i: PostListing) {
1492 i.state.showMoreMobile = !i.state.showMoreMobile;
1493 i.state.showAdvanced = !i.state.showAdvanced;
1494 i.setState(i.state);
1498 get pointsTippy(): string {
1499 let points = i18n.t("number_of_points", {
1500 count: this.state.score,
1503 let upvotes = i18n.t("number_of_upvotes", {
1504 count: this.state.upvotes,
1507 let downvotes = i18n.t("number_of_downvotes", {
1508 count: this.state.downvotes,
1511 return `${points} • ${upvotes} • ${downvotes}`;