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 { 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) {