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,
73 } from "lemmy-js-client";
74 import { fetchLimit, relTags, trendingFetchLimit } from "../../config";
79 } from "../../interfaces";
80 import { mdToHtml } from "../../markdown";
86 } from "../../services";
87 import { HttpService, RequestState } from "../../services/HttpService";
88 import { setupTippy } from "../../tippy";
89 import { toast } from "../../toast";
90 import { CommentNodes } from "../comment/comment-nodes";
91 import { DataTypeSelect } from "../common/data-type-select";
92 import { HtmlTags } from "../common/html-tags";
93 import { Icon, Spinner } from "../common/icon";
94 import { ListingTypeSelect } from "../common/listing-type-select";
95 import { Paginator } from "../common/paginator";
96 import { SortSelect } from "../common/sort-select";
97 import { CommunityLink } from "../community/community-link";
98 import { PostListings } from "../post/post-listings";
99 import { SiteSidebar } from "./site-sidebar";
101 interface HomeState {
102 postsRes: RequestState<GetPostsResponse>;
103 commentsRes: RequestState<GetCommentsResponse>;
104 trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
105 showSubscribedMobile: boolean;
106 showTrendingMobile: boolean;
107 showSidebarMobile: boolean;
108 subscribedCollapsed: boolean;
111 siteRes: GetSiteResponse;
112 finished: Map<CommentId, boolean | undefined>;
113 isIsomorphic: boolean;
116 interface HomeProps {
117 listingType?: ListingType;
123 type HomeData = RouteDataResponse<{
124 postsRes: GetPostsResponse;
125 commentsRes: GetCommentsResponse;
126 trendingCommunitiesRes: ListCommunitiesResponse;
129 function getRss(listingType: ListingType) {
130 const { sort } = getHomeQueryParams();
131 const auth = myAuth();
133 let rss: string | undefined = undefined;
135 switch (listingType) {
137 rss = `/feeds/all.xml?sort=${sort}`;
141 rss = `/feeds/local.xml?sort=${sort}`;
145 rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
153 <a href={rss} rel={relTags} title="RSS">
154 <Icon icon="rss" classes="text-muted small" />
156 <link rel="alternate" type="application/atom+xml" href={rss} />
162 function getDataTypeFromQuery(type?: string): DataType {
163 return type ? DataType[type] : DataType.Post;
166 function getListingTypeFromQuery(type?: string): ListingType | undefined {
167 const myListingType =
168 UserService.Instance.myUserInfo?.local_user_view?.local_user
169 ?.default_listing_type;
171 return type ? (type as ListingType) : myListingType;
174 function getSortTypeFromQuery(type?: string): SortType {
176 UserService.Instance.myUserInfo?.local_user_view?.local_user
179 return (type ? (type as SortType) : mySortType) ?? "Active";
182 const getHomeQueryParams = () =>
183 getQueryParams<HomeProps>({
184 sort: getSortTypeFromQuery,
185 listingType: getListingTypeFromQuery,
186 page: getPageFromString,
187 dataType: getDataTypeFromQuery,
190 const MobileButton = ({
195 textKey: NoOptionI18nKeys;
197 onClick: MouseEventHandler<HTMLButtonElement>;
200 className="btn btn-secondary d-inline-block mb-2 me-3"
203 {I18NextService.i18n.t(textKey)}{" "}
204 <Icon icon={show ? `minus-square` : `plus-square`} classes="icon-inline" />
208 const LinkButton = ({
213 translationKey: NoOptionI18nKeys;
215 <Link className="btn btn-secondary d-block" to={path}>
216 {I18NextService.i18n.t(translationKey)}
220 export class Home extends Component<any, HomeState> {
221 private isoData = setIsoData<HomeData>(this.context);
223 postsRes: { state: "empty" },
224 commentsRes: { state: "empty" },
225 trendingCommunitiesRes: { state: "empty" },
227 siteRes: this.isoData.site_res,
228 showSubscribedMobile: false,
229 showTrendingMobile: false,
230 showSidebarMobile: false,
231 subscribedCollapsed: false,
236 constructor(props: any, context: any) {
237 super(props, context);
239 this.handleSortChange = this.handleSortChange.bind(this);
240 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
241 this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
242 this.handlePageChange = this.handlePageChange.bind(this);
244 this.handleCreateComment = this.handleCreateComment.bind(this);
245 this.handleEditComment = this.handleEditComment.bind(this);
246 this.handleSaveComment = this.handleSaveComment.bind(this);
247 this.handleBlockPerson = this.handleBlockPerson.bind(this);
248 this.handleDeleteComment = this.handleDeleteComment.bind(this);
249 this.handleRemoveComment = this.handleRemoveComment.bind(this);
250 this.handleCommentVote = this.handleCommentVote.bind(this);
251 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
252 this.handleAddAdmin = this.handleAddAdmin.bind(this);
253 this.handlePurgePerson = this.handlePurgePerson.bind(this);
254 this.handlePurgeComment = this.handlePurgeComment.bind(this);
255 this.handleCommentReport = this.handleCommentReport.bind(this);
256 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
257 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
258 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
259 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
260 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
261 this.handleBanPerson = this.handleBanPerson.bind(this);
262 this.handlePostEdit = this.handlePostEdit.bind(this);
263 this.handlePostVote = this.handlePostVote.bind(this);
264 this.handlePostReport = this.handlePostReport.bind(this);
265 this.handleLockPost = this.handleLockPost.bind(this);
266 this.handleDeletePost = this.handleDeletePost.bind(this);
267 this.handleRemovePost = this.handleRemovePost.bind(this);
268 this.handleSavePost = this.handleSavePost.bind(this);
269 this.handlePurgePost = this.handlePurgePost.bind(this);
270 this.handleFeaturePost = this.handleFeaturePost.bind(this);
272 // Only fetch the data if coming from another route
273 if (FirstLoadService.isFirstLoad) {
274 const { trendingCommunitiesRes, commentsRes, postsRes } =
275 this.isoData.routeData;
279 trendingCommunitiesRes,
285 HomeCacheService.postsRes = postsRes;
288 this.state.tagline = getRandomFromList(
289 this.state?.siteRes?.taglines ?? []
293 componentWillUnmount() {
294 HomeCacheService.activate();
297 async componentDidMount() {
299 !this.state.isIsomorphic ||
300 !Object.values(this.isoData.routeData).some(
301 res => res.state === "success" || res.state === "failed"
304 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
310 static async fetchInitialData({
313 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
315 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
316 const dataType = getDataTypeFromQuery(urlDataType);
318 getListingTypeFromQuery(listingType) ??
319 site.site_view.local_site.default_post_listing_type;
320 const sort = getSortTypeFromQuery(urlSort);
322 const page = urlPage ? Number(urlPage) : 1;
324 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
325 let commentsRes: RequestState<GetCommentsResponse> = {
329 if (dataType === DataType.Post) {
330 const getPostsForm: GetPosts = {
339 postsRes = await client.getPosts(getPostsForm);
341 const getCommentsForm: GetComments = {
344 sort: postToCommentSortType(sort),
350 commentsRes = await client.getComments(getCommentsForm);
353 const trendingCommunitiesForm: ListCommunities = {
356 limit: trendingFetchLimit,
361 trendingCommunitiesRes: await client.listCommunities(
362 trendingCommunitiesForm
369 get documentTitle(): string {
370 const { name, description } = this.state.siteRes.site_view.site;
372 return description ? `${name} - ${description}` : name;
380 local_site: { site_setup },
386 <div className="home container-lg">
388 title={this.documentTitle}
389 path={this.context.router.route.match.url}
392 <div className="row">
393 <main role="main" className="col-12 col-md-8 col-lg-9">
397 dangerouslySetInnerHTML={mdToHtml(tagline)}
400 <div className="d-block d-md-none">{this.mobileView}</div>
403 <aside className="d-none d-md-block col-md-4 col-lg-3">
412 get hasFollows(): boolean {
413 const mui = UserService.Instance.myUserInfo;
414 return !!mui && mui.follows.length > 0;
420 site_view: { counts, site },
423 showSubscribedMobile,
429 <div className="row">
430 <div className="col-12">
431 {this.hasFollows && (
434 show={showSubscribedMobile}
435 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
440 show={showTrendingMobile}
441 onClick={linkEvent(this, this.handleShowTrendingMobile)}
445 show={showSidebarMobile}
446 onClick={linkEvent(this, this.handleShowSidebarMobile)}
448 {showSidebarMobile && (
453 showLocal={showLocal(this.isoData)}
457 {showTrendingMobile && (
458 <div className="card border-secondary mb-3">
459 {this.trendingCommunities()}
462 {showSubscribedMobile && (
463 <div className="card border-secondary mb-3">
464 {this.subscribedCommunities(true)}
475 site_view: { counts, site },
481 <div id="sidebarContainer">
482 <section id="sidebarMain" className="card border-secondary mb-3">
483 {this.trendingCommunities()}
489 showLocal={showLocal(this.isoData)}
491 {this.hasFollows && (
492 <div className="accordion">
494 id="sidebarSubscribed"
495 className="card border-secondary mb-3"
497 {this.subscribedCommunities(false)}
505 trendingCommunities() {
506 switch (this.state.trendingCommunitiesRes?.state) {
514 const trending = this.state.trendingCommunitiesRes.data.communities;
517 <header className="card-header d-flex align-items-center">
518 <h5 className="mb-0">
519 <T i18nKey="trending_communities">
521 <Link className="text-body" to="/communities">
527 <div className="card-body">
528 {trending.length > 0 && (
529 <ul className="list-inline">
530 {trending.map(cv => (
531 <li key={cv.community.id} className="list-inline-item">
532 <CommunityLink community={cv.community} />
537 {canCreateCommunity(this.state.siteRes) && (
539 path="/create_community"
540 translationKey="create_a_community"
545 translationKey="explore_communities"
554 subscribedCommunities(isMobile = false) {
555 const { subscribedCollapsed } = this.state;
560 className="card-header d-flex align-items-center"
561 id="sidebarSubscribedHeader"
563 <h5 className="mb-0 d-inline">
564 <T class="d-inline" i18nKey="subscribed_to_communities">
566 <Link className="text-body" to="/communities">
574 className="btn btn-sm text-muted"
575 onClick={linkEvent(this, this.handleCollapseSubscribe)}
578 ? I18NextService.i18n.t("expand")
579 : I18NextService.i18n.t("collapse")
583 ? I18NextService.i18n.t("expand")
584 : I18NextService.i18n.t("collapse")
587 aria-controls="sidebarSubscribedBody"
590 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
591 classes="icon-inline"
596 {!subscribedCollapsed && (
598 id="sidebarSubscribedBody"
599 aria-labelledby="sidebarSubscribedHeader"
601 <div className="card-body">
602 <ul className="list-inline mb-0">
603 {UserService.Instance.myUserInfo?.follows.map(cfv => (
605 key={cfv.community.id}
606 className="list-inline-item d-inline-block"
608 <CommunityLink community={cfv.community} />
619 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
621 dataType: urlDataType,
622 listingType: urlListingType,
625 } = getHomeQueryParams();
627 const queryParams: QueryParams<HomeProps> = {
628 dataType: getDataTypeString(dataType ?? urlDataType),
629 listingType: listingType ?? urlListingType,
630 page: (page ?? urlPage).toString(),
631 sort: sort ?? urlSort,
634 this.props.history.push({
636 search: getQueryString(queryParams),
639 if (!this.state.scrolled) {
640 this.setState({ scrolled: true });
641 setTimeout(() => window.scrollTo(0, 0), 0);
644 await this.fetchData();
648 const { page } = getHomeQueryParams();
651 <div className="main-content-wrapper">
655 <Paginator page={page} onChange={this.handlePageChange} />
662 const { dataType } = getHomeQueryParams();
663 const siteRes = this.state.siteRes;
665 if (dataType === DataType.Post) {
666 switch (this.state.postsRes?.state) {
668 return <div style="min-height: 20000px;"></div>;
676 const posts = this.state.postsRes.data.posts;
682 enableDownvotes={enableDownvotes(siteRes)}
683 enableNsfw={enableNsfw(siteRes)}
684 allLanguages={siteRes.all_languages}
685 siteLanguages={siteRes.discussion_languages}
686 onBlockPerson={this.handleBlockPerson}
687 onPostEdit={this.handlePostEdit}
688 onPostVote={this.handlePostVote}
689 onPostReport={this.handlePostReport}
690 onLockPost={this.handleLockPost}
691 onDeletePost={this.handleDeletePost}
692 onRemovePost={this.handleRemovePost}
693 onSavePost={this.handleSavePost}
694 onPurgePerson={this.handlePurgePerson}
695 onPurgePost={this.handlePurgePost}
696 onBanPerson={this.handleBanPerson}
697 onBanPersonFromCommunity={this.handleBanFromCommunity}
698 onAddModToCommunity={this.handleAddModToCommunity}
699 onAddAdmin={this.handleAddAdmin}
700 onTransferCommunity={this.handleTransferCommunity}
701 onFeaturePost={this.handleFeaturePost}
707 switch (this.state.commentsRes.state) {
715 const comments = this.state.commentsRes.data.comments;
718 nodes={commentsToFlatNodes(comments)}
719 viewType={CommentViewType.Flat}
720 finished={this.state.finished}
724 enableDownvotes={enableDownvotes(siteRes)}
725 allLanguages={siteRes.all_languages}
726 siteLanguages={siteRes.discussion_languages}
727 onSaveComment={this.handleSaveComment}
728 onBlockPerson={this.handleBlockPerson}
729 onDeleteComment={this.handleDeleteComment}
730 onRemoveComment={this.handleRemoveComment}
731 onCommentVote={this.handleCommentVote}
732 onCommentReport={this.handleCommentReport}
733 onDistinguishComment={this.handleDistinguishComment}
734 onAddModToCommunity={this.handleAddModToCommunity}
735 onAddAdmin={this.handleAddAdmin}
736 onTransferCommunity={this.handleTransferCommunity}
737 onPurgeComment={this.handlePurgeComment}
738 onPurgePerson={this.handlePurgePerson}
739 onCommentReplyRead={this.handleCommentReplyRead}
740 onPersonMentionRead={this.handlePersonMentionRead}
741 onBanPersonFromCommunity={this.handleBanFromCommunity}
742 onBanPerson={this.handleBanPerson}
743 onCreateComment={this.handleCreateComment}
744 onEditComment={this.handleEditComment}
753 const { listingType, dataType, sort } = getHomeQueryParams();
756 <div className="row align-items-center mb-3 g-3">
757 <div className="col-auto">
760 onChange={this.handleDataTypeChange}
763 <div className="col-auto">
767 this.state.siteRes.site_view.local_site.default_post_listing_type
769 showLocal={showLocal(this.isoData)}
771 onChange={this.handleListingTypeChange}
774 <div className="col-auto">
775 <SortSelect sort={sort} onChange={this.handleSortChange} />
777 <div className="col-auto ps-0">
780 this.state.siteRes.site_view.local_site.default_post_listing_type
787 async fetchTrendingCommunities() {
788 this.setState({ trendingCommunitiesRes: { state: "loading" } });
790 trendingCommunitiesRes: await HttpService.client.listCommunities({
793 limit: trendingFetchLimit,
800 const auth = myAuth();
801 const { dataType, page, listingType, sort } = getHomeQueryParams();
803 if (dataType === DataType.Post) {
804 if (HomeCacheService.active) {
805 const { postsRes, scrollY } = HomeCacheService;
806 HomeCacheService.deactivate();
807 this.setState({ postsRes });
814 this.setState({ postsRes: { state: "loading" } });
816 postsRes: await HttpService.client.getPosts({
826 HomeCacheService.postsRes = this.state.postsRes;
829 this.setState({ commentsRes: { state: "loading" } });
831 commentsRes: await HttpService.client.getComments({
834 sort: postToCommentSortType(sort),
845 handleShowSubscribedMobile(i: Home) {
846 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
849 handleShowTrendingMobile(i: Home) {
850 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
853 handleShowSidebarMobile(i: Home) {
854 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
857 handleCollapseSubscribe(i: Home) {
858 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
861 handlePageChange(page: number) {
862 this.setState({ scrolled: false });
863 this.updateUrl({ page });
866 handleSortChange(val: SortType) {
867 this.setState({ scrolled: false });
868 this.updateUrl({ sort: val, page: 1 });
871 handleListingTypeChange(val: ListingType) {
872 this.setState({ scrolled: false });
873 this.updateUrl({ listingType: val, page: 1 });
876 handleDataTypeChange(val: DataType) {
877 this.setState({ scrolled: false });
878 this.updateUrl({ dataType: val, page: 1 });
881 async handleAddModToCommunity(form: AddModToCommunity) {
882 // TODO not sure what to do here
883 await HttpService.client.addModToCommunity(form);
886 async handlePurgePerson(form: PurgePerson) {
887 const purgePersonRes = await HttpService.client.purgePerson(form);
888 this.purgeItem(purgePersonRes);
891 async handlePurgeComment(form: PurgeComment) {
892 const purgeCommentRes = await HttpService.client.purgeComment(form);
893 this.purgeItem(purgeCommentRes);
896 async handlePurgePost(form: PurgePost) {
897 const purgeRes = await HttpService.client.purgePost(form);
898 this.purgeItem(purgeRes);
901 async handleBlockPerson(form: BlockPerson) {
902 const blockPersonRes = await HttpService.client.blockPerson(form);
903 if (blockPersonRes.state == "success") {
904 updatePersonBlock(blockPersonRes.data);
908 async handleCreateComment(form: CreateComment) {
909 const createCommentRes = await HttpService.client.createComment(form);
910 this.createAndUpdateComments(createCommentRes);
912 return createCommentRes;
915 async handleEditComment(form: EditComment) {
916 const editCommentRes = await HttpService.client.editComment(form);
917 this.findAndUpdateComment(editCommentRes);
919 return editCommentRes;
922 async handleDeleteComment(form: DeleteComment) {
923 const deleteCommentRes = await HttpService.client.deleteComment(form);
924 this.findAndUpdateComment(deleteCommentRes);
927 async handleDeletePost(form: DeletePost) {
928 const deleteRes = await HttpService.client.deletePost(form);
929 this.findAndUpdatePost(deleteRes);
932 async handleRemovePost(form: RemovePost) {
933 const removeRes = await HttpService.client.removePost(form);
934 this.findAndUpdatePost(removeRes);
937 async handleRemoveComment(form: RemoveComment) {
938 const removeCommentRes = await HttpService.client.removeComment(form);
939 this.findAndUpdateComment(removeCommentRes);
942 async handleSaveComment(form: SaveComment) {
943 const saveCommentRes = await HttpService.client.saveComment(form);
944 this.findAndUpdateComment(saveCommentRes);
947 async handleSavePost(form: SavePost) {
948 const saveRes = await HttpService.client.savePost(form);
949 this.findAndUpdatePost(saveRes);
952 async handleFeaturePost(form: FeaturePost) {
953 const featureRes = await HttpService.client.featurePost(form);
954 this.findAndUpdatePost(featureRes);
957 async handleCommentVote(form: CreateCommentLike) {
958 const voteRes = await HttpService.client.likeComment(form);
959 this.findAndUpdateComment(voteRes);
962 async handlePostEdit(form: EditPost) {
963 const res = await HttpService.client.editPost(form);
964 this.findAndUpdatePost(res);
967 async handlePostVote(form: CreatePostLike) {
968 const voteRes = await HttpService.client.likePost(form);
969 this.findAndUpdatePost(voteRes);
972 async handleCommentReport(form: CreateCommentReport) {
973 const reportRes = await HttpService.client.createCommentReport(form);
974 if (reportRes.state == "success") {
975 toast(I18NextService.i18n.t("report_created"));
979 async handlePostReport(form: CreatePostReport) {
980 const reportRes = await HttpService.client.createPostReport(form);
981 if (reportRes.state == "success") {
982 toast(I18NextService.i18n.t("report_created"));
986 async handleLockPost(form: LockPost) {
987 const lockRes = await HttpService.client.lockPost(form);
988 this.findAndUpdatePost(lockRes);
991 async handleDistinguishComment(form: DistinguishComment) {
992 const distinguishRes = await HttpService.client.distinguishComment(form);
993 this.findAndUpdateComment(distinguishRes);
996 async handleAddAdmin(form: AddAdmin) {
997 const addAdminRes = await HttpService.client.addAdmin(form);
999 if (addAdminRes.state == "success") {
1000 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
1004 async handleTransferCommunity(form: TransferCommunity) {
1005 await HttpService.client.transferCommunity(form);
1006 toast(I18NextService.i18n.t("transfer_community"));
1009 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
1010 const readRes = await HttpService.client.markCommentReplyAsRead(form);
1011 this.findAndUpdateCommentReply(readRes);
1014 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
1015 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
1016 await HttpService.client.markPersonMentionAsRead(form);
1019 async handleBanFromCommunity(form: BanFromCommunity) {
1020 const banRes = await HttpService.client.banFromCommunity(form);
1021 this.updateBanFromCommunity(banRes);
1024 async handleBanPerson(form: BanPerson) {
1025 const banRes = await HttpService.client.banPerson(form);
1026 this.updateBan(banRes);
1029 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
1030 // Maybe not necessary
1031 if (banRes.state == "success") {
1032 this.setState(s => {
1033 if (s.postsRes.state == "success") {
1034 s.postsRes.data.posts
1035 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1037 c => (c.creator_banned_from_community = banRes.data.banned)
1040 if (s.commentsRes.state == "success") {
1041 s.commentsRes.data.comments
1042 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1044 c => (c.creator_banned_from_community = banRes.data.banned)
1052 updateBan(banRes: RequestState<BanPersonResponse>) {
1053 // Maybe not necessary
1054 if (banRes.state == "success") {
1055 this.setState(s => {
1056 if (s.postsRes.state == "success") {
1057 s.postsRes.data.posts
1058 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1059 .forEach(c => (c.creator.banned = banRes.data.banned));
1061 if (s.commentsRes.state == "success") {
1062 s.commentsRes.data.comments
1063 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1064 .forEach(c => (c.creator.banned = banRes.data.banned));
1071 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1072 if (purgeRes.state == "success") {
1073 toast(I18NextService.i18n.t("purge_success"));
1074 this.context.router.history.push(`/`);
1078 findAndUpdateComment(res: RequestState<CommentResponse>) {
1079 this.setState(s => {
1080 if (s.commentsRes.state == "success" && res.state == "success") {
1081 s.commentsRes.data.comments = editComment(
1082 res.data.comment_view,
1083 s.commentsRes.data.comments
1085 s.finished.set(res.data.comment_view.comment.id, true);
1091 createAndUpdateComments(res: RequestState<CommentResponse>) {
1092 this.setState(s => {
1093 if (s.commentsRes.state == "success" && res.state == "success") {
1094 s.commentsRes.data.comments.unshift(res.data.comment_view);
1096 // Set finished for the parent
1098 getCommentParentId(res.data.comment_view.comment) ?? 0,
1106 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1107 this.setState(s => {
1108 if (s.commentsRes.state == "success" && res.state == "success") {
1109 s.commentsRes.data.comments = editWith(
1110 res.data.comment_reply_view,
1111 s.commentsRes.data.comments
1118 findAndUpdatePost(res: RequestState<PostResponse>) {
1119 this.setState(s => {
1120 if (s.postsRes.state == "success" && res.state == "success") {
1121 s.postsRes.data.posts = editPost(
1123 s.postsRes.data.posts