11 postToCommentSortType,
21 } from "@utils/helpers";
22 import { canCreateCommunity } from "@utils/roles";
23 import type { QueryParams } from "@utils/types";
24 import { RouteDataResponse } from "@utils/types";
25 import { NoOptionI18nKeys } from "i18next";
26 import { Component, MouseEventHandler, linkEvent } from "inferno";
27 import { T } from "inferno-i18next-dess";
28 import { Link } from "inferno-router";
33 BanFromCommunityResponse,
57 ListCommunitiesResponse,
60 MarkCommentReplyAsRead,
61 MarkPersonMentionAsRead,
74 } from "lemmy-js-client";
75 import { fetchLimit, relTags, trendingFetchLimit } from "../../config";
80 } from "../../interfaces";
81 import { mdToHtml } from "../../markdown";
87 } from "../../services";
88 import { HttpService, RequestState } from "../../services/HttpService";
89 import { setupTippy } from "../../tippy";
90 import { toast } from "../../toast";
91 import { CommentNodes } from "../comment/comment-nodes";
92 import { DataTypeSelect } from "../common/data-type-select";
93 import { HtmlTags } from "../common/html-tags";
94 import { Icon, Spinner } from "../common/icon";
95 import { ListingTypeSelect } from "../common/listing-type-select";
96 import { Paginator } from "../common/paginator";
97 import { SortSelect } from "../common/sort-select";
98 import { CommunityLink } from "../community/community-link";
99 import { PostListings } from "../post/post-listings";
100 import { SiteSidebar } from "./site-sidebar";
102 interface HomeState {
103 postsRes: RequestState<GetPostsResponse>;
104 commentsRes: RequestState<GetCommentsResponse>;
105 trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
106 showSubscribedMobile: boolean;
107 showTrendingMobile: boolean;
108 showSidebarMobile: boolean;
109 subscribedCollapsed: boolean;
112 siteRes: GetSiteResponse;
113 finished: Map<CommentId, boolean | undefined>;
114 isIsomorphic: boolean;
117 interface HomeProps {
118 listingType?: ListingType;
124 type HomeData = RouteDataResponse<{
125 postsRes: GetPostsResponse;
126 commentsRes: GetCommentsResponse;
127 trendingCommunitiesRes: ListCommunitiesResponse;
130 function getRss(listingType: ListingType) {
131 const { sort } = getHomeQueryParams();
132 const auth = myAuth();
134 let rss: string | undefined = undefined;
136 switch (listingType) {
138 rss = `/feeds/all.xml?sort=${sort}`;
142 rss = `/feeds/local.xml?sort=${sort}`;
146 rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
154 <a href={rss} rel={relTags} title="RSS">
155 <Icon icon="rss" classes="text-muted small" />
157 <link rel="alternate" type="application/atom+xml" href={rss} />
163 function getDataTypeFromQuery(type?: string): DataType {
164 return type ? DataType[type] : DataType.Post;
167 function getListingTypeFromQuery(type?: string): ListingType | undefined {
168 const myListingType =
169 UserService.Instance.myUserInfo?.local_user_view?.local_user
170 ?.default_listing_type;
172 return type ? (type as ListingType) : myListingType;
175 function getSortTypeFromQuery(type?: string): SortType {
177 UserService.Instance.myUserInfo?.local_user_view?.local_user
180 return (type ? (type as SortType) : mySortType) ?? "Active";
183 const getHomeQueryParams = () =>
184 getQueryParams<HomeProps>({
185 sort: getSortTypeFromQuery,
186 listingType: getListingTypeFromQuery,
187 page: getPageFromString,
188 dataType: getDataTypeFromQuery,
191 const MobileButton = ({
196 textKey: NoOptionI18nKeys;
198 onClick: MouseEventHandler<HTMLButtonElement>;
201 className="btn btn-secondary d-inline-block mb-2 me-3"
204 {I18NextService.i18n.t(textKey)}{" "}
205 <Icon icon={show ? `minus-square` : `plus-square`} classes="icon-inline" />
209 const LinkButton = ({
214 translationKey: NoOptionI18nKeys;
216 <Link className="btn btn-secondary d-block" to={path}>
217 {I18NextService.i18n.t(translationKey)}
221 export class Home extends Component<any, HomeState> {
222 private isoData = setIsoData<HomeData>(this.context);
224 postsRes: { state: "empty" },
225 commentsRes: { state: "empty" },
226 trendingCommunitiesRes: { state: "empty" },
228 siteRes: this.isoData.site_res,
229 showSubscribedMobile: false,
230 showTrendingMobile: false,
231 showSidebarMobile: false,
232 subscribedCollapsed: false,
237 constructor(props: any, context: any) {
238 super(props, context);
240 this.handleSortChange = this.handleSortChange.bind(this);
241 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
242 this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
243 this.handlePageChange = this.handlePageChange.bind(this);
245 this.handleCreateComment = this.handleCreateComment.bind(this);
246 this.handleEditComment = this.handleEditComment.bind(this);
247 this.handleSaveComment = this.handleSaveComment.bind(this);
248 this.handleBlockPerson = this.handleBlockPerson.bind(this);
249 this.handleDeleteComment = this.handleDeleteComment.bind(this);
250 this.handleRemoveComment = this.handleRemoveComment.bind(this);
251 this.handleCommentVote = this.handleCommentVote.bind(this);
252 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
253 this.handleAddAdmin = this.handleAddAdmin.bind(this);
254 this.handlePurgePerson = this.handlePurgePerson.bind(this);
255 this.handlePurgeComment = this.handlePurgeComment.bind(this);
256 this.handleCommentReport = this.handleCommentReport.bind(this);
257 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
258 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
259 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
260 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
261 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
262 this.handleBanPerson = this.handleBanPerson.bind(this);
263 this.handlePostEdit = this.handlePostEdit.bind(this);
264 this.handlePostVote = this.handlePostVote.bind(this);
265 this.handlePostReport = this.handlePostReport.bind(this);
266 this.handleLockPost = this.handleLockPost.bind(this);
267 this.handleDeletePost = this.handleDeletePost.bind(this);
268 this.handleRemovePost = this.handleRemovePost.bind(this);
269 this.handleSavePost = this.handleSavePost.bind(this);
270 this.handlePurgePost = this.handlePurgePost.bind(this);
271 this.handleFeaturePost = this.handleFeaturePost.bind(this);
272 this.handleMarkPostAsRead = this.handleMarkPostAsRead.bind(this);
274 // Only fetch the data if coming from another route
275 if (FirstLoadService.isFirstLoad) {
276 const { trendingCommunitiesRes, commentsRes, postsRes } =
277 this.isoData.routeData;
281 trendingCommunitiesRes,
287 HomeCacheService.postsRes = postsRes;
290 this.state.tagline = getRandomFromList(this.state?.siteRes?.taglines ?? [])
294 componentWillUnmount() {
295 HomeCacheService.activate();
298 async componentDidMount() {
300 !this.state.isIsomorphic ||
301 !Object.values(this.isoData.routeData).some(
302 res => res.state === "success" || res.state === "failed",
305 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
311 static async fetchInitialData({
314 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
316 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
317 const dataType = getDataTypeFromQuery(urlDataType);
319 getListingTypeFromQuery(listingType) ??
320 site.site_view.local_site.default_post_listing_type;
321 const sort = getSortTypeFromQuery(urlSort);
323 const page = urlPage ? Number(urlPage) : 1;
325 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
326 let commentsRes: RequestState<GetCommentsResponse> = {
330 if (dataType === DataType.Post) {
331 const getPostsForm: GetPosts = {
340 postsRes = await client.getPosts(getPostsForm);
342 const getCommentsForm: GetComments = {
345 sort: postToCommentSortType(sort),
351 commentsRes = await client.getComments(getCommentsForm);
354 const trendingCommunitiesForm: ListCommunities = {
357 limit: trendingFetchLimit,
362 trendingCommunitiesRes: await client.listCommunities(
363 trendingCommunitiesForm,
370 get documentTitle(): string {
371 const { name, description } = this.state.siteRes.site_view.site;
373 return description ? `${name} - ${description}` : name;
381 local_site: { site_setup },
387 <div className="home container-lg">
389 title={this.documentTitle}
390 path={this.context.router.route.match.url}
393 <div className="row">
394 <main role="main" className="col-12 col-md-8 col-lg-9">
398 dangerouslySetInnerHTML={mdToHtml(tagline)}
401 <div className="d-block d-md-none">{this.mobileView}</div>
404 <aside className="d-none d-md-block col-md-4 col-lg-3">
413 get hasFollows(): boolean {
414 const mui = UserService.Instance.myUserInfo;
415 return !!mui && mui.follows.length > 0;
421 site_view: { counts, site },
424 showSubscribedMobile,
430 <div className="row">
431 <div className="col-12">
432 {this.hasFollows && (
435 show={showSubscribedMobile}
436 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
441 show={showTrendingMobile}
442 onClick={linkEvent(this, this.handleShowTrendingMobile)}
446 show={showSidebarMobile}
447 onClick={linkEvent(this, this.handleShowSidebarMobile)}
449 {showSidebarMobile && (
454 showLocal={showLocal(this.isoData)}
458 {showTrendingMobile && (
459 <div className="card border-secondary mb-3">
460 {this.trendingCommunities()}
463 {showSubscribedMobile && (
464 <div className="card border-secondary mb-3">
465 {this.subscribedCommunities(true)}
476 site_view: { counts, site },
482 <div id="sidebarContainer">
483 <section id="sidebarMain" className="card border-secondary mb-3">
484 {this.trendingCommunities()}
490 showLocal={showLocal(this.isoData)}
492 {this.hasFollows && (
493 <div className="accordion">
495 id="sidebarSubscribed"
496 className="card border-secondary mb-3"
498 {this.subscribedCommunities(false)}
506 trendingCommunities() {
507 switch (this.state.trendingCommunitiesRes?.state) {
515 const trending = this.state.trendingCommunitiesRes.data.communities;
518 <header className="card-header d-flex align-items-center">
519 <h5 className="mb-0">
520 <T i18nKey="trending_communities">
522 <Link className="text-body" to="/communities">
528 <div className="card-body">
529 {trending.length > 0 && (
530 <ul className="list-inline">
531 {trending.map(cv => (
532 <li key={cv.community.id} className="list-inline-item">
533 <CommunityLink community={cv.community} />
538 {canCreateCommunity(this.state.siteRes) && (
540 path="/create_community"
541 translationKey="create_a_community"
546 translationKey="explore_communities"
555 subscribedCommunities(isMobile = false) {
556 const { subscribedCollapsed } = this.state;
561 className="card-header d-flex align-items-center"
562 id="sidebarSubscribedHeader"
564 <h5 className="mb-0 d-inline">
565 <T class="d-inline" i18nKey="subscribed_to_communities">
567 <Link className="text-body" to="/communities">
575 className="btn btn-sm text-muted"
576 onClick={linkEvent(this, this.handleCollapseSubscribe)}
579 ? I18NextService.i18n.t("expand")
580 : I18NextService.i18n.t("collapse")
584 ? I18NextService.i18n.t("expand")
585 : I18NextService.i18n.t("collapse")
588 aria-controls="sidebarSubscribedBody"
591 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
592 classes="icon-inline"
597 {!subscribedCollapsed && (
599 id="sidebarSubscribedBody"
600 aria-labelledby="sidebarSubscribedHeader"
602 <div className="card-body">
603 <ul className="list-inline mb-0">
604 {UserService.Instance.myUserInfo?.follows.map(cfv => (
606 key={cfv.community.id}
607 className="list-inline-item d-inline-block"
609 <CommunityLink community={cfv.community} />
620 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
622 dataType: urlDataType,
623 listingType: urlListingType,
626 } = getHomeQueryParams();
628 const queryParams: QueryParams<HomeProps> = {
629 dataType: getDataTypeString(dataType ?? urlDataType),
630 listingType: listingType ?? urlListingType,
631 page: (page ?? urlPage).toString(),
632 sort: sort ?? urlSort,
635 this.props.history.push({
637 search: getQueryString(queryParams),
640 if (!this.state.scrolled) {
641 this.setState({ scrolled: true });
642 setTimeout(() => window.scrollTo(0, 0), 0);
645 await this.fetchData();
649 const { page } = getHomeQueryParams();
652 <div className="main-content-wrapper">
656 <Paginator page={page} onChange={this.handlePageChange} />
663 const { dataType } = getHomeQueryParams();
664 const siteRes = this.state.siteRes;
666 if (dataType === DataType.Post) {
667 switch (this.state.postsRes?.state) {
669 return <div style="min-height: 20000px;"></div>;
677 const posts = this.state.postsRes.data.posts;
683 enableDownvotes={enableDownvotes(siteRes)}
684 enableNsfw={enableNsfw(siteRes)}
685 allLanguages={siteRes.all_languages}
686 siteLanguages={siteRes.discussion_languages}
687 onBlockPerson={this.handleBlockPerson}
688 onPostEdit={this.handlePostEdit}
689 onPostVote={this.handlePostVote}
690 onPostReport={this.handlePostReport}
691 onLockPost={this.handleLockPost}
692 onDeletePost={this.handleDeletePost}
693 onRemovePost={this.handleRemovePost}
694 onSavePost={this.handleSavePost}
695 onPurgePerson={this.handlePurgePerson}
696 onPurgePost={this.handlePurgePost}
697 onBanPerson={this.handleBanPerson}
698 onBanPersonFromCommunity={this.handleBanFromCommunity}
699 onAddModToCommunity={this.handleAddModToCommunity}
700 onAddAdmin={this.handleAddAdmin}
701 onTransferCommunity={this.handleTransferCommunity}
702 onFeaturePost={this.handleFeaturePost}
703 onMarkPostAsRead={this.handleMarkPostAsRead}
709 switch (this.state.commentsRes.state) {
717 const comments = this.state.commentsRes.data.comments;
720 nodes={commentsToFlatNodes(comments)}
721 viewType={CommentViewType.Flat}
722 finished={this.state.finished}
726 enableDownvotes={enableDownvotes(siteRes)}
727 allLanguages={siteRes.all_languages}
728 siteLanguages={siteRes.discussion_languages}
729 onSaveComment={this.handleSaveComment}
730 onBlockPerson={this.handleBlockPerson}
731 onDeleteComment={this.handleDeleteComment}
732 onRemoveComment={this.handleRemoveComment}
733 onCommentVote={this.handleCommentVote}
734 onCommentReport={this.handleCommentReport}
735 onDistinguishComment={this.handleDistinguishComment}
736 onAddModToCommunity={this.handleAddModToCommunity}
737 onAddAdmin={this.handleAddAdmin}
738 onTransferCommunity={this.handleTransferCommunity}
739 onPurgeComment={this.handlePurgeComment}
740 onPurgePerson={this.handlePurgePerson}
741 onCommentReplyRead={this.handleCommentReplyRead}
742 onPersonMentionRead={this.handlePersonMentionRead}
743 onBanPersonFromCommunity={this.handleBanFromCommunity}
744 onBanPerson={this.handleBanPerson}
745 onCreateComment={this.handleCreateComment}
746 onEditComment={this.handleEditComment}
755 const { listingType, dataType, sort } = getHomeQueryParams();
758 <div className="row align-items-center mb-3 g-3">
759 <div className="col-auto">
762 onChange={this.handleDataTypeChange}
765 <div className="col-auto">
769 this.state.siteRes.site_view.local_site.default_post_listing_type
771 showLocal={showLocal(this.isoData)}
773 onChange={this.handleListingTypeChange}
776 <div className="col-auto">
777 <SortSelect sort={sort} onChange={this.handleSortChange} />
779 <div className="col-auto ps-0">
782 this.state.siteRes.site_view.local_site.default_post_listing_type,
789 async fetchTrendingCommunities() {
790 this.setState({ trendingCommunitiesRes: { state: "loading" } });
792 trendingCommunitiesRes: await HttpService.client.listCommunities({
795 limit: trendingFetchLimit,
802 const auth = myAuth();
803 const { dataType, page, listingType, sort } = getHomeQueryParams();
805 if (dataType === DataType.Post) {
806 if (HomeCacheService.active) {
807 const { postsRes, scrollY } = HomeCacheService;
808 HomeCacheService.deactivate();
809 this.setState({ postsRes });
816 this.setState({ postsRes: { state: "loading" } });
818 postsRes: await HttpService.client.getPosts({
828 HomeCacheService.postsRes = this.state.postsRes;
831 this.setState({ commentsRes: { state: "loading" } });
833 commentsRes: await HttpService.client.getComments({
836 sort: postToCommentSortType(sort),
847 handleShowSubscribedMobile(i: Home) {
848 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
851 handleShowTrendingMobile(i: Home) {
852 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
855 handleShowSidebarMobile(i: Home) {
856 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
859 handleCollapseSubscribe(i: Home) {
860 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
863 handlePageChange(page: number) {
864 this.setState({ scrolled: false });
865 this.updateUrl({ page });
868 handleSortChange(val: SortType) {
869 this.setState({ scrolled: false });
870 this.updateUrl({ sort: val, page: 1 });
873 handleListingTypeChange(val: ListingType) {
874 this.setState({ scrolled: false });
875 this.updateUrl({ listingType: val, page: 1 });
878 handleDataTypeChange(val: DataType) {
879 this.setState({ scrolled: false });
880 this.updateUrl({ dataType: val, page: 1 });
883 async handleAddModToCommunity(form: AddModToCommunity) {
884 // TODO not sure what to do here
885 await HttpService.client.addModToCommunity(form);
888 async handlePurgePerson(form: PurgePerson) {
889 const purgePersonRes = await HttpService.client.purgePerson(form);
890 this.purgeItem(purgePersonRes);
893 async handlePurgeComment(form: PurgeComment) {
894 const purgeCommentRes = await HttpService.client.purgeComment(form);
895 this.purgeItem(purgeCommentRes);
898 async handlePurgePost(form: PurgePost) {
899 const purgeRes = await HttpService.client.purgePost(form);
900 this.purgeItem(purgeRes);
903 async handleBlockPerson(form: BlockPerson) {
904 const blockPersonRes = await HttpService.client.blockPerson(form);
905 if (blockPersonRes.state === "success") {
906 updatePersonBlock(blockPersonRes.data);
910 async handleCreateComment(form: CreateComment) {
911 const createCommentRes = await HttpService.client.createComment(form);
912 this.createAndUpdateComments(createCommentRes);
914 return createCommentRes;
917 async handleEditComment(form: EditComment) {
918 const editCommentRes = await HttpService.client.editComment(form);
919 this.findAndUpdateComment(editCommentRes);
921 return editCommentRes;
924 async handleDeleteComment(form: DeleteComment) {
925 const deleteCommentRes = await HttpService.client.deleteComment(form);
926 this.findAndUpdateComment(deleteCommentRes);
929 async handleDeletePost(form: DeletePost) {
930 const deleteRes = await HttpService.client.deletePost(form);
931 this.findAndUpdatePost(deleteRes);
934 async handleRemovePost(form: RemovePost) {
935 const removeRes = await HttpService.client.removePost(form);
936 this.findAndUpdatePost(removeRes);
939 async handleRemoveComment(form: RemoveComment) {
940 const removeCommentRes = await HttpService.client.removeComment(form);
941 this.findAndUpdateComment(removeCommentRes);
944 async handleSaveComment(form: SaveComment) {
945 const saveCommentRes = await HttpService.client.saveComment(form);
946 this.findAndUpdateComment(saveCommentRes);
949 async handleSavePost(form: SavePost) {
950 const saveRes = await HttpService.client.savePost(form);
951 this.findAndUpdatePost(saveRes);
954 async handleFeaturePost(form: FeaturePost) {
955 const featureRes = await HttpService.client.featurePost(form);
956 this.findAndUpdatePost(featureRes);
959 async handleCommentVote(form: CreateCommentLike) {
960 const voteRes = await HttpService.client.likeComment(form);
961 this.findAndUpdateComment(voteRes);
964 async handlePostEdit(form: EditPost) {
965 const res = await HttpService.client.editPost(form);
966 this.findAndUpdatePost(res);
969 async handlePostVote(form: CreatePostLike) {
970 const voteRes = await HttpService.client.likePost(form);
971 this.findAndUpdatePost(voteRes);
974 async handleCommentReport(form: CreateCommentReport) {
975 const reportRes = await HttpService.client.createCommentReport(form);
976 if (reportRes.state === "success") {
977 toast(I18NextService.i18n.t("report_created"));
981 async handlePostReport(form: CreatePostReport) {
982 const reportRes = await HttpService.client.createPostReport(form);
983 if (reportRes.state === "success") {
984 toast(I18NextService.i18n.t("report_created"));
988 async handleLockPost(form: LockPost) {
989 const lockRes = await HttpService.client.lockPost(form);
990 this.findAndUpdatePost(lockRes);
993 async handleDistinguishComment(form: DistinguishComment) {
994 const distinguishRes = await HttpService.client.distinguishComment(form);
995 this.findAndUpdateComment(distinguishRes);
998 async handleAddAdmin(form: AddAdmin) {
999 const addAdminRes = await HttpService.client.addAdmin(form);
1001 if (addAdminRes.state === "success") {
1002 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
1006 async handleTransferCommunity(form: TransferCommunity) {
1007 await HttpService.client.transferCommunity(form);
1008 toast(I18NextService.i18n.t("transfer_community"));
1011 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
1012 const readRes = await HttpService.client.markCommentReplyAsRead(form);
1013 this.findAndUpdateCommentReply(readRes);
1016 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
1017 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
1018 await HttpService.client.markPersonMentionAsRead(form);
1021 async handleBanFromCommunity(form: BanFromCommunity) {
1022 const banRes = await HttpService.client.banFromCommunity(form);
1023 this.updateBanFromCommunity(banRes);
1026 async handleBanPerson(form: BanPerson) {
1027 const banRes = await HttpService.client.banPerson(form);
1028 this.updateBan(banRes);
1031 async handleMarkPostAsRead(form: MarkPostAsRead) {
1032 const res = await HttpService.client.markPostAsRead(form);
1033 this.findAndUpdatePost(res);
1036 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
1037 // Maybe not necessary
1038 if (banRes.state === "success") {
1039 this.setState(s => {
1040 if (s.postsRes.state === "success") {
1041 s.postsRes.data.posts
1042 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1044 c => (c.creator_banned_from_community = banRes.data.banned),
1047 if (s.commentsRes.state === "success") {
1048 s.commentsRes.data.comments
1049 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1051 c => (c.creator_banned_from_community = banRes.data.banned),
1059 updateBan(banRes: RequestState<BanPersonResponse>) {
1060 // Maybe not necessary
1061 if (banRes.state === "success") {
1062 this.setState(s => {
1063 if (s.postsRes.state === "success") {
1064 s.postsRes.data.posts
1065 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1066 .forEach(c => (c.creator.banned = banRes.data.banned));
1068 if (s.commentsRes.state === "success") {
1069 s.commentsRes.data.comments
1070 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1071 .forEach(c => (c.creator.banned = banRes.data.banned));
1078 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1079 if (purgeRes.state === "success") {
1080 toast(I18NextService.i18n.t("purge_success"));
1081 this.context.router.history.push(`/`);
1085 findAndUpdateComment(res: RequestState<CommentResponse>) {
1086 this.setState(s => {
1087 if (s.commentsRes.state === "success" && res.state === "success") {
1088 s.commentsRes.data.comments = editComment(
1089 res.data.comment_view,
1090 s.commentsRes.data.comments,
1092 s.finished.set(res.data.comment_view.comment.id, true);
1098 createAndUpdateComments(res: RequestState<CommentResponse>) {
1099 this.setState(s => {
1100 if (s.commentsRes.state === "success" && res.state === "success") {
1101 s.commentsRes.data.comments.unshift(res.data.comment_view);
1103 // Set finished for the parent
1105 getCommentParentId(res.data.comment_view.comment) ?? 0,
1113 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1114 this.setState(s => {
1115 if (s.commentsRes.state === "success" && res.state === "success") {
1116 s.commentsRes.data.comments = editWith(
1117 res.data.comment_reply_view,
1118 s.commentsRes.data.comments,
1125 findAndUpdatePost(res: RequestState<PostResponse>) {
1126 this.setState(s => {
1127 if (s.postsRes.state === "success" && res.state === "success") {
1128 s.postsRes.data.posts = editPost(
1130 s.postsRes.data.posts,