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,
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 },
314 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
315 const dataType = getDataTypeFromQuery(urlDataType);
317 // TODO figure out auth default_listingType, default_sort_type
318 const type_ = getListingTypeFromQuery(listingType);
319 const sort = getSortTypeFromQuery(urlSort);
321 const page = urlPage ? Number(urlPage) : 1;
323 let postsRes: RequestState<GetPostsResponse> = { state: "empty" };
324 let commentsRes: RequestState<GetCommentsResponse> = {
328 if (dataType === DataType.Post) {
329 const getPostsForm: GetPosts = {
338 postsRes = await client.getPosts(getPostsForm);
340 const getCommentsForm: GetComments = {
343 sort: postToCommentSortType(sort),
349 commentsRes = await client.getComments(getCommentsForm);
352 const trendingCommunitiesForm: ListCommunities = {
355 limit: trendingFetchLimit,
360 trendingCommunitiesRes: await client.listCommunities(
361 trendingCommunitiesForm
368 get documentTitle(): string {
369 const { name, description } = this.state.siteRes.site_view.site;
371 return description ? `${name} - ${description}` : name;
379 local_site: { site_setup },
385 <div className="home container-lg">
387 title={this.documentTitle}
388 path={this.context.router.route.match.url}
391 <div className="row">
392 <main role="main" className="col-12 col-md-8 col-lg-9">
396 dangerouslySetInnerHTML={mdToHtml(tagline)}
399 <div className="d-block d-md-none">{this.mobileView}</div>
402 <aside className="d-none d-md-block col-md-4 col-lg-3">
411 get hasFollows(): boolean {
412 const mui = UserService.Instance.myUserInfo;
413 return !!mui && mui.follows.length > 0;
419 site_view: { counts, site },
422 showSubscribedMobile,
428 <div className="row">
429 <div className="col-12">
430 {this.hasFollows && (
433 show={showSubscribedMobile}
434 onClick={linkEvent(this, this.handleShowSubscribedMobile)}
439 show={showTrendingMobile}
440 onClick={linkEvent(this, this.handleShowTrendingMobile)}
444 show={showSidebarMobile}
445 onClick={linkEvent(this, this.handleShowSidebarMobile)}
447 {showSidebarMobile && (
452 showLocal={showLocal(this.isoData)}
456 {showTrendingMobile && (
457 <div className="card border-secondary mb-3">
458 {this.trendingCommunities()}
461 {showSubscribedMobile && (
462 <div className="card border-secondary mb-3">
463 {this.subscribedCommunities(true)}
474 site_view: { counts, site },
480 <div id="sidebarContainer">
481 <section id="sidebarMain" className="card border-secondary mb-3">
482 {this.trendingCommunities()}
488 showLocal={showLocal(this.isoData)}
490 {this.hasFollows && (
491 <div className="accordion">
493 id="sidebarSubscribed"
494 className="card border-secondary mb-3"
496 {this.subscribedCommunities(false)}
504 trendingCommunities() {
505 switch (this.state.trendingCommunitiesRes?.state) {
513 const trending = this.state.trendingCommunitiesRes.data.communities;
516 <header className="card-header d-flex align-items-center">
517 <h5 className="mb-0">
518 <T i18nKey="trending_communities">
520 <Link className="text-body" to="/communities">
526 <div className="card-body">
527 {trending.length > 0 && (
528 <ul className="list-inline">
529 {trending.map(cv => (
530 <li key={cv.community.id} className="list-inline-item">
531 <CommunityLink community={cv.community} />
536 {canCreateCommunity(this.state.siteRes) && (
538 path="/create_community"
539 translationKey="create_a_community"
544 translationKey="explore_communities"
553 subscribedCommunities(isMobile = false) {
554 const { subscribedCollapsed } = this.state;
559 className="card-header d-flex align-items-center"
560 id="sidebarSubscribedHeader"
562 <h5 className="mb-0 d-inline">
563 <T class="d-inline" i18nKey="subscribed_to_communities">
565 <Link className="text-body" to="/communities">
573 className="btn btn-sm text-muted"
574 onClick={linkEvent(this, this.handleCollapseSubscribe)}
577 ? I18NextService.i18n.t("expand")
578 : I18NextService.i18n.t("collapse")
582 ? I18NextService.i18n.t("expand")
583 : I18NextService.i18n.t("collapse")
586 aria-controls="sidebarSubscribedBody"
589 icon={`${subscribedCollapsed ? "plus" : "minus"}-square`}
590 classes="icon-inline"
595 {!subscribedCollapsed && (
597 id="sidebarSubscribedBody"
598 aria-labelledby="sidebarSubscribedHeader"
600 <div className="card-body">
601 <ul className="list-inline mb-0">
602 {UserService.Instance.myUserInfo?.follows.map(cfv => (
604 key={cfv.community.id}
605 className="list-inline-item d-inline-block"
607 <CommunityLink community={cfv.community} />
618 async updateUrl({ dataType, listingType, page, sort }: Partial<HomeProps>) {
620 dataType: urlDataType,
621 listingType: urlListingType,
624 } = getHomeQueryParams();
626 const queryParams: QueryParams<HomeProps> = {
627 dataType: getDataTypeString(dataType ?? urlDataType),
628 listingType: listingType ?? urlListingType,
629 page: (page ?? urlPage).toString(),
630 sort: sort ?? urlSort,
633 this.props.history.push({
635 search: getQueryString(queryParams),
638 if (!this.state.scrolled) {
639 this.setState({ scrolled: true });
640 setTimeout(() => window.scrollTo(0, 0), 0);
643 await this.fetchData();
647 const { page } = getHomeQueryParams();
650 <div className="main-content-wrapper">
654 <Paginator page={page} onChange={this.handlePageChange} />
661 const { dataType } = getHomeQueryParams();
662 const siteRes = this.state.siteRes;
664 if (dataType === DataType.Post) {
665 switch (this.state.postsRes?.state) {
667 return <div style="min-height: 20000px;"></div>;
675 const posts = this.state.postsRes.data.posts;
681 enableDownvotes={enableDownvotes(siteRes)}
682 enableNsfw={enableNsfw(siteRes)}
683 allLanguages={siteRes.all_languages}
684 siteLanguages={siteRes.discussion_languages}
685 onBlockPerson={this.handleBlockPerson}
686 onPostEdit={this.handlePostEdit}
687 onPostVote={this.handlePostVote}
688 onPostReport={this.handlePostReport}
689 onLockPost={this.handleLockPost}
690 onDeletePost={this.handleDeletePost}
691 onRemovePost={this.handleRemovePost}
692 onSavePost={this.handleSavePost}
693 onPurgePerson={this.handlePurgePerson}
694 onPurgePost={this.handlePurgePost}
695 onBanPerson={this.handleBanPerson}
696 onBanPersonFromCommunity={this.handleBanFromCommunity}
697 onAddModToCommunity={this.handleAddModToCommunity}
698 onAddAdmin={this.handleAddAdmin}
699 onTransferCommunity={this.handleTransferCommunity}
700 onFeaturePost={this.handleFeaturePost}
706 switch (this.state.commentsRes.state) {
714 const comments = this.state.commentsRes.data.comments;
717 nodes={commentsToFlatNodes(comments)}
718 viewType={CommentViewType.Flat}
719 finished={this.state.finished}
723 enableDownvotes={enableDownvotes(siteRes)}
724 allLanguages={siteRes.all_languages}
725 siteLanguages={siteRes.discussion_languages}
726 onSaveComment={this.handleSaveComment}
727 onBlockPerson={this.handleBlockPerson}
728 onDeleteComment={this.handleDeleteComment}
729 onRemoveComment={this.handleRemoveComment}
730 onCommentVote={this.handleCommentVote}
731 onCommentReport={this.handleCommentReport}
732 onDistinguishComment={this.handleDistinguishComment}
733 onAddModToCommunity={this.handleAddModToCommunity}
734 onAddAdmin={this.handleAddAdmin}
735 onTransferCommunity={this.handleTransferCommunity}
736 onPurgeComment={this.handlePurgeComment}
737 onPurgePerson={this.handlePurgePerson}
738 onCommentReplyRead={this.handleCommentReplyRead}
739 onPersonMentionRead={this.handlePersonMentionRead}
740 onBanPersonFromCommunity={this.handleBanFromCommunity}
741 onBanPerson={this.handleBanPerson}
742 onCreateComment={this.handleCreateComment}
743 onEditComment={this.handleEditComment}
752 const { listingType, dataType, sort } = getHomeQueryParams();
755 <div className="row align-items-center mb-3 g-3">
756 <div className="col-auto">
759 onChange={this.handleDataTypeChange}
762 <div className="col-auto">
765 showLocal={showLocal(this.isoData)}
767 onChange={this.handleListingTypeChange}
770 <div className="col-auto">
771 <SortSelect sort={sort} onChange={this.handleSortChange} />
773 <div className="col-auto ps-0">{getRss(listingType)}</div>
778 async fetchTrendingCommunities() {
779 this.setState({ trendingCommunitiesRes: { state: "loading" } });
781 trendingCommunitiesRes: await HttpService.client.listCommunities({
784 limit: trendingFetchLimit,
791 const auth = myAuth();
792 const { dataType, page, listingType, sort } = getHomeQueryParams();
794 if (dataType === DataType.Post) {
795 if (HomeCacheService.active) {
796 const { postsRes, scrollY } = HomeCacheService;
797 HomeCacheService.deactivate();
798 this.setState({ postsRes });
805 this.setState({ postsRes: { state: "loading" } });
807 postsRes: await HttpService.client.getPosts({
817 HomeCacheService.postsRes = this.state.postsRes;
820 this.setState({ commentsRes: { state: "loading" } });
822 commentsRes: await HttpService.client.getComments({
825 sort: postToCommentSortType(sort),
836 handleShowSubscribedMobile(i: Home) {
837 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
840 handleShowTrendingMobile(i: Home) {
841 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
844 handleShowSidebarMobile(i: Home) {
845 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
848 handleCollapseSubscribe(i: Home) {
849 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
852 handlePageChange(page: number) {
853 this.setState({ scrolled: false });
854 this.updateUrl({ page });
857 handleSortChange(val: SortType) {
858 this.setState({ scrolled: false });
859 this.updateUrl({ sort: val, page: 1 });
862 handleListingTypeChange(val: ListingType) {
863 this.setState({ scrolled: false });
864 this.updateUrl({ listingType: val, page: 1 });
867 handleDataTypeChange(val: DataType) {
868 this.setState({ scrolled: false });
869 this.updateUrl({ dataType: val, page: 1 });
872 async handleAddModToCommunity(form: AddModToCommunity) {
873 // TODO not sure what to do here
874 await HttpService.client.addModToCommunity(form);
877 async handlePurgePerson(form: PurgePerson) {
878 const purgePersonRes = await HttpService.client.purgePerson(form);
879 this.purgeItem(purgePersonRes);
882 async handlePurgeComment(form: PurgeComment) {
883 const purgeCommentRes = await HttpService.client.purgeComment(form);
884 this.purgeItem(purgeCommentRes);
887 async handlePurgePost(form: PurgePost) {
888 const purgeRes = await HttpService.client.purgePost(form);
889 this.purgeItem(purgeRes);
892 async handleBlockPerson(form: BlockPerson) {
893 const blockPersonRes = await HttpService.client.blockPerson(form);
894 if (blockPersonRes.state == "success") {
895 updatePersonBlock(blockPersonRes.data);
899 async handleCreateComment(form: CreateComment) {
900 const createCommentRes = await HttpService.client.createComment(form);
901 this.createAndUpdateComments(createCommentRes);
903 return createCommentRes;
906 async handleEditComment(form: EditComment) {
907 const editCommentRes = await HttpService.client.editComment(form);
908 this.findAndUpdateComment(editCommentRes);
910 return editCommentRes;
913 async handleDeleteComment(form: DeleteComment) {
914 const deleteCommentRes = await HttpService.client.deleteComment(form);
915 this.findAndUpdateComment(deleteCommentRes);
918 async handleDeletePost(form: DeletePost) {
919 const deleteRes = await HttpService.client.deletePost(form);
920 this.findAndUpdatePost(deleteRes);
923 async handleRemovePost(form: RemovePost) {
924 const removeRes = await HttpService.client.removePost(form);
925 this.findAndUpdatePost(removeRes);
928 async handleRemoveComment(form: RemoveComment) {
929 const removeCommentRes = await HttpService.client.removeComment(form);
930 this.findAndUpdateComment(removeCommentRes);
933 async handleSaveComment(form: SaveComment) {
934 const saveCommentRes = await HttpService.client.saveComment(form);
935 this.findAndUpdateComment(saveCommentRes);
938 async handleSavePost(form: SavePost) {
939 const saveRes = await HttpService.client.savePost(form);
940 this.findAndUpdatePost(saveRes);
943 async handleFeaturePost(form: FeaturePost) {
944 const featureRes = await HttpService.client.featurePost(form);
945 this.findAndUpdatePost(featureRes);
948 async handleCommentVote(form: CreateCommentLike) {
949 const voteRes = await HttpService.client.likeComment(form);
950 this.findAndUpdateComment(voteRes);
953 async handlePostEdit(form: EditPost) {
954 const res = await HttpService.client.editPost(form);
955 this.findAndUpdatePost(res);
958 async handlePostVote(form: CreatePostLike) {
959 const voteRes = await HttpService.client.likePost(form);
960 this.findAndUpdatePost(voteRes);
963 async handleCommentReport(form: CreateCommentReport) {
964 const reportRes = await HttpService.client.createCommentReport(form);
965 if (reportRes.state == "success") {
966 toast(I18NextService.i18n.t("report_created"));
970 async handlePostReport(form: CreatePostReport) {
971 const reportRes = await HttpService.client.createPostReport(form);
972 if (reportRes.state == "success") {
973 toast(I18NextService.i18n.t("report_created"));
977 async handleLockPost(form: LockPost) {
978 const lockRes = await HttpService.client.lockPost(form);
979 this.findAndUpdatePost(lockRes);
982 async handleDistinguishComment(form: DistinguishComment) {
983 const distinguishRes = await HttpService.client.distinguishComment(form);
984 this.findAndUpdateComment(distinguishRes);
987 async handleAddAdmin(form: AddAdmin) {
988 const addAdminRes = await HttpService.client.addAdmin(form);
990 if (addAdminRes.state == "success") {
991 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
995 async handleTransferCommunity(form: TransferCommunity) {
996 await HttpService.client.transferCommunity(form);
997 toast(I18NextService.i18n.t("transfer_community"));
1000 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
1001 const readRes = await HttpService.client.markCommentReplyAsRead(form);
1002 this.findAndUpdateCommentReply(readRes);
1005 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
1006 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
1007 await HttpService.client.markPersonMentionAsRead(form);
1010 async handleBanFromCommunity(form: BanFromCommunity) {
1011 const banRes = await HttpService.client.banFromCommunity(form);
1012 this.updateBanFromCommunity(banRes);
1015 async handleBanPerson(form: BanPerson) {
1016 const banRes = await HttpService.client.banPerson(form);
1017 this.updateBan(banRes);
1020 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
1021 // Maybe not necessary
1022 if (banRes.state == "success") {
1023 this.setState(s => {
1024 if (s.postsRes.state == "success") {
1025 s.postsRes.data.posts
1026 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1028 c => (c.creator_banned_from_community = banRes.data.banned)
1031 if (s.commentsRes.state == "success") {
1032 s.commentsRes.data.comments
1033 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1035 c => (c.creator_banned_from_community = banRes.data.banned)
1043 updateBan(banRes: RequestState<BanPersonResponse>) {
1044 // Maybe not necessary
1045 if (banRes.state == "success") {
1046 this.setState(s => {
1047 if (s.postsRes.state == "success") {
1048 s.postsRes.data.posts
1049 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1050 .forEach(c => (c.creator.banned = banRes.data.banned));
1052 if (s.commentsRes.state == "success") {
1053 s.commentsRes.data.comments
1054 .filter(c => c.creator.id == banRes.data.person_view.person.id)
1055 .forEach(c => (c.creator.banned = banRes.data.banned));
1062 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1063 if (purgeRes.state == "success") {
1064 toast(I18NextService.i18n.t("purge_success"));
1065 this.context.router.history.push(`/`);
1069 findAndUpdateComment(res: RequestState<CommentResponse>) {
1070 this.setState(s => {
1071 if (s.commentsRes.state == "success" && res.state == "success") {
1072 s.commentsRes.data.comments = editComment(
1073 res.data.comment_view,
1074 s.commentsRes.data.comments
1076 s.finished.set(res.data.comment_view.comment.id, true);
1082 createAndUpdateComments(res: RequestState<CommentResponse>) {
1083 this.setState(s => {
1084 if (s.commentsRes.state == "success" && res.state == "success") {
1085 s.commentsRes.data.comments.unshift(res.data.comment_view);
1087 // Set finished for the parent
1089 getCommentParentId(res.data.comment_view.comment) ?? 0,
1097 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1098 this.setState(s => {
1099 if (s.commentsRes.state == "success" && res.state == "success") {
1100 s.commentsRes.data.comments = editWith(
1101 res.data.comment_reply_view,
1102 s.commentsRes.data.comments
1109 findAndUpdatePost(res: RequestState<PostResponse>) {
1110 this.setState(s => {
1111 if (s.postsRes.state == "success" && res.state == "success") {
1112 s.postsRes.data.posts = editPost(
1114 s.postsRes.data.posts