From baee5143037f22aec7dbe65af9a79a4d2751225c Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sat, 23 Jan 2021 20:41:23 -0500 Subject: [PATCH] Show cross-posts for isomorphic loading. Fixes #113 --- src/shared/components/post.tsx | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/shared/components/post.tsx b/src/shared/components/post.tsx index 2068305..91e9b01 100644 --- a/src/shared/components/post.tsx +++ b/src/shared/components/post.tsx @@ -101,8 +101,11 @@ export class Post extends Component { this.state.categories = this.isoData.routeData[1].categories; this.state.loading = false; - if (isBrowser() && this.state.commentId) { - this.scrollCommentIntoView(); + if (isBrowser()) { + this.fetchCrossPosts(); + if (this.state.commentId) { + this.scrollCommentIntoView(); + } } } else { this.fetchPost(); @@ -118,6 +121,20 @@ export class Post extends Component { WebSocketService.Instance.send(wsClient.getPost(form)); } + fetchCrossPosts() { + if (this.state.postRes.post_view.post.url) { + let form: Search = { + q: this.state.postRes.post_view.post.url, + type_: SearchType.Url, + sort: SortType.TopAll, + page: 1, + limit: 6, + auth: authField(false), + }; + WebSocketService.Instance.send(wsClient.search(form)); + } + } + static fetchInitialData(req: InitialFetchRequest): Promise[] { let pathSplit = req.path.split('/'); let promises: Promise[] = []; @@ -463,18 +480,7 @@ export class Post extends Component { this.state.loading = false; // Get cross-posts - if (this.state.postRes.post_view.post.url) { - let form: Search = { - q: this.state.postRes.post_view.post.url, - type_: SearchType.Url, - sort: SortType.TopAll, - page: 1, - limit: 6, - auth: authField(false), - }; - WebSocketService.Instance.send(wsClient.search(form)); - } - + this.fetchCrossPosts(); this.setState(this.state); setupTippy(); } else if (op == UserOperation.CreateComment) { -- 2.44.1