1 import autosize from "autosize";
2 import { Component, createRef, linkEvent, RefObject } from "inferno";
6 AddModToCommunityResponse,
8 BanFromCommunityResponse,
39 MarkCommentReplyAsRead,
40 MarkPersonMentionAsRead,
53 } from "lemmy-js-client";
54 import { i18n } from "../../i18next";
59 } from "../../interfaces";
60 import { UserService } from "../../services";
61 import { FirstLoadService } from "../../services/FirstLoadService";
62 import { HttpService, RequestState } from "../../services/HttpService";
72 getCommentIdFromProps,
79 restoreScrollPosition,
87 import { CommentForm } from "../comment/comment-form";
88 import { CommentNodes } from "../comment/comment-nodes";
89 import { HtmlTags } from "../common/html-tags";
90 import { Icon, Spinner } from "../common/icon";
91 import { Sidebar } from "../community/sidebar";
92 import { PostListing } from "./post-listing";
94 const commentsShownInterval = 15;
99 postRes: RequestState<GetPostResponse>;
100 commentsRes: RequestState<GetCommentsResponse>;
101 commentSort: CommentSortType;
102 commentViewType: CommentViewType;
104 siteRes: GetSiteResponse;
105 commentSectionRef?: RefObject<HTMLDivElement>;
106 showSidebarMobile: boolean;
107 maxCommentsShown: number;
108 finished: Map<CommentId, boolean | undefined>;
109 isIsomorphic: boolean;
112 export class Post extends Component<any, PostState> {
113 private isoData = setIsoData(this.context);
114 private commentScrollDebounced: () => void;
116 postRes: { state: "empty" },
117 commentsRes: { state: "empty" },
118 postId: getIdFromProps(this.props),
119 commentId: getCommentIdFromProps(this.props),
121 commentViewType: CommentViewType.Tree,
123 siteRes: this.isoData.site_res,
124 showSidebarMobile: false,
125 maxCommentsShown: commentsShownInterval,
130 constructor(props: any, context: any) {
131 super(props, context);
133 this.handleDeleteCommunityClick =
134 this.handleDeleteCommunityClick.bind(this);
135 this.handleEditCommunity = this.handleEditCommunity.bind(this);
136 this.handleFollow = this.handleFollow.bind(this);
137 this.handleModRemoveCommunity = this.handleModRemoveCommunity.bind(this);
138 this.handleCreateComment = this.handleCreateComment.bind(this);
139 this.handleEditComment = this.handleEditComment.bind(this);
140 this.handleSaveComment = this.handleSaveComment.bind(this);
141 this.handleBlockCommunity = this.handleBlockCommunity.bind(this);
142 this.handleBlockPerson = this.handleBlockPerson.bind(this);
143 this.handleDeleteComment = this.handleDeleteComment.bind(this);
144 this.handleRemoveComment = this.handleRemoveComment.bind(this);
145 this.handleCommentVote = this.handleCommentVote.bind(this);
146 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
147 this.handleAddAdmin = this.handleAddAdmin.bind(this);
148 this.handlePurgePerson = this.handlePurgePerson.bind(this);
149 this.handlePurgeComment = this.handlePurgeComment.bind(this);
150 this.handleCommentReport = this.handleCommentReport.bind(this);
151 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
152 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
153 this.handleFetchChildren = this.handleFetchChildren.bind(this);
154 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
155 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
156 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
157 this.handleBanPerson = this.handleBanPerson.bind(this);
158 this.handlePostEdit = this.handlePostEdit.bind(this);
159 this.handlePostVote = this.handlePostVote.bind(this);
160 this.handlePostReport = this.handlePostReport.bind(this);
161 this.handleLockPost = this.handleLockPost.bind(this);
162 this.handleDeletePost = this.handleDeletePost.bind(this);
163 this.handleRemovePost = this.handleRemovePost.bind(this);
164 this.handleSavePost = this.handleSavePost.bind(this);
165 this.handlePurgePost = this.handlePurgePost.bind(this);
166 this.handleFeaturePost = this.handleFeaturePost.bind(this);
168 this.state = { ...this.state, commentSectionRef: createRef() };
170 // Only fetch the data if coming from another route
171 if (FirstLoadService.isFirstLoad) {
172 const [postRes, commentsRes] = this.isoData.routeData;
182 if (this.checkScrollIntoCommentsParam) {
183 this.scrollIntoCommentSection();
191 postRes: { state: "loading" },
192 commentsRes: { state: "loading" },
195 const auth = myAuth();
198 postRes: await HttpService.client.getPost({
199 id: this.state.postId,
200 comment_id: this.state.commentId,
203 commentsRes: await HttpService.client.getComments({
204 post_id: this.state.postId,
205 parent_id: this.state.commentId,
206 max_depth: commentTreeMaxDepth,
207 sort: this.state.commentSort,
216 if (!this.state.commentId) restoreScrollPosition(this.context);
218 if (this.checkScrollIntoCommentsParam) {
219 this.scrollIntoCommentSection();
223 static fetchInitialData({
227 }: InitialFetchRequest): Promise<any>[] {
228 const pathSplit = path.split("/");
229 const promises: Promise<RequestState<any>>[] = [];
231 const pathType = pathSplit.at(1);
232 const id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined;
234 const postForm: GetPost = {
238 const commentsForm: GetComments = {
239 max_depth: commentTreeMaxDepth,
246 // Set the correct id based on the path type
247 if (pathType === "post") {
249 commentsForm.post_id = id;
251 postForm.comment_id = id;
252 commentsForm.parent_id = id;
255 promises.push(client.getPost(postForm));
256 promises.push(client.getComments(commentsForm));
261 componentWillUnmount() {
262 document.removeEventListener("scroll", this.commentScrollDebounced);
264 saveScrollPosition(this.context);
267 async componentDidMount() {
268 if (!this.state.isIsomorphic) {
269 await this.fetchPost();
272 autosize(document.querySelectorAll("textarea"));
274 this.commentScrollDebounced = debounce(this.trackCommentsBoxScrolling, 100);
275 document.addEventListener("scroll", this.commentScrollDebounced);
278 async componentDidUpdate(_lastProps: any) {
279 // Necessary if you are on a post and you click another post (same route)
280 if (_lastProps.location.pathname !== _lastProps.history.location.pathname) {
281 await this.fetchPost();
285 get checkScrollIntoCommentsParam() {
287 new URLSearchParams(this.props.location.search).get("scrollToComments")
291 scrollIntoCommentSection() {
292 this.state.commentSectionRef?.current?.scrollIntoView();
295 isBottom(el: Element): boolean {
296 return el?.getBoundingClientRect().bottom <= window.innerHeight;
300 * Shows new comments when scrolling to the bottom of the comments div
302 trackCommentsBoxScrolling = () => {
303 const wrappedElement = document.getElementsByClassName("comments")[0];
304 if (wrappedElement && this.isBottom(wrappedElement)) {
306 this.state.commentsRes.state == "success"
307 ? this.state.commentsRes.data.comments.length
310 if (this.state.maxCommentsShown < commentCount) {
312 maxCommentsShown: this.state.maxCommentsShown + commentsShownInterval,
318 get documentTitle(): string {
319 const siteName = this.state.siteRes.site_view.site.name;
320 return this.state.postRes.state == "success"
321 ? `${this.state.postRes.data.post_view.post.name} - ${siteName}`
325 get imageTag(): string | undefined {
326 if (this.state.postRes.state == "success") {
327 const post = this.state.postRes.data.post_view.post;
328 const thumbnail = post.thumbnail_url;
329 const url = post.url;
330 return thumbnail || (url && isImage(url) ? url : undefined);
331 } else return undefined;
335 switch (this.state.postRes.state) {
343 const res = this.state.postRes.data;
345 <div className="row">
346 <div className="col-12 col-md-8 mb-3">
348 title={this.documentTitle}
349 path={this.context.router.route.match.url}
350 image={this.imageTag}
351 description={res.post_view.post.body}
354 post_view={res.post_view}
355 crossPosts={res.cross_posts}
358 moderators={res.moderators}
359 admins={this.state.siteRes.admins}
360 enableDownvotes={enableDownvotes(this.state.siteRes)}
361 enableNsfw={enableNsfw(this.state.siteRes)}
362 allLanguages={this.state.siteRes.all_languages}
363 siteLanguages={this.state.siteRes.discussion_languages}
364 onBlockPerson={this.handleBlockPerson}
365 onPostEdit={this.handlePostEdit}
366 onPostVote={this.handlePostVote}
367 onPostReport={this.handlePostReport}
368 onLockPost={this.handleLockPost}
369 onDeletePost={this.handleDeletePost}
370 onRemovePost={this.handleRemovePost}
371 onSavePost={this.handleSavePost}
372 onPurgePerson={this.handlePurgePerson}
373 onPurgePost={this.handlePurgePost}
374 onBanPerson={this.handleBanPerson}
375 onBanPersonFromCommunity={this.handleBanFromCommunity}
376 onAddModToCommunity={this.handleAddModToCommunity}
377 onAddAdmin={this.handleAddAdmin}
378 onTransferCommunity={this.handleTransferCommunity}
379 onFeaturePost={this.handleFeaturePost}
381 <div ref={this.state.commentSectionRef} className="mb-2" />
383 node={res.post_view.post.id}
384 disabled={res.post_view.post.locked}
385 allLanguages={this.state.siteRes.all_languages}
386 siteLanguages={this.state.siteRes.discussion_languages}
387 containerClass="post-comment-container"
388 onUpsertComment={this.handleCreateComment}
389 finished={this.state.finished.get(0)}
391 <div className="d-block d-md-none">
393 className="btn btn-secondary d-inline-block mb-2 mr-3"
394 onClick={linkEvent(this, this.handleShowSidebarMobile)}
396 {i18n.t("sidebar")}{" "}
399 this.state.showSidebarMobile
403 classes="icon-inline"
406 {this.state.showSidebarMobile && this.sidebar()}
409 {this.state.commentViewType == CommentViewType.Tree &&
411 {this.state.commentViewType == CommentViewType.Flat &&
414 <div className="d-none d-md-block col-md-4">{this.sidebar()}</div>
422 return <div className="container-lg">{this.renderPostRes()}</div>;
428 <div className="btn-group btn-group-toggle flex-wrap mr-3 mb-2">
430 className={`btn btn-outline-secondary pointer ${
431 this.state.commentSort === "Hot" && "active"
438 checked={this.state.commentSort === "Hot"}
439 onChange={linkEvent(this, this.handleCommentSortChange)}
443 className={`btn btn-outline-secondary pointer ${
444 this.state.commentSort === "Top" && "active"
451 checked={this.state.commentSort === "Top"}
452 onChange={linkEvent(this, this.handleCommentSortChange)}
456 className={`btn btn-outline-secondary pointer ${
457 this.state.commentSort === "New" && "active"
464 checked={this.state.commentSort === "New"}
465 onChange={linkEvent(this, this.handleCommentSortChange)}
469 className={`btn btn-outline-secondary pointer ${
470 this.state.commentSort === "Old" && "active"
477 checked={this.state.commentSort === "Old"}
478 onChange={linkEvent(this, this.handleCommentSortChange)}
482 <div className="btn-group btn-group-toggle flex-wrap mb-2">
484 className={`btn btn-outline-secondary pointer ${
485 this.state.commentViewType === CommentViewType.Flat && "active"
491 value={CommentViewType.Flat}
492 checked={this.state.commentViewType === CommentViewType.Flat}
493 onChange={linkEvent(this, this.handleCommentViewTypeChange)}
502 // These are already sorted by new
503 const commentsRes = this.state.commentsRes;
504 const postRes = this.state.postRes;
506 if (commentsRes.state == "success" && postRes.state == "success") {
510 nodes={commentsToFlatNodes(commentsRes.data.comments)}
511 viewType={this.state.commentViewType}
512 maxCommentsShown={this.state.maxCommentsShown}
514 locked={postRes.data.post_view.post.locked}
515 moderators={postRes.data.moderators}
516 admins={this.state.siteRes.admins}
517 enableDownvotes={enableDownvotes(this.state.siteRes)}
519 finished={this.state.finished}
520 allLanguages={this.state.siteRes.all_languages}
521 siteLanguages={this.state.siteRes.discussion_languages}
522 onSaveComment={this.handleSaveComment}
523 onBlockPerson={this.handleBlockPerson}
524 onDeleteComment={this.handleDeleteComment}
525 onRemoveComment={this.handleRemoveComment}
526 onCommentVote={this.handleCommentVote}
527 onCommentReport={this.handleCommentReport}
528 onDistinguishComment={this.handleDistinguishComment}
529 onAddModToCommunity={this.handleAddModToCommunity}
530 onAddAdmin={this.handleAddAdmin}
531 onTransferCommunity={this.handleTransferCommunity}
532 onFetchChildren={this.handleFetchChildren}
533 onPurgeComment={this.handlePurgeComment}
534 onPurgePerson={this.handlePurgePerson}
535 onCommentReplyRead={this.handleCommentReplyRead}
536 onPersonMentionRead={this.handlePersonMentionRead}
537 onBanPersonFromCommunity={this.handleBanFromCommunity}
538 onBanPerson={this.handleBanPerson}
539 onCreateComment={this.handleCreateComment}
540 onEditComment={this.handleEditComment}
548 const res = this.state.postRes;
549 if (res.state === "success") {
551 <div className="mb-3">
553 community_view={res.data.community_view}
554 moderators={res.data.moderators}
555 admins={this.state.siteRes.admins}
556 online={res.data.online}
557 enableNsfw={enableNsfw(this.state.siteRes)}
559 allLanguages={this.state.siteRes.all_languages}
560 siteLanguages={this.state.siteRes.discussion_languages}
561 onDeleteCommunity={this.handleDeleteCommunityClick}
562 onLeaveModTeam={this.handleAddModToCommunity}
563 onFollowCommunity={this.handleFollow}
564 onRemoveCommunity={this.handleModRemoveCommunity}
565 onPurgeCommunity={this.handlePurgeCommunity}
566 onBlockCommunity={this.handleBlockCommunity}
567 onEditCommunity={this.handleEditCommunity}
575 const res = this.state.postRes;
576 const firstComment = this.commentTree().at(0)?.comment_view.comment;
577 const depth = getDepthFromComment(firstComment);
578 const showContextButton = depth ? depth > 0 : false;
581 res.state == "success" && (
583 {!!this.state.commentId && (
586 className="pl-0 d-block btn btn-link text-muted"
587 onClick={linkEvent(this, this.handleViewPost)}
589 {i18n.t("view_all_comments")} âž”
591 {showContextButton && (
593 className="pl-0 d-block btn btn-link text-muted"
594 onClick={linkEvent(this, this.handleViewContext)}
596 {i18n.t("show_context")} âž”
602 nodes={this.commentTree()}
603 viewType={this.state.commentViewType}
604 maxCommentsShown={this.state.maxCommentsShown}
605 locked={res.data.post_view.post.locked}
606 moderators={res.data.moderators}
607 admins={this.state.siteRes.admins}
608 enableDownvotes={enableDownvotes(this.state.siteRes)}
609 finished={this.state.finished}
610 allLanguages={this.state.siteRes.all_languages}
611 siteLanguages={this.state.siteRes.discussion_languages}
612 onSaveComment={this.handleSaveComment}
613 onBlockPerson={this.handleBlockPerson}
614 onDeleteComment={this.handleDeleteComment}
615 onRemoveComment={this.handleRemoveComment}
616 onCommentVote={this.handleCommentVote}
617 onCommentReport={this.handleCommentReport}
618 onDistinguishComment={this.handleDistinguishComment}
619 onAddModToCommunity={this.handleAddModToCommunity}
620 onAddAdmin={this.handleAddAdmin}
621 onTransferCommunity={this.handleTransferCommunity}
622 onFetchChildren={this.handleFetchChildren}
623 onPurgeComment={this.handlePurgeComment}
624 onPurgePerson={this.handlePurgePerson}
625 onCommentReplyRead={this.handleCommentReplyRead}
626 onPersonMentionRead={this.handlePersonMentionRead}
627 onBanPersonFromCommunity={this.handleBanFromCommunity}
628 onBanPerson={this.handleBanPerson}
629 onCreateComment={this.handleCreateComment}
630 onEditComment={this.handleEditComment}
637 commentTree(): CommentNodeI[] {
638 if (this.state.commentsRes.state == "success") {
639 return buildCommentsTree(
640 this.state.commentsRes.data.comments,
641 !!this.state.commentId
648 async handleCommentSortChange(i: Post, event: any) {
650 commentSort: event.target.value as CommentSortType,
651 commentViewType: CommentViewType.Tree,
652 commentsRes: { state: "loading" },
653 postRes: { state: "loading" },
658 handleCommentViewTypeChange(i: Post, event: any) {
660 commentViewType: Number(event.target.value),
665 handleShowSidebarMobile(i: Post) {
666 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
669 handleViewPost(i: Post) {
670 if (i.state.postRes.state == "success") {
671 const id = i.state.postRes.data.post_view.post.id;
672 i.context.router.history.push(`/post/${id}`);
676 handleViewContext(i: Post) {
677 if (i.state.commentsRes.state == "success") {
678 const parentId = getCommentParentId(
679 i.state.commentsRes.data.comments.at(0)?.comment
682 i.context.router.history.push(`/comment/${parentId}`);
687 async handleDeleteCommunityClick(form: DeleteCommunity) {
688 const deleteCommunityRes = await HttpService.client.deleteCommunity(form);
689 this.updateCommunity(deleteCommunityRes);
692 async handleAddModToCommunity(form: AddModToCommunity) {
693 const addModRes = await HttpService.client.addModToCommunity(form);
694 this.updateModerators(addModRes);
697 async handleFollow(form: FollowCommunity) {
698 const followCommunityRes = await HttpService.client.followCommunity(form);
699 this.updateCommunity(followCommunityRes);
702 if (followCommunityRes.state === "success") {
703 const communityId = followCommunityRes.data.community_view.community.id;
704 const mui = UserService.Instance.myUserInfo;
706 mui.follows = mui.follows.filter(i => i.community.id != communityId);
711 async handlePurgeCommunity(form: PurgeCommunity) {
712 const purgeCommunityRes = await HttpService.client.purgeCommunity(form);
713 this.purgeItem(purgeCommunityRes);
716 async handlePurgePerson(form: PurgePerson) {
717 const purgePersonRes = await HttpService.client.purgePerson(form);
718 this.purgeItem(purgePersonRes);
721 async handlePurgeComment(form: PurgeComment) {
722 const purgeCommentRes = await HttpService.client.purgeComment(form);
723 this.purgeItem(purgeCommentRes);
726 async handlePurgePost(form: PurgePost) {
727 const purgeRes = await HttpService.client.purgePost(form);
728 this.purgeItem(purgeRes);
731 async handleBlockCommunity(form: BlockCommunity) {
732 const blockCommunityRes = await HttpService.client.blockCommunity(form);
733 // TODO Probably isn't necessary
736 s.postRes.state == "success" &&
737 blockCommunityRes.state == "success"
739 s.postRes.data.community_view = blockCommunityRes.data.community_view;
744 if (blockCommunityRes.state == "success") {
745 updateCommunityBlock(blockCommunityRes.data);
749 async handleBlockPerson(form: BlockPerson) {
750 const blockPersonRes = await HttpService.client.blockPerson(form);
751 if (blockPersonRes.state == "success") {
752 updatePersonBlock(blockPersonRes.data);
756 async handleModRemoveCommunity(form: RemoveCommunity) {
757 const removeCommunityRes = await HttpService.client.removeCommunity(form);
758 this.updateCommunity(removeCommunityRes);
761 async handleEditCommunity(form: EditCommunity) {
762 const res = await HttpService.client.editCommunity(form);
763 this.updateCommunity(res);
768 async handleCreateComment(form: CreateComment) {
769 const createCommentRes = await HttpService.client.createComment(form);
770 this.createAndUpdateComments(createCommentRes);
772 return createCommentRes;
775 async handleEditComment(form: EditComment) {
776 const editCommentRes = await HttpService.client.editComment(form);
777 this.findAndUpdateComment(editCommentRes);
779 return editCommentRes;
782 async handleDeleteComment(form: DeleteComment) {
783 const deleteCommentRes = await HttpService.client.deleteComment(form);
784 this.findAndUpdateComment(deleteCommentRes);
787 async handleDeletePost(form: DeletePost) {
788 const deleteRes = await HttpService.client.deletePost(form);
789 this.updatePost(deleteRes);
792 async handleRemovePost(form: RemovePost) {
793 const removeRes = await HttpService.client.removePost(form);
794 this.updatePost(removeRes);
797 async handleRemoveComment(form: RemoveComment) {
798 const removeCommentRes = await HttpService.client.removeComment(form);
799 this.findAndUpdateComment(removeCommentRes);
802 async handleSaveComment(form: SaveComment) {
803 const saveCommentRes = await HttpService.client.saveComment(form);
804 this.findAndUpdateComment(saveCommentRes);
807 async handleSavePost(form: SavePost) {
808 const saveRes = await HttpService.client.savePost(form);
809 this.updatePost(saveRes);
812 async handleFeaturePost(form: FeaturePost) {
813 const featureRes = await HttpService.client.featurePost(form);
814 this.updatePost(featureRes);
817 async handleCommentVote(form: CreateCommentLike) {
818 const voteRes = await HttpService.client.likeComment(form);
819 this.findAndUpdateComment(voteRes);
822 async handlePostVote(form: CreatePostLike) {
823 const voteRes = await HttpService.client.likePost(form);
824 this.updatePost(voteRes);
827 async handlePostEdit(form: EditPost) {
828 const res = await HttpService.client.editPost(form);
829 this.updatePost(res);
832 async handleCommentReport(form: CreateCommentReport) {
833 const reportRes = await HttpService.client.createCommentReport(form);
834 if (reportRes.state == "success") {
835 toast(i18n.t("report_created"));
839 async handlePostReport(form: CreatePostReport) {
840 const reportRes = await HttpService.client.createPostReport(form);
841 if (reportRes.state == "success") {
842 toast(i18n.t("report_created"));
846 async handleLockPost(form: LockPost) {
847 const lockRes = await HttpService.client.lockPost(form);
848 this.updatePost(lockRes);
851 async handleDistinguishComment(form: DistinguishComment) {
852 const distinguishRes = await HttpService.client.distinguishComment(form);
853 this.findAndUpdateComment(distinguishRes);
856 async handleAddAdmin(form: AddAdmin) {
857 const addAdminRes = await HttpService.client.addAdmin(form);
859 if (addAdminRes.state === "success") {
860 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
864 async handleTransferCommunity(form: TransferCommunity) {
865 const transferCommunityRes = await HttpService.client.transferCommunity(
868 this.updateCommunityFull(transferCommunityRes);
871 async handleFetchChildren(form: GetComments) {
872 const moreCommentsRes = await HttpService.client.getComments(form);
874 this.state.commentsRes.state == "success" &&
875 moreCommentsRes.state == "success"
877 const newComments = moreCommentsRes.data.comments;
878 // Remove the first comment, since it is the parent
880 const newRes = this.state.commentsRes;
881 newRes.data.comments.push(...newComments);
882 this.setState({ commentsRes: newRes });
886 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
887 const readRes = await HttpService.client.markCommentReplyAsRead(form);
888 this.findAndUpdateCommentReply(readRes);
891 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
892 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
893 await HttpService.client.markPersonMentionAsRead(form);
896 async handleBanFromCommunity(form: BanFromCommunity) {
897 const banRes = await HttpService.client.banFromCommunity(form);
898 this.updateBan(banRes);
901 async handleBanPerson(form: BanPerson) {
902 const banRes = await HttpService.client.banPerson(form);
903 this.updateBan(banRes);
906 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
907 // Maybe not necessary
908 if (banRes.state == "success") {
911 s.postRes.state == "success" &&
912 s.postRes.data.post_view.creator.id ==
913 banRes.data.person_view.person.id
915 s.postRes.data.post_view.creator_banned_from_community =
918 if (s.commentsRes.state == "success") {
919 s.commentsRes.data.comments
920 .filter(c => c.creator.id == banRes.data.person_view.person.id)
922 c => (c.creator_banned_from_community = banRes.data.banned)
930 updateBan(banRes: RequestState<BanPersonResponse>) {
931 // Maybe not necessary
932 if (banRes.state == "success") {
935 s.postRes.state == "success" &&
936 s.postRes.data.post_view.creator.id ==
937 banRes.data.person_view.person.id
939 s.postRes.data.post_view.creator.banned = banRes.data.banned;
941 if (s.commentsRes.state == "success") {
942 s.commentsRes.data.comments
943 .filter(c => c.creator.id == banRes.data.person_view.person.id)
944 .forEach(c => (c.creator.banned = banRes.data.banned));
951 updateCommunity(communityRes: RequestState<CommunityResponse>) {
953 if (s.postRes.state == "success" && communityRes.state == "success") {
954 s.postRes.data.community_view = communityRes.data.community_view;
960 updateCommunityFull(res: RequestState<GetCommunityResponse>) {
962 if (s.postRes.state == "success" && res.state == "success") {
963 s.postRes.data.community_view = res.data.community_view;
964 s.postRes.data.moderators = res.data.moderators;
970 updatePost(post: RequestState<PostResponse>) {
972 if (s.postRes.state == "success" && post.state == "success") {
973 s.postRes.data.post_view = post.data.post_view;
979 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
980 if (purgeRes.state == "success") {
981 toast(i18n.t("purge_success"));
982 this.context.router.history.push(`/`);
986 createAndUpdateComments(res: RequestState<CommentResponse>) {
988 if (s.commentsRes.state === "success" && res.state === "success") {
989 s.commentsRes.data.comments.unshift(res.data.comment_view);
991 // Set finished for the parent
993 getCommentParentId(res.data.comment_view.comment) ?? 0,
1001 findAndUpdateComment(res: RequestState<CommentResponse>) {
1002 this.setState(s => {
1003 if (s.commentsRes.state == "success" && res.state == "success") {
1004 s.commentsRes.data.comments = editComment(
1005 res.data.comment_view,
1006 s.commentsRes.data.comments
1008 s.finished.set(res.data.comment_view.comment.id, true);
1014 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1015 this.setState(s => {
1016 if (s.commentsRes.state == "success" && res.state == "success") {
1017 s.commentsRes.data.comments = editWith(
1018 res.data.comment_reply_view,
1019 s.commentsRes.data.comments
1026 updateModerators(res: RequestState<AddModToCommunityResponse>) {
1027 // Update the moderators
1028 this.setState(s => {
1029 if (s.postRes.state == "success" && res.state == "success") {
1030 s.postRes.data.moderators = res.data.moderators;