From: Dessalines Date: Thu, 12 Aug 2021 01:06:54 +0000 (-0400) Subject: Cleaning up scroll to comments X-Git-Url: http://these/git/%7Bpost.url%7D?a=commitdiff_plain;h=5e5695c3ea039ad976ee6a10fb5a7bbc92d57fd0;p=lemmy-ui.git Cleaning up scroll to comments --- diff --git a/src/shared/components/post/post.tsx b/src/shared/components/post/post.tsx index 50d3528..58f1ae1 100644 --- a/src/shared/components/post/post.tsx +++ b/src/shared/components/post/post.tsx @@ -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 { 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 { 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 { 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 { 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) {