]> Untitled Git - lemmy-ui.git/commitdiff
Show cross-posts for isomorphic loading. Fixes #113
authorDessalines <tyhou13@gmx.com>
Sun, 24 Jan 2021 01:41:23 +0000 (20:41 -0500)
committerDessalines <tyhou13@gmx.com>
Sun, 24 Jan 2021 01:41:23 +0000 (20:41 -0500)
src/shared/components/post.tsx

index 2068305550ff28c307b13b3b4e27cc615e8e577e..91e9b013aa9176d935ceb049ff3514a45e905a10 100644 (file)
@@ -101,8 +101,11 @@ export class Post extends Component<any, PostState> {
       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<any, PostState> {
     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<any>[] {
     let pathSplit = req.path.split('/');
     let promises: Promise<any>[] = [];
@@ -463,18 +480,7 @@ export class Post extends Component<any, PostState> {
       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) {