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 {
167 const myListingType =
168 UserService.Instance.myUserInfo?.local_user_view?.local_user
169 ?.default_listing_type;
171 return (type ? (type as ListingType) : myListingType) ?? "Local";
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,
282 tagline: getRandomFromList(this.state?.siteRes?.taglines ?? [])
287 HomeCacheService.postsRes = postsRes;
291 componentWillUnmount() {
292 HomeCacheService.activate();
295 async componentDidMount() {
297 !this.state.isIsomorphic ||
298 !Object.values(this.isoData.routeData).some(
299 res => res.state === "success" || res.state === "failed"
302 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
308 static async fetchInitialData({
311 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
312 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
313 const dataType = getDataTypeFromQuery(urlDataType);
315 // TODO figure out auth default_listingType, default_sort_type
316 const type_ = getListingTypeFromQuery(listingType);
317 const sort = getSortTypeFromQuery(urlSort);
319 const page = urlPage ? Number(urlPage) : 1;
321 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
322 let commentsRes: RequestState<GetCommentsResponse> = {
326 if (dataType === DataType.Post) {
327 const getPostsForm: GetPosts = {
336 postsRes = await client.getPosts(getPostsForm);
338 const getCommentsForm: GetComments = {
341 sort: postToCommentSortType(sort),
347 commentsRes = await client.getComments(getCommentsForm);
350 const trendingCommunitiesForm: ListCommunities = {
353 limit: trendingFetchLimit,
358 trendingCommunitiesRes: await client.listCommunities(
359 trendingCommunitiesForm
366 get documentTitle(): string {
367 const { name, description } = this.state.siteRes.site_view.site;
369 return description ? `${name} - ${description}` : name;
377 local_site: { site_setup },
383 <div className="home container-lg">
385 title={this.documentTitle}
386 path={this.context.router.route.match.url}
389 <div className="row">
390 <main role="main" className="col-12 col-md-8">
394 dangerouslySetInnerHTML={mdToHtml(tagline)}
397 <div className="d-block d-md-none">{this.mobileView}</div>
400 <aside className="d-none d-md-block col-md-4">
409 get hasFollows(): boolean {
410 const mui = UserService.Instance.myUserInfo;
411 return !!mui && mui.follows.length > 0;
417 site_view: { counts, site },
420 showSubscribedMobile,
426 <div className="row">
427 <div className="col-12">
428 {this.hasFollows && (
431 show={showSubscribedMobile}
432 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
437 show={showTrendingMobile}
438 onClick={linkEvent(this, this.handleShowTrendingMobile)}
442 show={showSidebarMobile}
443 onClick={linkEvent(this, this.handleShowSidebarMobile)}
445 {showSidebarMobile && (
450 showLocal={showLocal(this.isoData)}
454 {showTrendingMobile && (
455 <div className="card border-secondary mb-3">
456 {this.trendingCommunities()}
459 {showSubscribedMobile && (
460 <div className="card border-secondary mb-3">
461 {this.subscribedCommunities(true)}
472 site_view: { counts, site },
478 <div id="sidebarContainer">
479 <section id="sidebarMain" className="card border-secondary mb-3">
480 {this.trendingCommunities()}
486 showLocal={showLocal(this.isoData)}
488 {this.hasFollows && (
489 <div className="accordion">
491 id="sidebarSubscribed"
492 className="card border-secondary mb-3"
494 {this.subscribedCommunities(false)}
502 trendingCommunities() {
503 switch (this.state.trendingCommunitiesRes?.state) {
511 const trending = this.state.trendingCommunitiesRes.data.communities;
514 <header className="card-header d-flex align-items-center">
515 <h5 className="mb-0">
516 <T i18nKey="trending_communities">
518 <Link className="text-body" to="/communities">
524 <div className="card-body">
525 {trending.length > 0 && (
526 <ul className="list-inline">
527 {trending.map(cv => (
528 <li key={cv.community.id} className="list-inline-item">
529 <CommunityLink community={cv.community} />
534 {canCreateCommunity(this.state.siteRes) && (
536 path="/create_community"
537 translationKey="create_a_community"
542 translationKey="explore_communities"
551 subscribedCommunities(isMobile = false) {
552 const { subscribedCollapsed } = this.state;
557 className="card-header d-flex align-items-center"
558 id="sidebarSubscribedHeader"
560 <h5 className="mb-0 d-inline">
561 <T class="d-inline" i18nKey="subscribed_to_communities">
563 <Link className="text-body" to="/communities">
571 className="btn btn-sm text-muted"
572 onClick={linkEvent(this, this.handleCollapseSubscribe)}
575 ? I18NextService.i18n.t("expand")
576 : I18NextService.i18n.t("collapse")
580 ? I18NextService.i18n.t("expand")
581 : I18NextService.i18n.t("collapse")
584 aria-controls="sidebarSubscribedBody"
587 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
588 classes="icon-inline"
593 {!subscribedCollapsed && (
595 id="sidebarSubscribedBody"
596 aria-labelledby="sidebarSubscribedHeader"
598 <div className="card-body">
599 <ul className="list-inline mb-0">
600 {UserService.Instance.myUserInfo?.follows.map(cfv => (
602 key={cfv.community.id}
603 className="list-inline-item d-inline-block"
605 <CommunityLink community={cfv.community} />
616 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
618 dataType: urlDataType,
619 listingType: urlListingType,
622 } = getHomeQueryParams();
624 const queryParams: QueryParams<HomeProps> = {
625 dataType: getDataTypeString(dataType ?? urlDataType),
626 listingType: listingType ?? urlListingType,
627 page: (page ?? urlPage).toString(),
628 sort: sort ?? urlSort,
631 this.props.history.push({
633 search: getQueryString(queryParams),
636 if (!this.state.scrolled) {
637 this.setState({ scrolled: true });
638 setTimeout(() => window.scrollTo(0, 0), 0);
641 await this.fetchData();
645 const { page } = getHomeQueryParams();
648 <div className="main-content-wrapper">
652 <Paginator page={page} onChange={this.handlePageChange} />
659 const { dataType } = getHomeQueryParams();
660 const siteRes = this.state.siteRes;
662 if (dataType === DataType.Post) {
663 switch (this.state.postsRes?.state) {
665 return <div style="min-height: 20000px;"></div>;
673 const posts = this.state.postsRes.data.posts;
679 enableDownvotes={enableDownvotes(siteRes)}
680 enableNsfw={enableNsfw(siteRes)}
681 allLanguages={siteRes.all_languages}
682 siteLanguages={siteRes.discussion_languages}
683 onBlockPerson={this.handleBlockPerson}
684 onPostEdit={this.handlePostEdit}
685 onPostVote={this.handlePostVote}
686 onPostReport={this.handlePostReport}
687 onLockPost={this.handleLockPost}
688 onDeletePost={this.handleDeletePost}
689 onRemovePost={this.handleRemovePost}
690 onSavePost={this.handleSavePost}
691 onPurgePerson={this.handlePurgePerson}
692 onPurgePost={this.handlePurgePost}
693 onBanPerson={this.handleBanPerson}
694 onBanPersonFromCommunity={this.handleBanFromCommunity}
695 onAddModToCommunity={this.handleAddModToCommunity}
696 onAddAdmin={this.handleAddAdmin}
697 onTransferCommunity={this.handleTransferCommunity}
698 onFeaturePost={this.handleFeaturePost}
704 switch (this.state.commentsRes.state) {
712 const comments = this.state.commentsRes.data.comments;
715 nodes={commentsToFlatNodes(comments)}
716 viewType={CommentViewType.Flat}
717 finished={this.state.finished}
721 enableDownvotes={enableDownvotes(siteRes)}
722 allLanguages={siteRes.all_languages}
723 siteLanguages={siteRes.discussion_languages}
724 onSaveComment={this.handleSaveComment}
725 onBlockPerson={this.handleBlockPerson}
726 onDeleteComment={this.handleDeleteComment}
727 onRemoveComment={this.handleRemoveComment}
728 onCommentVote={this.handleCommentVote}
729 onCommentReport={this.handleCommentReport}
730 onDistinguishComment={this.handleDistinguishComment}
731 onAddModToCommunity={this.handleAddModToCommunity}
732 onAddAdmin={this.handleAddAdmin}
733 onTransferCommunity={this.handleTransferCommunity}
734 onPurgeComment={this.handlePurgeComment}
735 onPurgePerson={this.handlePurgePerson}
736 onCommentReplyRead={this.handleCommentReplyRead}
737 onPersonMentionRead={this.handlePersonMentionRead}
738 onBanPersonFromCommunity={this.handleBanFromCommunity}
739 onBanPerson={this.handleBanPerson}
740 onCreateComment={this.handleCreateComment}
741 onEditComment={this.handleEditComment}
750 const { listingType, dataType, sort } = getHomeQueryParams();
753 <div className="row align-items-center mb-3 g-3">
754 <div className="col-auto">
757 onChange={this.handleDataTypeChange}
760 <div className="col-auto">
763 showLocal={showLocal(this.isoData)}
765 onChange={this.handleListingTypeChange}
768 <div className="col-auto">
769 <SortSelect sort={sort} onChange={this.handleSortChange} />
771 <div className="col-auto ps-0">{getRss(listingType)}</div>
776 async fetchTrendingCommunities() {
777 this.setState({ trendingCommunitiesRes: { state: "loading" } });
779 trendingCommunitiesRes: await HttpService.client.listCommunities({
782 limit: trendingFetchLimit,
789 const auth = myAuth();
790 const { dataType, page, listingType, sort } = getHomeQueryParams();
792 if (dataType === DataType.Post) {
793 if (HomeCacheService.active) {
794 const { postsRes, scrollY } = HomeCacheService;
795 HomeCacheService.deactivate();
796 this.setState({ postsRes });
803 this.setState({ postsRes: { state: "loading" } });
805 postsRes: await HttpService.client.getPosts({
815 HomeCacheService.postsRes = this.state.postsRes;
818 this.setState({ commentsRes: { state: "loading" } });
820 commentsRes: await HttpService.client.getComments({
823 sort: postToCommentSortType(sort),
834 handleShowSubscribedMobile(i: Home) {
835 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
838 handleShowTrendingMobile(i: Home) {
839 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
842 handleShowSidebarMobile(i: Home) {
843 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
846 handleCollapseSubscribe(i: Home) {
847 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
850 handlePageChange(page: number) {
851 this.setState({ scrolled: false });
852 this.updateUrl({ page });
855 handleSortChange(val: SortType) {
856 this.setState({ scrolled: false });
857 this.updateUrl({ sort: val, page: 1 });
860 handleListingTypeChange(val: ListingType) {
861 this.setState({ scrolled: false });
862 this.updateUrl({ listingType: val, page: 1 });
865 handleDataTypeChange(val: DataType) {
866 this.setState({ scrolled: false });
867 this.updateUrl({ dataType: val, page: 1 });
870 async handleAddModToCommunity(form: AddModToCommunity) {
871 // TODO not sure what to do here
872 await HttpService.client.addModToCommunity(form);
875 async handlePurgePerson(form: PurgePerson) {
876 const purgePersonRes = await HttpService.client.purgePerson(form);
877 this.purgeItem(purgePersonRes);
880 async handlePurgeComment(form: PurgeComment) {
881 const purgeCommentRes = await HttpService.client.purgeComment(form);
882 this.purgeItem(purgeCommentRes);
885 async handlePurgePost(form: PurgePost) {
886 const purgeRes = await HttpService.client.purgePost(form);
887 this.purgeItem(purgeRes);
890 async handleBlockPerson(form: BlockPerson) {
891 const blockPersonRes = await HttpService.client.blockPerson(form);
892 if (blockPersonRes.state == "success") {
893 updatePersonBlock(blockPersonRes.data);
897 async handleCreateComment(form: CreateComment) {
898 const createCommentRes = await HttpService.client.createComment(form);
899 this.createAndUpdateComments(createCommentRes);
901 return createCommentRes;
904 async handleEditComment(form: EditComment) {
905 const editCommentRes = await HttpService.client.editComment(form);
906 this.findAndUpdateComment(editCommentRes);
908 return editCommentRes;
911 async handleDeleteComment(form: DeleteComment) {
912 const deleteCommentRes = await HttpService.client.deleteComment(form);
913 this.findAndUpdateComment(deleteCommentRes);
916 async handleDeletePost(form: DeletePost) {
917 const deleteRes = await HttpService.client.deletePost(form);
918 this.findAndUpdatePost(deleteRes);
921 async handleRemovePost(form: RemovePost) {
922 const removeRes = await HttpService.client.removePost(form);
923 this.findAndUpdatePost(removeRes);
926 async handleRemoveComment(form: RemoveComment) {
927 const removeCommentRes = await HttpService.client.removeComment(form);
928 this.findAndUpdateComment(removeCommentRes);
931 async handleSaveComment(form: SaveComment) {
932 const saveCommentRes = await HttpService.client.saveComment(form);
933 this.findAndUpdateComment(saveCommentRes);
936 async handleSavePost(form: SavePost) {
937 const saveRes = await HttpService.client.savePost(form);
938 this.findAndUpdatePost(saveRes);
941 async handleFeaturePost(form: FeaturePost) {
942 const featureRes = await HttpService.client.featurePost(form);
943 this.findAndUpdatePost(featureRes);
946 async handleCommentVote(form: CreateCommentLike) {
947 const voteRes = await HttpService.client.likeComment(form);
948 this.findAndUpdateComment(voteRes);
951 async handlePostEdit(form: EditPost) {
952 const res = await HttpService.client.editPost(form);
953 this.findAndUpdatePost(res);
956 async handlePostVote(form: CreatePostLike) {
957 const voteRes = await HttpService.client.likePost(form);
958 this.findAndUpdatePost(voteRes);
961 async handleCommentReport(form: CreateCommentReport) {
962 const reportRes = await HttpService.client.createCommentReport(form);
963 if (reportRes.state == "success") {
964 toast(I18NextService.i18n.t("report_created"));
968 async handlePostReport(form: CreatePostReport) {
969 const reportRes = await HttpService.client.createPostReport(form);
970 if (reportRes.state == "success") {
971 toast(I18NextService.i18n.t("report_created"));
975 async handleLockPost(form: LockPost) {
976 const lockRes = await HttpService.client.lockPost(form);
977 this.findAndUpdatePost(lockRes);
980 async handleDistinguishComment(form: DistinguishComment) {
981 const distinguishRes = await HttpService.client.distinguishComment(form);
982 this.findAndUpdateComment(distinguishRes);
985 async handleAddAdmin(form: AddAdmin) {
986 const addAdminRes = await HttpService.client.addAdmin(form);
988 if (addAdminRes.state == "success") {
989 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
993 async handleTransferCommunity(form: TransferCommunity) {
994 await HttpService.client.transferCommunity(form);
995 toast(I18NextService.i18n.t("transfer_community"));
998 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
999 const readRes = await HttpService.client.markCommentReplyAsRead(form);
1000 this.findAndUpdateCommentReply(readRes);
1003 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
1004 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
1005 await HttpService.client.markPersonMentionAsRead(form);
1008 async handleBanFromCommunity(form: BanFromCommunity) {
1009 const banRes = await HttpService.client.banFromCommunity(form);
1010 this.updateBanFromCommunity(banRes);
1013 async handleBanPerson(form: BanPerson) {
1014 const banRes = await HttpService.client.banPerson(form);
1015 this.updateBan(banRes);
1018 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
1019 // Maybe not necessary
1020 if (banRes.state == "success") {
1021 this.setState(s => {
1022 if (s.postsRes.state == "success") {
1023 s.postsRes.data.posts
1024 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1026 c => (c.creator_banned_from_community = banRes.data.banned)
1029 if (s.commentsRes.state == "success") {
1030 s.commentsRes.data.comments
1031 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1033 c => (c.creator_banned_from_community = banRes.data.banned)
1041 updateBan(banRes: RequestState<BanPersonResponse>) {
1042 // Maybe not necessary
1043 if (banRes.state == "success") {
1044 this.setState(s => {
1045 if (s.postsRes.state == "success") {
1046 s.postsRes.data.posts
1047 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1048 .forEach(c => (c.creator.banned = banRes.data.banned));
1050 if (s.commentsRes.state == "success") {
1051 s.commentsRes.data.comments
1052 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1053 .forEach(c => (c.creator.banned = banRes.data.banned));
1060 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1061 if (purgeRes.state == "success") {
1062 toast(I18NextService.i18n.t("purge_success"));
1063 this.context.router.history.push(`/`);
1067 findAndUpdateComment(res: RequestState<CommentResponse>) {
1068 this.setState(s => {
1069 if (s.commentsRes.state == "success" && res.state == "success") {
1070 s.commentsRes.data.comments = editComment(
1071 res.data.comment_view,
1072 s.commentsRes.data.comments
1074 s.finished.set(res.data.comment_view.comment.id, true);
1080 createAndUpdateComments(res: RequestState<CommentResponse>) {
1081 this.setState(s => {
1082 if (s.commentsRes.state == "success" && res.state == "success") {
1083 s.commentsRes.data.comments.unshift(res.data.comment_view);
1085 // Set finished for the parent
1087 getCommentParentId(res.data.comment_view.comment) ?? 0,
1095 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1096 this.setState(s => {
1097 if (s.commentsRes.state == "success" && res.state == "success") {
1098 s.commentsRes.data.comments = editWith(
1099 res.data.comment_reply_view,
1100 s.commentsRes.data.comments
1107 findAndUpdatePost(res: RequestState<PostResponse>) {
1108 this.setState(s => {
1109 if (s.postsRes.state == "success" && res.state == "success") {
1110 s.postsRes.data.posts = editPost(
1112 s.postsRes.data.posts