From 5e5695c3ea039ad976ee6a10fb5a7bbc92d57fd0 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Wed, 11 Aug 2021 21:06:54 -0400 Subject: [PATCH] Cleaning up scroll to comments --- src/shared/components/post/post.tsx | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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) { -- 2.44.1