Cleaning up scroll to comments

This commit is contained in:
Dessalines 2021-08-11 21:06:54 -04:00
parent 3870703b12
commit 5e5695c3ea

View file

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