]> Untitled Git - lemmy-ui.git/commitdiff
Cleaning up scroll to comments
authorDessalines <tyhou13@gmx.com>
Thu, 12 Aug 2021 01:06:54 +0000 (21:06 -0400)
committerDessalines <tyhou13@gmx.com>
Thu, 12 Aug 2021 01:06:54 +0000 (21:06 -0400)
src/shared/components/post/post.tsx

index 50d3528a40254897cf98163c7037c0af41759b50..58f1ae13a5ca43aa1cc3f13f5c8aa9c20ee63235 100644 (file)
@@ -1,5 +1,5 @@
-import { Component, linkEvent, createRef, RefObject } from "inferno";
 import autosize from "autosize";
+import { Component, createRef, linkEvent, RefObject } from "inferno";
 import {
   AddAdminResponse,
   AddModToCommunityResponse,
@@ -117,7 +117,9 @@ export class Post extends Component<any, PostState> {
         this.fetchCrossPosts();
         if (this.state.commentId) {
           this.scrollCommentIntoView();
-        } else if (new URLSearchParams(this.props.location.search).get('scrollToComments')) {
+        }
+
+        if (this.checkScrollIntoCommentsParam) {
           this.scrollIntoCommentSection();
         }
       }
@@ -188,7 +190,7 @@ export class Post extends Component<any, PostState> {
       this.scrollCommentIntoView();
     }
 
-    if (new URLSearchParams(this.props.location.search).get('scrollToComments') ) {
+    if (this.checkScrollIntoCommentsParam) {
       this.scrollIntoCommentSection();
     }
 
@@ -212,6 +214,12 @@ export class Post extends Component<any, PostState> {
     this.markScrolledAsRead(this.state.commentId);
   }
 
+  get checkScrollIntoCommentsParam() {
+    return Boolean(
+      new URLSearchParams(this.props.location.search).get("scrollToComments")
+    );
+  }
+
   scrollIntoCommentSection() {
     this.state.commentSectionRef.current?.scrollIntoView();
   }
@@ -503,7 +511,8 @@ export class Post extends Component<any, PostState> {
       this.setState(this.state);
       setupTippy();
       if (!this.state.commentId) restoreScrollPosition(this.context);
-      if (new URLSearchParams(this.props.location.search).get('scrollToComments') ) {
+
+      if (this.checkScrollIntoCommentsParam) {
         this.scrollIntoCommentSection();
       }
     } else if (op == UserOperation.CreateComment) {