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";
81 import { FirstLoadService, I18NextService, UserService } from "../../services";
82 import { HttpService, RequestState } from "../../services/HttpService";
83 import { setupTippy } from "../../tippy";
84 import { toast } from "../../toast";
85 import { CommentNodes } from "../comment/comment-nodes";
86 import { DataTypeSelect } from "../common/data-type-select";
87 import { HtmlTags } from "../common/html-tags";
88 import { Icon, Spinner } from "../common/icon";
89 import { ListingTypeSelect } from "../common/listing-type-select";
90 import { Paginator } from "../common/paginator";
91 import { SortSelect } from "../common/sort-select";
92 import { CommunityLink } from "../community/community-link";
93 import { PostListings } from "../post/post-listings";
94 import { SiteSidebar } from "./site-sidebar";
97 postsRes: RequestState<GetPostsResponse>;
98 commentsRes: RequestState<GetCommentsResponse>;
99 trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
100 showSubscribedMobile: boolean;
101 showTrendingMobile: boolean;
102 showSidebarMobile: boolean;
103 subscribedCollapsed: boolean;
106 siteRes: GetSiteResponse;
107 finished: Map<CommentId, boolean | undefined>;
108 isIsomorphic: boolean;
111 interface HomeProps {
112 listingType: ListingType;
118 type HomeData = RouteDataResponse<{
119 postsRes: GetPostsResponse;
120 commentsRes: GetCommentsResponse;
121 trendingCommunitiesRes: ListCommunitiesResponse;
124 function getRss(listingType: ListingType) {
125 const { sort } = getHomeQueryParams();
126 const auth = myAuth();
128 let rss: string | undefined = undefined;
130 switch (listingType) {
132 rss = `/feeds/all.xml?sort=${sort}`;
136 rss = `/feeds/local.xml?sort=${sort}`;
140 rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
148 <a href={rss} rel={relTags} title="RSS">
149 <Icon icon="rss" classes="text-muted small" />
151 <link rel="alternate" type="application/atom+xml" href={rss} />
157 function getDataTypeFromQuery(type?: string): DataType {
158 return type ? DataType[type] : DataType.Post;
161 function getListingTypeFromQuery(type?: string): ListingType {
162 const myListingType =
163 UserService.Instance.myUserInfo?.local_user_view?.local_user
164 ?.default_listing_type;
166 return (type ? (type as ListingType) : myListingType) ?? "Local";
169 function getSortTypeFromQuery(type?: string): SortType {
171 UserService.Instance.myUserInfo?.local_user_view?.local_user
174 return (type ? (type as SortType) : mySortType) ?? "Active";
177 const getHomeQueryParams = () =>
178 getQueryParams<HomeProps>({
179 sort: getSortTypeFromQuery,
180 listingType: getListingTypeFromQuery,
181 page: getPageFromString,
182 dataType: getDataTypeFromQuery,
185 const MobileButton = ({
190 textKey: NoOptionI18nKeys;
192 onClick: MouseEventHandler<HTMLButtonElement>;
195 className="btn btn-secondary d-inline-block mb-2 me-3"
198 {I18NextService.i18n.t(textKey)}{" "}
199 <Icon icon={show ? `minus-square` : `plus-square`} classes="icon-inline" />
203 const LinkButton = ({
208 translationKey: NoOptionI18nKeys;
210 <Link className="btn btn-secondary d-block" to={path}>
211 {I18NextService.i18n.t(translationKey)}
215 export class Home extends Component<any, HomeState> {
216 private isoData = setIsoData<HomeData>(this.context);
218 postsRes: { state: "empty" },
219 commentsRes: { state: "empty" },
220 trendingCommunitiesRes: { state: "empty" },
222 siteRes: this.isoData.site_res,
223 showSubscribedMobile: false,
224 showTrendingMobile: false,
225 showSidebarMobile: false,
226 subscribedCollapsed: false,
231 constructor(props: any, context: any) {
232 super(props, context);
234 this.handleSortChange = this.handleSortChange.bind(this);
235 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
236 this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
237 this.handlePageChange = this.handlePageChange.bind(this);
239 this.handleCreateComment = this.handleCreateComment.bind(this);
240 this.handleEditComment = this.handleEditComment.bind(this);
241 this.handleSaveComment = this.handleSaveComment.bind(this);
242 this.handleBlockPerson = this.handleBlockPerson.bind(this);
243 this.handleDeleteComment = this.handleDeleteComment.bind(this);
244 this.handleRemoveComment = this.handleRemoveComment.bind(this);
245 this.handleCommentVote = this.handleCommentVote.bind(this);
246 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
247 this.handleAddAdmin = this.handleAddAdmin.bind(this);
248 this.handlePurgePerson = this.handlePurgePerson.bind(this);
249 this.handlePurgeComment = this.handlePurgeComment.bind(this);
250 this.handleCommentReport = this.handleCommentReport.bind(this);
251 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
252 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
253 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
254 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
255 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
256 this.handleBanPerson = this.handleBanPerson.bind(this);
257 this.handlePostEdit = this.handlePostEdit.bind(this);
258 this.handlePostVote = this.handlePostVote.bind(this);
259 this.handlePostReport = this.handlePostReport.bind(this);
260 this.handleLockPost = this.handleLockPost.bind(this);
261 this.handleDeletePost = this.handleDeletePost.bind(this);
262 this.handleRemovePost = this.handleRemovePost.bind(this);
263 this.handleSavePost = this.handleSavePost.bind(this);
264 this.handlePurgePost = this.handlePurgePost.bind(this);
265 this.handleFeaturePost = this.handleFeaturePost.bind(this);
267 // Only fetch the data if coming from another route
268 if (FirstLoadService.isFirstLoad) {
269 const { trendingCommunitiesRes, commentsRes, postsRes } =
270 this.isoData.routeData;
274 trendingCommunitiesRes,
277 tagline: getRandomFromList(this.state?.siteRes?.taglines ?? [])
284 async componentDidMount() {
286 !this.state.isIsomorphic ||
287 !Object.values(this.isoData.routeData).some(
288 res => res.state === "success" || res.state === "failed"
291 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
297 static async fetchInitialData({
300 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
301 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
302 const dataType = getDataTypeFromQuery(urlDataType);
304 // TODO figure out auth default_listingType, default_sort_type
305 const type_ = getListingTypeFromQuery(listingType);
306 const sort = getSortTypeFromQuery(urlSort);
308 const page = urlPage ? Number(urlPage) : 1;
310 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
311 let commentsRes: RequestState<GetCommentsResponse> = {
315 if (dataType === DataType.Post) {
316 const getPostsForm: GetPosts = {
325 postsRes = await client.getPosts(getPostsForm);
327 const getCommentsForm: GetComments = {
330 sort: postToCommentSortType(sort),
336 commentsRes = await client.getComments(getCommentsForm);
339 const trendingCommunitiesForm: ListCommunities = {
342 limit: trendingFetchLimit,
347 trendingCommunitiesRes: await client.listCommunities(
348 trendingCommunitiesForm
355 get documentTitle(): string {
356 const { name, description } = this.state.siteRes.site_view.site;
358 return description ? `${name} - ${description}` : name;
366 local_site: { site_setup },
372 <div className="home container-lg">
374 title={this.documentTitle}
375 path={this.context.router.route.match.url}
378 <div className="row">
379 <main role="main" className="col-12 col-md-8">
383 dangerouslySetInnerHTML={mdToHtml(tagline)}
386 <div className="d-block d-md-none">{this.mobileView}</div>
389 <aside className="d-none d-md-block col-md-4">
398 get hasFollows(): boolean {
399 const mui = UserService.Instance.myUserInfo;
400 return !!mui && mui.follows.length > 0;
406 site_view: { counts, site },
409 showSubscribedMobile,
415 <div className="row">
416 <div className="col-12">
417 {this.hasFollows && (
420 show={showSubscribedMobile}
421 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
426 show={showTrendingMobile}
427 onClick={linkEvent(this, this.handleShowTrendingMobile)}
431 show={showSidebarMobile}
432 onClick={linkEvent(this, this.handleShowSidebarMobile)}
434 {showSidebarMobile && (
439 showLocal={showLocal(this.isoData)}
443 {showTrendingMobile && (
444 <div className="card border-secondary mb-3">
445 {this.trendingCommunities()}
448 {showSubscribedMobile && (
449 <div className="card border-secondary mb-3">
450 {this.subscribedCommunities(true)}
461 site_view: { counts, site },
467 <div id="sidebarContainer">
468 <section id="sidebarMain" className="card border-secondary mb-3">
469 {this.trendingCommunities()}
475 showLocal={showLocal(this.isoData)}
477 {this.hasFollows && (
478 <div className="accordion">
480 id="sidebarSubscribed"
481 className="card border-secondary mb-3"
483 {this.subscribedCommunities(false)}
491 trendingCommunities() {
492 switch (this.state.trendingCommunitiesRes?.state) {
500 const trending = this.state.trendingCommunitiesRes.data.communities;
503 <header className="card-header d-flex align-items-center">
504 <h5 className="mb-0">
505 <T i18nKey="trending_communities">
507 <Link className="text-body" to="/communities">
513 <div className="card-body">
514 {trending.length > 0 && (
515 <ul className="list-inline">
516 {trending.map(cv => (
517 <li key={cv.community.id} className="list-inline-item">
518 <CommunityLink community={cv.community} />
523 {canCreateCommunity(this.state.siteRes) && (
525 path="/create_community"
526 translationKey="create_a_community"
531 translationKey="explore_communities"
540 subscribedCommunities(isMobile = false) {
541 const { subscribedCollapsed } = this.state;
546 className="card-header d-flex align-items-center"
547 id="sidebarSubscribedHeader"
549 <h5 className="mb-0 d-inline">
550 <T class="d-inline" i18nKey="subscribed_to_communities">
552 <Link className="text-body" to="/communities">
560 className="btn btn-sm text-muted"
561 onClick={linkEvent(this, this.handleCollapseSubscribe)}
564 ? I18NextService.i18n.t("expand")
565 : I18NextService.i18n.t("collapse")
569 ? I18NextService.i18n.t("expand")
570 : I18NextService.i18n.t("collapse")
573 aria-controls="sidebarSubscribedBody"
576 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
577 classes="icon-inline"
582 {!subscribedCollapsed && (
584 id="sidebarSubscribedBody"
585 aria-labelledby="sidebarSubscribedHeader"
587 <div className="card-body">
588 <ul className="list-inline mb-0">
589 {UserService.Instance.myUserInfo?.follows.map(cfv => (
591 key={cfv.community.id}
592 className="list-inline-item d-inline-block"
594 <CommunityLink community={cfv.community} />
605 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
607 dataType: urlDataType,
608 listingType: urlListingType,
611 } = getHomeQueryParams();
613 const queryParams: QueryParams<HomeProps> = {
614 dataType: getDataTypeString(dataType ?? urlDataType),
615 listingType: listingType ?? urlListingType,
616 page: (page ?? urlPage).toString(),
617 sort: sort ?? urlSort,
620 this.props.history.push({
622 search: getQueryString(queryParams),
625 if (!this.state.scrolled) {
626 this.setState({ scrolled: true });
627 setTimeout(() => window.scrollTo(0, 0), 0);
630 await this.fetchData();
634 const { page } = getHomeQueryParams();
637 <div className="main-content-wrapper">
641 <Paginator page={page} onChange={this.handlePageChange} />
648 const { dataType } = getHomeQueryParams();
649 const siteRes = this.state.siteRes;
651 if (dataType === DataType.Post) {
652 switch (this.state.postsRes?.state) {
660 const posts = this.state.postsRes.data.posts;
666 enableDownvotes={enableDownvotes(siteRes)}
667 enableNsfw={enableNsfw(siteRes)}
668 allLanguages={siteRes.all_languages}
669 siteLanguages={siteRes.discussion_languages}
670 onBlockPerson={this.handleBlockPerson}
671 onPostEdit={this.handlePostEdit}
672 onPostVote={this.handlePostVote}
673 onPostReport={this.handlePostReport}
674 onLockPost={this.handleLockPost}
675 onDeletePost={this.handleDeletePost}
676 onRemovePost={this.handleRemovePost}
677 onSavePost={this.handleSavePost}
678 onPurgePerson={this.handlePurgePerson}
679 onPurgePost={this.handlePurgePost}
680 onBanPerson={this.handleBanPerson}
681 onBanPersonFromCommunity={this.handleBanFromCommunity}
682 onAddModToCommunity={this.handleAddModToCommunity}
683 onAddAdmin={this.handleAddAdmin}
684 onTransferCommunity={this.handleTransferCommunity}
685 onFeaturePost={this.handleFeaturePost}
691 switch (this.state.commentsRes.state) {
699 const comments = this.state.commentsRes.data.comments;
702 nodes={commentsToFlatNodes(comments)}
703 viewType={CommentViewType.Flat}
704 finished={this.state.finished}
708 enableDownvotes={enableDownvotes(siteRes)}
709 allLanguages={siteRes.all_languages}
710 siteLanguages={siteRes.discussion_languages}
711 onSaveComment={this.handleSaveComment}
712 onBlockPerson={this.handleBlockPerson}
713 onDeleteComment={this.handleDeleteComment}
714 onRemoveComment={this.handleRemoveComment}
715 onCommentVote={this.handleCommentVote}
716 onCommentReport={this.handleCommentReport}
717 onDistinguishComment={this.handleDistinguishComment}
718 onAddModToCommunity={this.handleAddModToCommunity}
719 onAddAdmin={this.handleAddAdmin}
720 onTransferCommunity={this.handleTransferCommunity}
721 onPurgeComment={this.handlePurgeComment}
722 onPurgePerson={this.handlePurgePerson}
723 onCommentReplyRead={this.handleCommentReplyRead}
724 onPersonMentionRead={this.handlePersonMentionRead}
725 onBanPersonFromCommunity={this.handleBanFromCommunity}
726 onBanPerson={this.handleBanPerson}
727 onCreateComment={this.handleCreateComment}
728 onEditComment={this.handleEditComment}
737 const { listingType, dataType, sort } = getHomeQueryParams();
740 <div className="row align-items-center mb-3 g-3">
741 <div className="col-auto">
744 onChange={this.handleDataTypeChange}
747 <div className="col-auto">
750 showLocal={showLocal(this.isoData)}
752 onChange={this.handleListingTypeChange}
755 <div className="col-auto">
756 <SortSelect sort={sort} onChange={this.handleSortChange} />
758 <div className="col-auto ps-0">{getRss(listingType)}</div>
763 async fetchTrendingCommunities() {
764 this.setState({ trendingCommunitiesRes: { state: "loading" } });
766 trendingCommunitiesRes: await HttpService.client.listCommunities({
769 limit: trendingFetchLimit,
776 const auth = myAuth();
777 const { dataType, page, listingType, sort } = getHomeQueryParams();
779 if (dataType === DataType.Post) {
780 this.setState({ postsRes: { state: "loading" } });
782 postsRes: await HttpService.client.getPosts({
792 this.setState({ commentsRes: { state: "loading" } });
794 commentsRes: await HttpService.client.getComments({
797 sort: postToCommentSortType(sort),
808 handleShowSubscribedMobile(i: Home) {
809 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
812 handleShowTrendingMobile(i: Home) {
813 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
816 handleShowSidebarMobile(i: Home) {
817 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
820 handleCollapseSubscribe(i: Home) {
821 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
824 handlePageChange(page: number) {
825 this.setState({ scrolled: false });
826 this.updateUrl({ page });
829 handleSortChange(val: SortType) {
830 this.setState({ scrolled: false });
831 this.updateUrl({ sort: val, page: 1 });
834 handleListingTypeChange(val: ListingType) {
835 this.setState({ scrolled: false });
836 this.updateUrl({ listingType: val, page: 1 });
839 handleDataTypeChange(val: DataType) {
840 this.setState({ scrolled: false });
841 this.updateUrl({ dataType: val, page: 1 });
844 async handleAddModToCommunity(form: AddModToCommunity) {
845 // TODO not sure what to do here
846 await HttpService.client.addModToCommunity(form);
849 async handlePurgePerson(form: PurgePerson) {
850 const purgePersonRes = await HttpService.client.purgePerson(form);
851 this.purgeItem(purgePersonRes);
854 async handlePurgeComment(form: PurgeComment) {
855 const purgeCommentRes = await HttpService.client.purgeComment(form);
856 this.purgeItem(purgeCommentRes);
859 async handlePurgePost(form: PurgePost) {
860 const purgeRes = await HttpService.client.purgePost(form);
861 this.purgeItem(purgeRes);
864 async handleBlockPerson(form: BlockPerson) {
865 const blockPersonRes = await HttpService.client.blockPerson(form);
866 if (blockPersonRes.state == "success") {
867 updatePersonBlock(blockPersonRes.data);
871 async handleCreateComment(form: CreateComment) {
872 const createCommentRes = await HttpService.client.createComment(form);
873 this.createAndUpdateComments(createCommentRes);
875 return createCommentRes;
878 async handleEditComment(form: EditComment) {
879 const editCommentRes = await HttpService.client.editComment(form);
880 this.findAndUpdateComment(editCommentRes);
882 return editCommentRes;
885 async handleDeleteComment(form: DeleteComment) {
886 const deleteCommentRes = await HttpService.client.deleteComment(form);
887 this.findAndUpdateComment(deleteCommentRes);
890 async handleDeletePost(form: DeletePost) {
891 const deleteRes = await HttpService.client.deletePost(form);
892 this.findAndUpdatePost(deleteRes);
895 async handleRemovePost(form: RemovePost) {
896 const removeRes = await HttpService.client.removePost(form);
897 this.findAndUpdatePost(removeRes);
900 async handleRemoveComment(form: RemoveComment) {
901 const removeCommentRes = await HttpService.client.removeComment(form);
902 this.findAndUpdateComment(removeCommentRes);
905 async handleSaveComment(form: SaveComment) {
906 const saveCommentRes = await HttpService.client.saveComment(form);
907 this.findAndUpdateComment(saveCommentRes);
910 async handleSavePost(form: SavePost) {
911 const saveRes = await HttpService.client.savePost(form);
912 this.findAndUpdatePost(saveRes);
915 async handleFeaturePost(form: FeaturePost) {
916 const featureRes = await HttpService.client.featurePost(form);
917 this.findAndUpdatePost(featureRes);
920 async handleCommentVote(form: CreateCommentLike) {
921 const voteRes = await HttpService.client.likeComment(form);
922 this.findAndUpdateComment(voteRes);
925 async handlePostEdit(form: EditPost) {
926 const res = await HttpService.client.editPost(form);
927 this.findAndUpdatePost(res);
930 async handlePostVote(form: CreatePostLike) {
931 const voteRes = await HttpService.client.likePost(form);
932 this.findAndUpdatePost(voteRes);
935 async handleCommentReport(form: CreateCommentReport) {
936 const reportRes = await HttpService.client.createCommentReport(form);
937 if (reportRes.state == "success") {
938 toast(I18NextService.i18n.t("report_created"));
942 async handlePostReport(form: CreatePostReport) {
943 const reportRes = await HttpService.client.createPostReport(form);
944 if (reportRes.state == "success") {
945 toast(I18NextService.i18n.t("report_created"));
949 async handleLockPost(form: LockPost) {
950 const lockRes = await HttpService.client.lockPost(form);
951 this.findAndUpdatePost(lockRes);
954 async handleDistinguishComment(form: DistinguishComment) {
955 const distinguishRes = await HttpService.client.distinguishComment(form);
956 this.findAndUpdateComment(distinguishRes);
959 async handleAddAdmin(form: AddAdmin) {
960 const addAdminRes = await HttpService.client.addAdmin(form);
962 if (addAdminRes.state == "success") {
963 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
967 async handleTransferCommunity(form: TransferCommunity) {
968 await HttpService.client.transferCommunity(form);
969 toast(I18NextService.i18n.t("transfer_community"));
972 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
973 const readRes = await HttpService.client.markCommentReplyAsRead(form);
974 this.findAndUpdateCommentReply(readRes);
977 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
978 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
979 await HttpService.client.markPersonMentionAsRead(form);
982 async handleBanFromCommunity(form: BanFromCommunity) {
983 const banRes = await HttpService.client.banFromCommunity(form);
984 this.updateBanFromCommunity(banRes);
987 async handleBanPerson(form: BanPerson) {
988 const banRes = await HttpService.client.banPerson(form);
989 this.updateBan(banRes);
992 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
993 // Maybe not necessary
994 if (banRes.state == "success") {
996 if (s.postsRes.state == "success") {
997 s.postsRes.data.posts
998 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1000 c => (c.creator_banned_from_community = banRes.data.banned)
1003 if (s.commentsRes.state == "success") {
1004 s.commentsRes.data.comments
1005 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1007 c => (c.creator_banned_from_community = banRes.data.banned)
1015 updateBan(banRes: RequestState<BanPersonResponse>) {
1016 // Maybe not necessary
1017 if (banRes.state == "success") {
1018 this.setState(s => {
1019 if (s.postsRes.state == "success") {
1020 s.postsRes.data.posts
1021 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1022 .forEach(c => (c.creator.banned = banRes.data.banned));
1024 if (s.commentsRes.state == "success") {
1025 s.commentsRes.data.comments
1026 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1027 .forEach(c => (c.creator.banned = banRes.data.banned));
1034 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1035 if (purgeRes.state == "success") {
1036 toast(I18NextService.i18n.t("purge_success"));
1037 this.context.router.history.push(`/`);
1041 findAndUpdateComment(res: RequestState<CommentResponse>) {
1042 this.setState(s => {
1043 if (s.commentsRes.state == "success" && res.state == "success") {
1044 s.commentsRes.data.comments = editComment(
1045 res.data.comment_view,
1046 s.commentsRes.data.comments
1048 s.finished.set(res.data.comment_view.comment.id, true);
1054 createAndUpdateComments(res: RequestState<CommentResponse>) {
1055 this.setState(s => {
1056 if (s.commentsRes.state == "success" && res.state == "success") {
1057 s.commentsRes.data.comments.unshift(res.data.comment_view);
1059 // Set finished for the parent
1061 getCommentParentId(res.data.comment_view.comment) ?? 0,
1069 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1070 this.setState(s => {
1071 if (s.commentsRes.state == "success" && res.state == "success") {
1072 s.commentsRes.data.comments = editWith(
1073 res.data.comment_reply_view,
1074 s.commentsRes.data.comments
1081 findAndUpdatePost(res: RequestState<PostResponse>) {
1082 this.setState(s => {
1083 if (s.postsRes.state == "success" && res.state == "success") {
1084 s.postsRes.data.posts = editPost(
1086 s.postsRes.data.posts