11 postToCommentSortType,
21 } from "@utils/helpers";
22 import { canCreateCommunity } from "@utils/roles";
23 import type { QueryParams } from "@utils/types";
24 import { RouteDataResponse } from "@utils/types";
25 import { NoOptionI18nKeys } from "i18next";
26 import { Component, MouseEventHandler, linkEvent } from "inferno";
27 import { T } from "inferno-i18next-dess";
28 import { Link } from "inferno-router";
33 BanFromCommunityResponse,
57 ListCommunitiesResponse,
60 MarkCommentReplyAsRead,
61 MarkPersonMentionAsRead,
73 } from "lemmy-js-client";
74 import { fetchLimit, relTags, trendingFetchLimit } from "../../config";
79 } from "../../interfaces";
80 import { mdToHtml } from "../../markdown";
86 } from "../../services";
87 import { HttpService, RequestState } from "../../services/HttpService";
88 import { setupTippy } from "../../tippy";
89 import { toast } from "../../toast";
90 import { CommentNodes } from "../comment/comment-nodes";
91 import { DataTypeSelect } from "../common/data-type-select";
92 import { HtmlTags } from "../common/html-tags";
93 import { Icon, Spinner } from "../common/icon";
94 import { ListingTypeSelect } from "../common/listing-type-select";
95 import { Paginator } from "../common/paginator";
96 import { SortSelect } from "../common/sort-select";
97 import { CommunityLink } from "../community/community-link";
98 import { PostListings } from "../post/post-listings";
99 import { SiteSidebar } from "./site-sidebar";
101 interface HomeState {
102 postsRes: RequestState<GetPostsResponse>;
103 commentsRes: RequestState<GetCommentsResponse>;
104 trendingCommunitiesRes: RequestState<ListCommunitiesResponse>;
105 showSubscribedMobile: boolean;
106 showTrendingMobile: boolean;
107 showSidebarMobile: boolean;
108 subscribedCollapsed: boolean;
111 siteRes: GetSiteResponse;
112 finished: Map<CommentId, boolean | undefined>;
113 isIsomorphic: boolean;
116 interface HomeProps {
117 listingType?: ListingType;
123 type HomeData = RouteDataResponse<{
124 postsRes: GetPostsResponse;
125 commentsRes: GetCommentsResponse;
126 trendingCommunitiesRes: ListCommunitiesResponse;
129 function getRss(listingType: ListingType) {
130 const { sort } = getHomeQueryParams();
131 const auth = myAuth();
133 let rss: string | undefined = undefined;
135 switch (listingType) {
137 rss = `/feeds/all.xml?sort=${sort}`;
141 rss = `/feeds/local.xml?sort=${sort}`;
145 rss = auth ? `/feeds/front/${auth}.xml?sort=${sort}` : undefined;
153 <a href={rss} rel={relTags} title="RSS">
154 <Icon icon="rss" classes="text-muted small" />
156 <link rel="alternate" type="application/atom+xml" href={rss} />
162 function getDataTypeFromQuery(type?: string): DataType {
163 return type ? DataType[type] : DataType.Post;
166 function getListingTypeFromQuery(type?: string): ListingType | undefined {
167 const myListingType =
168 UserService.Instance.myUserInfo?.local_user_view?.local_user
169 ?.default_listing_type;
171 return type ? (type as ListingType) : myListingType;
174 function getSortTypeFromQuery(type?: string): SortType {
176 UserService.Instance.myUserInfo?.local_user_view?.local_user
179 return (type ? (type as SortType) : mySortType) ?? "Active";
182 const getHomeQueryParams = () =>
183 getQueryParams<HomeProps>({
184 sort: getSortTypeFromQuery,
185 listingType: getListingTypeFromQuery,
186 page: getPageFromString,
187 dataType: getDataTypeFromQuery,
190 const MobileButton = ({
195 textKey: NoOptionI18nKeys;
197 onClick: MouseEventHandler<HTMLButtonElement>;
200 className="btn btn-secondary d-inline-block mb-2 me-3"
203 {I18NextService.i18n.t(textKey)}{" "}
204 <Icon icon={show ? `minus-square` : `plus-square`} classes="icon-inline" />
208 const LinkButton = ({
213 translationKey: NoOptionI18nKeys;
215 <Link className="btn btn-secondary d-block" to={path}>
216 {I18NextService.i18n.t(translationKey)}
220 export class Home extends Component<any, HomeState> {
221 private isoData = setIsoData<HomeData>(this.context);
223 postsRes: { state: "empty" },
224 commentsRes: { state: "empty" },
225 trendingCommunitiesRes: { state: "empty" },
227 siteRes: this.isoData.site_res,
228 showSubscribedMobile: false,
229 showTrendingMobile: false,
230 showSidebarMobile: false,
231 subscribedCollapsed: false,
236 constructor(props: any, context: any) {
237 super(props, context);
239 this.handleSortChange = this.handleSortChange.bind(this);
240 this.handleListingTypeChange = this.handleListingTypeChange.bind(this);
241 this.handleDataTypeChange = this.handleDataTypeChange.bind(this);
242 this.handlePageChange = this.handlePageChange.bind(this);
244 this.handleCreateComment = this.handleCreateComment.bind(this);
245 this.handleEditComment = this.handleEditComment.bind(this);
246 this.handleSaveComment = this.handleSaveComment.bind(this);
247 this.handleBlockPerson = this.handleBlockPerson.bind(this);
248 this.handleDeleteComment = this.handleDeleteComment.bind(this);
249 this.handleRemoveComment = this.handleRemoveComment.bind(this);
250 this.handleCommentVote = this.handleCommentVote.bind(this);
251 this.handleAddModToCommunity = this.handleAddModToCommunity.bind(this);
252 this.handleAddAdmin = this.handleAddAdmin.bind(this);
253 this.handlePurgePerson = this.handlePurgePerson.bind(this);
254 this.handlePurgeComment = this.handlePurgeComment.bind(this);
255 this.handleCommentReport = this.handleCommentReport.bind(this);
256 this.handleDistinguishComment = this.handleDistinguishComment.bind(this);
257 this.handleTransferCommunity = this.handleTransferCommunity.bind(this);
258 this.handleCommentReplyRead = this.handleCommentReplyRead.bind(this);
259 this.handlePersonMentionRead = this.handlePersonMentionRead.bind(this);
260 this.handleBanFromCommunity = this.handleBanFromCommunity.bind(this);
261 this.handleBanPerson = this.handleBanPerson.bind(this);
262 this.handlePostEdit = this.handlePostEdit.bind(this);
263 this.handlePostVote = this.handlePostVote.bind(this);
264 this.handlePostReport = this.handlePostReport.bind(this);
265 this.handleLockPost = this.handleLockPost.bind(this);
266 this.handleDeletePost = this.handleDeletePost.bind(this);
267 this.handleRemovePost = this.handleRemovePost.bind(this);
268 this.handleSavePost = this.handleSavePost.bind(this);
269 this.handlePurgePost = this.handlePurgePost.bind(this);
270 this.handleFeaturePost = this.handleFeaturePost.bind(this);
272 // Only fetch the data if coming from another route
273 if (FirstLoadService.isFirstLoad) {
274 const { trendingCommunitiesRes, commentsRes, postsRes } =
275 this.isoData.routeData;
279 trendingCommunitiesRes,
285 HomeCacheService.postsRes = postsRes;
288 this.state.tagline = getRandomFromList(this.state?.siteRes?.taglines ?? [])
292 componentWillUnmount() {
293 HomeCacheService.activate();
296 async componentDidMount() {
298 !this.state.isIsomorphic ||
299 !Object.values(this.isoData.routeData).some(
300 res => res.state === "success" || res.state === "failed",
303 await Promise.all([this.fetchTrendingCommunities(), this.fetchData()]);
309 static async fetchInitialData({
312 query: { dataType: urlDataType, listingType, page: urlPage, sort: urlSort },
314 }: InitialFetchRequest<QueryParams<HomeProps>>): Promise<HomeData> {
315 const dataType = getDataTypeFromQuery(urlDataType);
317 getListingTypeFromQuery(listingType) ??
318 site.site_view.local_site.default_post_listing_type;
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">
766 this.state.siteRes.site_view.local_site.default_post_listing_type
768 showLocal={showLocal(this.isoData)}
770 onChange={this.handleListingTypeChange}
773 <div className="col-auto">
774 <SortSelect sort={sort} onChange={this.handleSortChange} />
776 <div className="col-auto ps-0">
779 this.state.siteRes.site_view.local_site.default_post_listing_type,
786 async fetchTrendingCommunities() {
787 this.setState({ trendingCommunitiesRes: { state: "loading" } });
789 trendingCommunitiesRes: await HttpService.client.listCommunities({
792 limit: trendingFetchLimit,
799 const auth = myAuth();
800 const { dataType, page, listingType, sort } = getHomeQueryParams();
802 if (dataType === DataType.Post) {
803 if (HomeCacheService.active) {
804 const { postsRes, scrollY } = HomeCacheService;
805 HomeCacheService.deactivate();
806 this.setState({ postsRes });
813 this.setState({ postsRes: { state: "loading" } });
815 postsRes: await HttpService.client.getPosts({
825 HomeCacheService.postsRes = this.state.postsRes;
828 this.setState({ commentsRes: { state: "loading" } });
830 commentsRes: await HttpService.client.getComments({
833 sort: postToCommentSortType(sort),
844 handleShowSubscribedMobile(i: Home) {
845 i.setState({ showSubscribedMobile: !i.state.showSubscribedMobile });
848 handleShowTrendingMobile(i: Home) {
849 i.setState({ showTrendingMobile: !i.state.showTrendingMobile });
852 handleShowSidebarMobile(i: Home) {
853 i.setState({ showSidebarMobile: !i.state.showSidebarMobile });
856 handleCollapseSubscribe(i: Home) {
857 i.setState({ subscribedCollapsed: !i.state.subscribedCollapsed });
860 handlePageChange(page: number) {
861 this.setState({ scrolled: false });
862 this.updateUrl({ page });
865 handleSortChange(val: SortType) {
866 this.setState({ scrolled: false });
867 this.updateUrl({ sort: val, page: 1 });
870 handleListingTypeChange(val: ListingType) {
871 this.setState({ scrolled: false });
872 this.updateUrl({ listingType: val, page: 1 });
875 handleDataTypeChange(val: DataType) {
876 this.setState({ scrolled: false });
877 this.updateUrl({ dataType: val, page: 1 });
880 async handleAddModToCommunity(form: AddModToCommunity) {
881 // TODO not sure what to do here
882 await HttpService.client.addModToCommunity(form);
885 async handlePurgePerson(form: PurgePerson) {
886 const purgePersonRes = await HttpService.client.purgePerson(form);
887 this.purgeItem(purgePersonRes);
890 async handlePurgeComment(form: PurgeComment) {
891 const purgeCommentRes = await HttpService.client.purgeComment(form);
892 this.purgeItem(purgeCommentRes);
895 async handlePurgePost(form: PurgePost) {
896 const purgeRes = await HttpService.client.purgePost(form);
897 this.purgeItem(purgeRes);
900 async handleBlockPerson(form: BlockPerson) {
901 const blockPersonRes = await HttpService.client.blockPerson(form);
902 if (blockPersonRes.state === "success") {
903 updatePersonBlock(blockPersonRes.data);
907 async handleCreateComment(form: CreateComment) {
908 const createCommentRes = await HttpService.client.createComment(form);
909 this.createAndUpdateComments(createCommentRes);
911 return createCommentRes;
914 async handleEditComment(form: EditComment) {
915 const editCommentRes = await HttpService.client.editComment(form);
916 this.findAndUpdateComment(editCommentRes);
918 return editCommentRes;
921 async handleDeleteComment(form: DeleteComment) {
922 const deleteCommentRes = await HttpService.client.deleteComment(form);
923 this.findAndUpdateComment(deleteCommentRes);
926 async handleDeletePost(form: DeletePost) {
927 const deleteRes = await HttpService.client.deletePost(form);
928 this.findAndUpdatePost(deleteRes);
931 async handleRemovePost(form: RemovePost) {
932 const removeRes = await HttpService.client.removePost(form);
933 this.findAndUpdatePost(removeRes);
936 async handleRemoveComment(form: RemoveComment) {
937 const removeCommentRes = await HttpService.client.removeComment(form);
938 this.findAndUpdateComment(removeCommentRes);
941 async handleSaveComment(form: SaveComment) {
942 const saveCommentRes = await HttpService.client.saveComment(form);
943 this.findAndUpdateComment(saveCommentRes);
946 async handleSavePost(form: SavePost) {
947 const saveRes = await HttpService.client.savePost(form);
948 this.findAndUpdatePost(saveRes);
951 async handleFeaturePost(form: FeaturePost) {
952 const featureRes = await HttpService.client.featurePost(form);
953 this.findAndUpdatePost(featureRes);
956 async handleCommentVote(form: CreateCommentLike) {
957 const voteRes = await HttpService.client.likeComment(form);
958 this.findAndUpdateComment(voteRes);
961 async handlePostEdit(form: EditPost) {
962 const res = await HttpService.client.editPost(form);
963 this.findAndUpdatePost(res);
966 async handlePostVote(form: CreatePostLike) {
967 const voteRes = await HttpService.client.likePost(form);
968 this.findAndUpdatePost(voteRes);
971 async handleCommentReport(form: CreateCommentReport) {
972 const reportRes = await HttpService.client.createCommentReport(form);
973 if (reportRes.state === "success") {
974 toast(I18NextService.i18n.t("report_created"));
978 async handlePostReport(form: CreatePostReport) {
979 const reportRes = await HttpService.client.createPostReport(form);
980 if (reportRes.state === "success") {
981 toast(I18NextService.i18n.t("report_created"));
985 async handleLockPost(form: LockPost) {
986 const lockRes = await HttpService.client.lockPost(form);
987 this.findAndUpdatePost(lockRes);
990 async handleDistinguishComment(form: DistinguishComment) {
991 const distinguishRes = await HttpService.client.distinguishComment(form);
992 this.findAndUpdateComment(distinguishRes);
995 async handleAddAdmin(form: AddAdmin) {
996 const addAdminRes = await HttpService.client.addAdmin(form);
998 if (addAdminRes.state === "success") {
999 this.setState(s => ((s.siteRes.admins = addAdminRes.data.admins), s));
1003 async handleTransferCommunity(form: TransferCommunity) {
1004 await HttpService.client.transferCommunity(form);
1005 toast(I18NextService.i18n.t("transfer_community"));
1008 async handleCommentReplyRead(form: MarkCommentReplyAsRead) {
1009 const readRes = await HttpService.client.markCommentReplyAsRead(form);
1010 this.findAndUpdateCommentReply(readRes);
1013 async handlePersonMentionRead(form: MarkPersonMentionAsRead) {
1014 // TODO not sure what to do here. Maybe it is actually optional, because post doesn't need it.
1015 await HttpService.client.markPersonMentionAsRead(form);
1018 async handleBanFromCommunity(form: BanFromCommunity) {
1019 const banRes = await HttpService.client.banFromCommunity(form);
1020 this.updateBanFromCommunity(banRes);
1023 async handleBanPerson(form: BanPerson) {
1024 const banRes = await HttpService.client.banPerson(form);
1025 this.updateBan(banRes);
1028 updateBanFromCommunity(banRes: RequestState<BanFromCommunityResponse>) {
1029 // Maybe not necessary
1030 if (banRes.state === "success") {
1031 this.setState(s => {
1032 if (s.postsRes.state === "success") {
1033 s.postsRes.data.posts
1034 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1036 c => (c.creator_banned_from_community = banRes.data.banned),
1039 if (s.commentsRes.state === "success") {
1040 s.commentsRes.data.comments
1041 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1043 c => (c.creator_banned_from_community = banRes.data.banned),
1051 updateBan(banRes: RequestState<BanPersonResponse>) {
1052 // Maybe not necessary
1053 if (banRes.state === "success") {
1054 this.setState(s => {
1055 if (s.postsRes.state === "success") {
1056 s.postsRes.data.posts
1057 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1058 .forEach(c => (c.creator.banned = banRes.data.banned));
1060 if (s.commentsRes.state === "success") {
1061 s.commentsRes.data.comments
1062 .filter(c => c.creator.id === banRes.data.person_view.person.id)
1063 .forEach(c => (c.creator.banned = banRes.data.banned));
1070 purgeItem(purgeRes: RequestState<PurgeItemResponse>) {
1071 if (purgeRes.state === "success") {
1072 toast(I18NextService.i18n.t("purge_success"));
1073 this.context.router.history.push(`/`);
1077 findAndUpdateComment(res: RequestState<CommentResponse>) {
1078 this.setState(s => {
1079 if (s.commentsRes.state === "success" && res.state === "success") {
1080 s.commentsRes.data.comments = editComment(
1081 res.data.comment_view,
1082 s.commentsRes.data.comments,
1084 s.finished.set(res.data.comment_view.comment.id, true);
1090 createAndUpdateComments(res: RequestState<CommentResponse>) {
1091 this.setState(s => {
1092 if (s.commentsRes.state === "success" && res.state === "success") {
1093 s.commentsRes.data.comments.unshift(res.data.comment_view);
1095 // Set finished for the parent
1097 getCommentParentId(res.data.comment_view.comment) ?? 0,
1105 findAndUpdateCommentReply(res: RequestState<CommentReplyResponse>) {
1106 this.setState(s => {
1107 if (s.commentsRes.state === "success" && res.state === "success") {
1108 s.commentsRes.data.comments = editWith(
1109 res.data.comment_reply_view,
1110 s.commentsRes.data.comments,
1117 findAndUpdatePost(res: RequestState<PostResponse>) {
1118 this.setState(s => {
1119 if (s.postsRes.state === "success" && res.state === "success") {
1120 s.postsRes.data.posts = editPost(
1122 s.postsRes.data.posts,