let post_view = this.props.post_view;
return (
<div class="d-flex justify-content-between justify-content-lg-start flex-wrap text-muted font-weight-bold mb-1">
- <button class="btn btn-link text-muted p-0">
+ <button
+ class="btn btn-link text-muted p-0"
+ >
<Link
className="text-muted small"
title={i18n.t("number_of_comments", {
count: post_view.counts.comments,
})}
- to={`/post/${post_view.post.id}`}
+ to={`/post/${post_view.post.id}?scrollToComments=true`}
>
<Icon icon="message-square" classes="icon-inline mr-1" />
{i18n.t("number_of_comments", {
+import { Component, linkEvent, createRef, RefObject } from "inferno";
import autosize from "autosize";
-import { Component, linkEvent } from "inferno";
import {
AddAdminResponse,
AddModToCommunityResponse,
loading: boolean;
crossPosts: PostView[];
siteRes: GetSiteResponse;
+ commentSectionRef?: RefObject<HTMLDivElement>;
showSidebarMobile: boolean;
}
loading: true,
crossPosts: [],
siteRes: this.isoData.site_res,
+ commentSectionRef: null,
showSidebarMobile: false,
};
super(props, context);
this.state = this.emptyState;
+ this.state.commentSectionRef = createRef();
this.parseMessage = this.parseMessage.bind(this);
this.subscription = wsSubscribe(this.parseMessage);
this.fetchCrossPosts();
if (this.state.commentId) {
this.scrollCommentIntoView();
+ } else if (new URLSearchParams(this.props.location.search).get('scrollToComments')) {
+ this.scrollIntoCommentSection();
}
}
} else {
this.scrollCommentIntoView();
}
+ if (new URLSearchParams(this.props.location.search).get('scrollToComments') ) {
+ this.scrollIntoCommentSection();
+ }
+
// Necessary if you are on a post and you click another post (same route)
if (_lastProps.location.pathname !== _lastProps.history.location.pathname) {
// TODO Couldnt get a refresh working. This does for now.
this.markScrolledAsRead(this.state.commentId);
}
+ scrollIntoCommentSection() {
+ this.state.commentSectionRef.current?.scrollIntoView();
+ }
+
// TODO this needs some re-work
markScrolledAsRead(commentId: number) {
let found = this.state.postRes.comments.find(
}
enableNsfw={this.state.siteRes.site_view.site.enable_nsfw}
/>
- <div className="mb-2" />
+ <div ref={this.state.commentSectionRef} className="mb-2" />
<CommentForm
postId={this.state.postId}
disabled={pv.post.locked}
this.setState(this.state);
setupTippy();
if (!this.state.commentId) restoreScrollPosition(this.context);
+ if (new URLSearchParams(this.props.location.search).get('scrollToComments') ) {
+ this.scrollIntoCommentSection();
+ }
} else if (op == UserOperation.CreateComment) {
let data = wsJsonToRes<CommentResponse>(msg).data;