X-Git-Url: http://these/git/?a=blobdiff_plain;f=src%2Fshared%2Fcomponents%2Fpost%2Fpost.tsx;h=7eff1b4a4496d2e7115be1851df6e8de4aac59db;hb=4d716e039b8b96e6f4296f7e1ba7ae25d578741e;hp=b602f309285cab92ffcdaa40ed7029c371fd916f;hpb=e0cc7ba3c35994a490038d417686f1198cb58018;p=lemmy-ui.git diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index b602f30..7eff1b4 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -77,6 +77,7 @@ import { isImage, myAuth, restoreScrollPosition, + RouteDataResponse, saveScrollPosition, setIsoData, setupTippy, @@ -93,6 +94,11 @@ import { PostListing } from "./post-listing"; const commentsShownInterval = 15; +type PostData = RouteDataResponse<{ + postRes: GetPostResponse; + commentsRes: GetCommentsResponse; +}>; + interface PostState { postId?: number; commentId?: number; @@ -110,7 +116,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 +175,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 +226,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 +257,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() {