11 postToCommentSortType,
16 import { restoreScrollPosition, saveScrollPosition } from "@utils/browser";
22 } from "@utils/helpers";
23 import { canCreateCommunity } from "@utils/roles";
24 import type { QueryParams } from "@utils/types";
25 import { RouteDataResponse } from "@utils/types";
26 import { NoOptionI18nKeys } from "i18next";
27 import { Component, MouseEventHandler, linkEvent } from "inferno";
28 import { T } from "inferno-i18next-dess";
29 import { Link } from "inferno-router";
34 BanFromCommunityResponse,
58 ListCommunitiesResponse,
61 MarkCommentReplyAsRead,
62 MarkPersonMentionAsRead,
74 } from "lemmy-js-client";
75 import { fetchLimit, relTags, trendingFetchLimit } from "../../config";
76 import { i18n } from "../../i18next";
81 } from "../../interfaces";
82 import { mdToHtml } from "../../markdown";
83 import { UserService } from "../../services";
84 import { FirstLoadService } from "../../services/FirstLoadService";
85 import { HttpService, RequestState } from "../../services/HttpService";
86 import { setupTippy } from "../../tippy";
87 import { toast } from "../../toast";
88 import { CommentNodes } from "../comment/comment-nodes";
89 import { DataTypeSelect } from "../common/data-type-select";
90 import { HtmlTags } from "../common/html-tags";
91 import { Icon, Spinner } from "../common/icon";
92 import { ListingTypeSelect } from "../common/listing-type-select";
93 import { Paginator } from "../common/paginator";
94 import { SortSelect } from "../common/sort-select";
95 import { CommunityLink } from "../community/community-link";
96 import { PostListings } from "../post/post-listings";
97 import { SiteSidebar } from "./site-sidebar";
100 postsRes: RequestState<GetPostsResponse>;
101 commentsRes: RequestState<GetCommentsResponse>;
102 trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
103 showSubscribedMobile: boolean;
104 showTrendingMobile: boolean;
105 showSidebarMobile: boolean;
106 subscribedCollapsed: boolean;
108 siteRes: GetSiteResponse;
109 finished: Map<CommentId, boolean | undefined>;
110 isIsomorphic: boolean;
113 interface HomeProps {
114 listingType: ListingType;
120 type HomeData = RouteDataResponse<{
121 postsRes: GetPostsResponse;
122 commentsRes: GetCommentsResponse;
123 trendingCommunitiesRes: ListCommunitiesResponse;
126 function getRss(listingType: ListingType) {
127 const { sort } = getHomeQueryParams();
128 const auth = myAuth();
130 let rss: string | undefined = undefined;
132 switch (listingType) {
134 rss = `/feeds/all.xml?sort=${sort}`;
138 rss = `/feeds/local.xml?sort=${sort}`;
142 rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
150 <a href={rss} rel={relTags} title="RSS">
151 <Icon icon="rss" classes="text-muted small" />
153 <link rel="alternate" type="application/atom+xml" href={rss} />
159 function getDataTypeFromQuery(type?: string): DataType {
160 return type ? DataType[type] : DataType.Post;
163 function getListingTypeFromQuery(type?: string): ListingType {
164 const myListingType =
165 UserService.Instance.myUserInfo?.local_user_view?.local_user
166 ?.default_listing_type;
168 return (type ? (type as ListingType) : myListingType) ?? "Local";
171 function getSortTypeFromQuery(type?: string): SortType {
173 UserService.Instance.myUserInfo?.local_user_view?.local_user
176 return (type ? (type as SortType) : mySortType) ?? "Active";
179 const getHomeQueryParams = () =>
180 getQueryParams<HomeProps>({
181 sort: getSortTypeFromQuery,
182 listingType: getListingTypeFromQuery,
183 page: getPageFromString,
184 dataType: getDataTypeFromQuery,
187 const MobileButton = ({
192 textKey: NoOptionI18nKeys;
194 onClick: MouseEventHandler<HTMLButtonElement>;
197 className="btn btn-secondary d-inline-block mb-2 me-3"
200 {i18n.t(textKey)}{" "}
201 <Icon icon={show ? `minus-square` : `plus-square`} classes="icon-inline" />
205 const LinkButton = ({
210 translationKey: NoOptionI18nKeys;
212 <Link className="btn btn-secondary d-block" to={path}>
213 {i18n.t(translationKey)}
217 export class Home extends Component<any, HomeState> {
218 private isoData = setIsoData<HomeData>(this.context);
220 postsRes: { state: "empty" },
221 commentsRes: { state: "empty" },
222 trendingCommunitiesRes: { state: "empty" },
223 siteRes: this.isoData.site_res,
224 showSubscribedMobile: false,
225 showTrendingMobile: false,
226 showSidebarMobile: false,
227 subscribedCollapsed: false,
232 constructor(props: any, context: any) {
233 super(props, context);
235 this.handleSortChange = this.handleSortChange.bind(this);
236 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
237 this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
238 this.handlePageChange = this.handlePageChange.bind(this);
240 this.handleCreateComment = this.handleCreateComment.bind(this);
241 this.handleEditComment = this.handleEditComment.bind(this);
242 this.handleSaveComment = this.handleSaveComment.bind(this);
243 this.handleBlockPerson = this.handleBlockPerson.bind(this);
244 this.handleDeleteComment = this.handleDeleteComment.bind(this);
245 this.handleRemoveComment = this.handleRemoveComment.bind(this);
246 this.handleCommentVote = this.handleCommentVote.bind(this);
247 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
248 this.handleAddAdmin = this.handleAddAdmin.bind(this);
249 this.handlePurgePerson = this.handlePurgePerson.bind(this);
250 this.handlePurgeComment = this.handlePurgeComment.bind(this);
251 this.handleCommentReport = this.handleCommentReport.bind(this);
252 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
253 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
254 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
255 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
256 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
257 this.handleBanPerson = this.handleBanPerson.bind(this);
258 this.handlePostEdit = this.handlePostEdit.bind(this);
259 this.handlePostVote = this.handlePostVote.bind(this);
260 this.handlePostReport = this.handlePostReport.bind(this);
261 this.handleLockPost = this.handleLockPost.bind(this);
262 this.handleDeletePost = this.handleDeletePost.bind(this);
263 this.handleRemovePost = this.handleRemovePost.bind(this);
264 this.handleSavePost = this.handleSavePost.bind(this);
265 this.handlePurgePost = this.handlePurgePost.bind(this);
266 this.handleFeaturePost = this.handleFeaturePost.bind(this);
268 // Only fetch the data if coming from another route
269 if (FirstLoadService.isFirstLoad) {
270 const { trendingCommunitiesRes, commentsRes, postsRes } =
271 this.isoData.routeData;
275 trendingCommunitiesRes,
278 tagline: getRandomFromList(this.state?.siteRes?.taglines ?? [])
285 async componentDidMount() {
287 !this.state.isIsomorphic ||
288 !Object.values(this.isoData.routeData).some(
289 res => res.state === "success" || res.state === "failed"
292 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
298 componentWillUnmount() {
299 saveScrollPosition(this.context);
302 static async fetchInitialData({
305 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
306 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
307 const dataType = getDataTypeFromQuery(urlDataType);
309 // TODO figure out auth default_listingType, default_sort_type
310 const type_ = getListingTypeFromQuery(listingType);
311 const sort = getSortTypeFromQuery(urlSort);
313 const page = urlPage ? Number(urlPage) : 1;
315 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
316 let commentsRes: RequestState<GetCommentsResponse> = {
320 if (dataType === DataType.Post) {
321 const getPostsForm: GetPosts = {
330 postsRes = await client.getPosts(getPostsForm);
332 const getCommentsForm: GetComments = {
335 sort: postToCommentSortType(sort),
341 commentsRes = await client.getComments(getCommentsForm);
344 const trendingCommunitiesForm: ListCommunities = {
347 limit: trendingFetchLimit,
352 trendingCommunitiesRes: await client.listCommunities(
353 trendingCommunitiesForm
360 get documentTitle(): string {
361 const { name, description } = this.state.siteRes.site_view.site;
363 return description ? `${name} - ${description}` : name;
371 local_site: { site_setup },
377 <div className="home container-lg">
379 title={this.documentTitle}
380 path={this.context.router.route.match.url}
383 <div className="row">
384 <main role="main" className="col-12 col-md-8">
388 dangerouslySetInnerHTML={mdToHtml(tagline)}
391 <div className="d-block d-md-none">{this.mobileView}</div>
394 <aside className="d-none d-md-block col-md-4">
403 get hasFollows(): boolean {
404 const mui = UserService.Instance.myUserInfo;
405 return !!mui && mui.follows.length > 0;
411 site_view: { counts, site },
414 showSubscribedMobile,
420 <div className="row">
421 <div className="col-12">
422 {this.hasFollows && (
425 show={showSubscribedMobile}
426 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
431 show={showTrendingMobile}
432 onClick={linkEvent(this, this.handleShowTrendingMobile)}
436 show={showSidebarMobile}
437 onClick={linkEvent(this, this.handleShowSidebarMobile)}
439 {showSidebarMobile && (
444 showLocal={showLocal(this.isoData)}
448 {showTrendingMobile && (
449 <div className="card border-secondary mb-3">
450 {this.trendingCommunities()}
453 {showSubscribedMobile && (
454 <div className="card border-secondary mb-3">
455 {this.subscribedCommunities(true)}
466 site_view: { counts, site },
472 <div id="sidebarContainer">
473 <section id="sidebarMain" className="card border-secondary mb-3">
474 {this.trendingCommunities()}
480 showLocal={showLocal(this.isoData)}
482 {this.hasFollows && (
483 <div className="accordion">
485 id="sidebarSubscribed"
486 className="card border-secondary mb-3"
488 {this.subscribedCommunities(false)}
496 trendingCommunities() {
497 switch (this.state.trendingCommunitiesRes?.state) {
505 const trending = this.state.trendingCommunitiesRes.data.communities;
508 <header className="card-header d-flex align-items-center">
509 <h5 className="mb-0">
510 <T i18nKey="trending_communities">
512 <Link className="text-body" to="/communities">
518 <div className="card-body">
519 {trending.length > 0 && (
520 <ul className="list-inline">
521 {trending.map(cv => (
522 <li key={cv.community.id} className="list-inline-item">
523 <CommunityLink community={cv.community} />
528 {canCreateCommunity(this.state.siteRes) && (
530 path="/create_community"
531 translationKey="create_a_community"
536 translationKey="explore_communities"
545 subscribedCommunities(isMobile = false) {
546 const { subscribedCollapsed } = this.state;
551 className="card-header d-flex align-items-center"
552 id="sidebarSubscribedHeader"
554 <h5 className="mb-0 d-inline">
555 <T class="d-inline" i18nKey="subscribed_to_communities">
557 <Link className="text-body" to="/communities">
565 className="btn btn-sm text-muted"
566 onClick={linkEvent(this, this.handleCollapseSubscribe)}
568 subscribedCollapsed ? i18n.t("expand") : i18n.t("collapse")
571 subscribedCollapsed ? i18n.t("expand") : i18n.t("collapse")
574 aria-controls="sidebarSubscribedBody"
577 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
578 classes="icon-inline"
583 {!subscribedCollapsed && (
585 id="sidebarSubscribedBody"
586 aria-labelledby="sidebarSubscribedHeader"
588 <div className="card-body">
589 <ul className="list-inline mb-0">
590 {UserService.Instance.myUserInfo?.follows.map(cfv => (
592 key={cfv.community.id}
593 className="list-inline-item d-inline-block"
595 <CommunityLink community={cfv.community} />
606 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
608 dataType: urlDataType,
609 listingType: urlListingType,
612 } = getHomeQueryParams();
614 const queryParams: QueryParams<HomeProps> = {
615 dataType: getDataTypeString(dataType ?? urlDataType),
616 listingType: listingType ?? urlListingType,
617 page: (page ?? urlPage).toString(),
618 sort: sort ?? urlSort,
621 this.props.history.push({
623 search: getQueryString(queryParams),
626 await this.fetchData();
630 const { page } = getHomeQueryParams();
633 <div className="main-content-wrapper">
637 <Paginator page={page} onChange={this.handlePageChange} />
644 const { dataType } = getHomeQueryParams();
645 const siteRes = this.state.siteRes;
647 if (dataType === DataType.Post) {
648 switch (this.state.postsRes.state) {
656 const posts = this.state.postsRes.data.posts;
662 enableDownvotes={enableDownvotes(siteRes)}
663 enableNsfw={enableNsfw(siteRes)}
664 allLanguages={siteRes.all_languages}
665 siteLanguages={siteRes.discussion_languages}
666 onBlockPerson={this.handleBlockPerson}
667 onPostEdit={this.handlePostEdit}
668 onPostVote={this.handlePostVote}
669 onPostReport={this.handlePostReport}
670 onLockPost={this.handleLockPost}
671 onDeletePost={this.handleDeletePost}
672 onRemovePost={this.handleRemovePost}
673 onSavePost={this.handleSavePost}
674 onPurgePerson={this.handlePurgePerson}
675 onPurgePost={this.handlePurgePost}
676 onBanPerson={this.handleBanPerson}
677 onBanPersonFromCommunity={this.handleBanFromCommunity}
678 onAddModToCommunity={this.handleAddModToCommunity}
679 onAddAdmin={this.handleAddAdmin}
680 onTransferCommunity={this.handleTransferCommunity}
681 onFeaturePost={this.handleFeaturePost}
687 switch (this.state.commentsRes.state) {
695 const comments = this.state.commentsRes.data.comments;
698 nodes={commentsToFlatNodes(comments)}
699 viewType={CommentViewType.Flat}
700 finished={this.state.finished}
704 enableDownvotes={enableDownvotes(siteRes)}
705 allLanguages={siteRes.all_languages}
706 siteLanguages={siteRes.discussion_languages}
707 onSaveComment={this.handleSaveComment}
708 onBlockPerson={this.handleBlockPerson}
709 onDeleteComment={this.handleDeleteComment}
710 onRemoveComment={this.handleRemoveComment}
711 onCommentVote={this.handleCommentVote}
712 onCommentReport={this.handleCommentReport}
713 onDistinguishComment={this.handleDistinguishComment}
714 onAddModToCommunity={this.handleAddModToCommunity}
715 onAddAdmin={this.handleAddAdmin}
716 onTransferCommunity={this.handleTransferCommunity}
717 onPurgeComment={this.handlePurgeComment}
718 onPurgePerson={this.handlePurgePerson}
719 onCommentReplyRead={this.handleCommentReplyRead}
720 onPersonMentionRead={this.handlePersonMentionRead}
721 onBanPersonFromCommunity={this.handleBanFromCommunity}
722 onBanPerson={this.handleBanPerson}
723 onCreateComment={this.handleCreateComment}
724 onEditComment={this.handleEditComment}
733 const { listingType, dataType, sort } = getHomeQueryParams();
736 <div className="row align-items-center mb-3 g-3">
737 <div className="col-auto">
740 onChange={this.handleDataTypeChange}
743 <div className="col-auto">
746 showLocal={showLocal(this.isoData)}
748 onChange={this.handleListingTypeChange}
751 <div className="col-auto">
752 <SortSelect sort={sort} onChange={this.handleSortChange} />
754 <div className="col-auto ps-0">{getRss(listingType)}</div>
759 async fetchTrendingCommunities() {
760 this.setState({ trendingCommunitiesRes: { state: "loading" } });
762 trendingCommunitiesRes: await HttpService.client.listCommunities({
765 limit: trendingFetchLimit,
772 const auth = myAuth();
773 const { dataType, page, listingType, sort } = getHomeQueryParams();
775 if (dataType === DataType.Post) {
776 this.setState({ postsRes: { state: "loading" } });
778 postsRes: await HttpService.client.getPosts({
788 this.setState({ commentsRes: { state: "loading" } });
790 commentsRes: await HttpService.client.getComments({
793 sort: postToCommentSortType(sort),
801 restoreScrollPosition(this.context);
805 handleShowSubscribedMobile(i: Home) {
806 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
809 handleShowTrendingMobile(i: Home) {
810 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
813 handleShowSidebarMobile(i: Home) {
814 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
817 handleCollapseSubscribe(i: Home) {
818 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
821 handlePageChange(page: number) {
822 this.updateUrl({ page });
823 window.scrollTo(0, 0);
826 handleSortChange(val: SortType) {
827 this.updateUrl({ sort: val, page: 1 });
828 window.scrollTo(0, 0);
831 handleListingTypeChange(val: ListingType) {
832 this.updateUrl({ listingType: val, page: 1 });
833 window.scrollTo(0, 0);
836 handleDataTypeChange(val: DataType) {
837 this.updateUrl({ dataType: val, page: 1 });
838 window.scrollTo(0, 0);
841 async handleAddModToCommunity(form: AddModToCommunity) {
842 // TODO not sure what to do here
843 await HttpService.client.addModToCommunity(form);
846 async handlePurgePerson(form: PurgePerson) {
847 const purgePersonRes = await HttpService.client.purgePerson(form);
848 this.purgeItem(purgePersonRes);
851 async handlePurgeComment(form: PurgeComment) {
852 const purgeCommentRes = await HttpService.client.purgeComment(form);
853 this.purgeItem(purgeCommentRes);
856 async handlePurgePost(form: PurgePost) {
857 const purgeRes = await HttpService.client.purgePost(form);
858 this.purgeItem(purgeRes);
861 async handleBlockPerson(form: BlockPerson) {
862 const blockPersonRes = await HttpService.client.blockPerson(form);
863 if (blockPersonRes.state == "success") {
864 updatePersonBlock(blockPersonRes.data);
868 async handleCreateComment(form: CreateComment) {
869 const createCommentRes = await HttpService.client.createComment(form);
870 this.createAndUpdateComments(createCommentRes);
872 return createCommentRes;
875 async handleEditComment(form: EditComment) {
876 const editCommentRes = await HttpService.client.editComment(form);
877 this.findAndUpdateComment(editCommentRes);
879 return editCommentRes;
882 async handleDeleteComment(form: DeleteComment) {
883 const deleteCommentRes = await HttpService.client.deleteComment(form);
884 this.findAndUpdateComment(deleteCommentRes);
887 async handleDeletePost(form: DeletePost) {
888 const deleteRes = await HttpService.client.deletePost(form);
889 this.findAndUpdatePost(deleteRes);
892 async handleRemovePost(form: RemovePost) {
893 const removeRes = await HttpService.client.removePost(form);
894 this.findAndUpdatePost(removeRes);
897 async handleRemoveComment(form: RemoveComment) {
898 const removeCommentRes = await HttpService.client.removeComment(form);
899 this.findAndUpdateComment(removeCommentRes);
902 async handleSaveComment(form: SaveComment) {
903 const saveCommentRes = await HttpService.client.saveComment(form);
904 this.findAndUpdateComment(saveCommentRes);
907 async handleSavePost(form: SavePost) {
908 const saveRes = await HttpService.client.savePost(form);
909 this.findAndUpdatePost(saveRes);
912 async handleFeaturePost(form: FeaturePost) {
913 const featureRes = await HttpService.client.featurePost(form);
914 this.findAndUpdatePost(featureRes);
917 async handleCommentVote(form: CreateCommentLike) {
918 const voteRes = await HttpService.client.likeComment(form);
919 this.findAndUpdateComment(voteRes);
922 async handlePostEdit(form: EditPost) {
923 const res = await HttpService.client.editPost(form);
924 this.findAndUpdatePost(res);
927 async handlePostVote(form: CreatePostLike) {
928 const voteRes = await HttpService.client.likePost(form);
929 this.findAndUpdatePost(voteRes);
932 async handleCommentReport(form: CreateCommentReport) {
933 const reportRes = await HttpService.client.createCommentReport(form);
934 if (reportRes.state == "success") {
935 toast(i18n.t("report_created"));
939 async handlePostReport(form: CreatePostReport) {
940 const reportRes = await HttpService.client.createPostReport(form);
941 if (reportRes.state == "success") {
942 toast(i18n.t("report_created"));
946 async handleLockPost(form: LockPost) {
947 const lockRes = await HttpService.client.lockPost(form);
948 this.findAndUpdatePost(lockRes);
951 async handleDistinguishComment(form: DistinguishComment) {
952 const distinguishRes = await HttpService.client.distinguishComment(form);
953 this.findAndUpdateComment(distinguishRes);
956 async handleAddAdmin(form: AddAdmin) {
957 const addAdminRes = await HttpService.client.addAdmin(form);
959 if (addAdminRes.state == "success") {
960 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
964 async handleTransferCommunity(form: TransferCommunity) {
965 await HttpService.client.transferCommunity(form);
966 toast(i18n.t("transfer_community"));
969 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
970 const readRes = await HttpService.client.markCommentReplyAsRead(form);
971 this.findAndUpdateCommentReply(readRes);
974 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
975 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
976 await HttpService.client.markPersonMentionAsRead(form);
979 async handleBanFromCommunity(form: BanFromCommunity) {
980 const banRes = await HttpService.client.banFromCommunity(form);
981 this.updateBanFromCommunity(banRes);
984 async handleBanPerson(form: BanPerson) {
985 const banRes = await HttpService.client.banPerson(form);
986 this.updateBan(banRes);
989 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
990 // Maybe not necessary
991 if (banRes.state == "success") {
993 if (s.postsRes.state == "success") {
994 s.postsRes.data.posts
995 .filter(c => c.creator.id == banRes.data.person_view.person.id)
997 c => (c.creator_banned_from_community = banRes.data.banned)
1000 if (s.commentsRes.state == "success") {
1001 s.commentsRes.data.comments
1002 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1004 c => (c.creator_banned_from_community = banRes.data.banned)
1012 updateBan(banRes: RequestState<BanPersonResponse>) {
1013 // Maybe not necessary
1014 if (banRes.state == "success") {
1015 this.setState(s => {
1016 if (s.postsRes.state == "success") {
1017 s.postsRes.data.posts
1018 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1019 .forEach(c => (c.creator.banned = banRes.data.banned));
1021 if (s.commentsRes.state == "success") {
1022 s.commentsRes.data.comments
1023 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1024 .forEach(c => (c.creator.banned = banRes.data.banned));
1031 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1032 if (purgeRes.state == "success") {
1033 toast(i18n.t("purge_success"));
1034 this.context.router.history.push(`/`);
1038 findAndUpdateComment(res: RequestState<CommentResponse>) {
1039 this.setState(s => {
1040 if (s.commentsRes.state == "success" && res.state == "success") {
1041 s.commentsRes.data.comments = editComment(
1042 res.data.comment_view,
1043 s.commentsRes.data.comments
1045 s.finished.set(res.data.comment_view.comment.id, true);
1051 createAndUpdateComments(res: RequestState<CommentResponse>) {
1052 this.setState(s => {
1053 if (s.commentsRes.state == "success" && res.state == "success") {
1054 s.commentsRes.data.comments.unshift(res.data.comment_view);
1056 // Set finished for the parent
1058 getCommentParentId(res.data.comment_view.comment) ?? 0,
1066 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1067 this.setState(s => {
1068 if (s.commentsRes.state == "success" && res.state == "success") {
1069 s.commentsRes.data.comments = editWith(
1070 res.data.comment_reply_view,
1071 s.commentsRes.data.comments
1078 findAndUpdatePost(res: RequestState<PostResponse>) {
1079 this.setState(s => {
1080 if (s.postsRes.state == "success" && res.state == "success") {
1081 s.postsRes.data.posts = editPost(
1083 s.postsRes.data.posts