X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fpost%2Fpost.tsx;h=eeb713a9cef6538bc483776b3cbb0dbf7313b6b5;hb=53c3cfeade90150b07431386745a24aa699a25ec;hp=1c4b6816baaef582a17c1253e2aa172331ba3076;hpb=3ee47d38b8e6cff675bd29b6b081eb0568360ec5;p=lemmy-ui.git diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 1c4b681..eeb713a 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -1,5 +1,30 @@ +import { + buildCommentsTree, + commentsToFlatNodes, + editComment, + editWith, + enableDownvotes, + enableNsfw, + getCommentIdFromProps, + getCommentParentId, + getDepthFromComment, + getIdFromProps, + myAuth, + setIsoData, + updateCommunityBlock, + updatePersonBlock, +} from "@utils/app"; +import { + isBrowser, + restoreScrollPosition, + saveScrollPosition, +} from "@utils/browser"; +import { debounce, randomStr } from "@utils/helpers"; +import { isImage } from "@utils/media"; +import { RouteDataResponse } from "@utils/types"; import autosize from "autosize"; -import { Component, createRef, linkEvent, RefObject } from "inferno"; +import classNames from "classnames"; +import { Component, RefObject, createRef, linkEvent } from "inferno"; import { AddAdmin, AddModToCommunity, @@ -51,39 +76,16 @@ import { SavePost, TransferCommunity, } from "lemmy-js-client"; -import { i18n } from "../../i18next"; +import { commentTreeMaxDepth } from "../../config"; import { CommentNodeI, CommentViewType, InitialFetchRequest, } from "../../interfaces"; -import { UserService } from "../../services"; -import { FirstLoadService } from "../../services/FirstLoadService"; +import { FirstLoadService, I18NextService, UserService } from "../../services"; import { HttpService, RequestState } from "../../services/HttpService"; -import { - buildCommentsTree, - commentsToFlatNodes, - commentTreeMaxDepth, - editComment, - editWith, - enableDownvotes, - enableNsfw, - getCommentIdFromProps, - getCommentParentId, - getDepthFromComment, - getIdFromProps, - isImage, - myAuth, - restoreScrollPosition, - saveScrollPosition, - setIsoData, - setupTippy, - toast, - updateCommunityBlock, - updatePersonBlock, -} from "../../utils"; -import { isBrowser } from "../../utils/browser/is-browser"; -import { debounce } from "../../utils/helpers/debounce"; +import { setupTippy } from "../../tippy"; +import { toast } from "../../toast"; import { CommentForm } from "../comment/comment-form"; import { CommentNodes } from "../comment/comment-nodes"; import { HtmlTags } from "../common/html-tags"; @@ -93,6 +95,11 @@ import { PostListing } from "./post-listing"; const commentsShownInterval = 15; +type PostData = RouteDataResponse<{ + postRes: GetPostResponse; + commentsRes: GetCommentsResponse; +}>; + interface PostState { postId?: number; commentId?: number; @@ -110,7 +117,7 @@ interface PostState { } export class Post extends Component { - private isoData = setIsoData(this.context); + private isoData = setIsoData(this.context); private commentScrollDebounced: () => void; state: PostState = { postRes: { state: "empty" }, @@ -169,7 +176,7 @@ export class Post extends Component { // Only fetch the data if coming from another route if (FirstLoadService.isFirstLoad) { - const [postRes, commentsRes] = this.isoData.routeData; + const { commentsRes, postRes } = this.isoData.routeData; this.state = { ...this.state, @@ -220,13 +227,12 @@ export class Post extends Component { } } - static fetchInitialData({ - auth, + static async fetchInitialData({ client, path, - }: InitialFetchRequest): Promise[] { + auth, + }: InitialFetchRequest): Promise { const pathSplit = path.split("/"); - const promises: Promise>[] = []; const pathType = pathSplit.at(1); const id = pathSplit.at(2) ? Number(pathSplit.at(2)) : undefined; @@ -252,10 +258,10 @@ export class Post extends Component { commentsForm.parent_id = id; } - promises.push(client.getPost(postForm)); - promises.push(client.getComments(commentsForm)); - - return promises; + return { + postRes: await client.getPost(postForm), + commentsRes: await client.getComments(commentsForm), + }; } componentWillUnmount() { @@ -343,10 +349,11 @@ export class Post extends Component { const res = this.state.postRes.data; return (
-
+
@@ -390,10 +397,10 @@ export class Post extends Component { />
-
{this.sidebar()}
+
+
); } @@ -419,79 +428,102 @@ export class Post extends Component { } render() { - return
{this.renderPostRes()}
; + return
{this.renderPostRes()}
; } sortRadios() { + const radioId = + this.state.postRes.state === "success" + ? this.state.postRes.data.post_view.post.id + : randomStr(); + return ( <> -
+
+ + + +
-
+
+
@@ -580,17 +612,17 @@ export class Post extends Component { {!!this.state.commentId && ( <> {showContextButton && ( )} @@ -824,14 +856,14 @@ export class Post extends Component { async handleCommentReport(form: CreateCommentReport) { const reportRes = await HttpService.client.createCommentReport(form); if (reportRes.state == "success") { - toast(i18n.t("report_created")); + toast(I18NextService.i18n.t("report_created")); } } async handlePostReport(form: CreatePostReport) { const reportRes = await HttpService.client.createPostReport(form); if (reportRes.state == "success") { - toast(i18n.t("report_created")); + toast(I18NextService.i18n.t("report_created")); } } @@ -970,7 +1002,7 @@ export class Post extends Component { purgeItem(purgeRes: RequestState) { if (purgeRes.state == "success") { - toast(i18n.t("purge_success")); + toast(I18NextService.i18n.t("purge_success")); this.context.router.history.push(`/`); } }