markable?: boolean;
showContext?: boolean;
showCommunity?: boolean;
+ maxCommentsShown?: number;
enableDownvotes: boolean;
}
}
render() {
+ let maxComments = this.props.maxCommentsShown
+ ? this.props.maxCommentsShown
+ : this.props.nodes.length;
+
return (
<div className="comments">
- {this.props.nodes.map(node => (
+ {this.props.nodes.slice(0, maxComments).map(node => (
<CommentNode
key={node.comment_view.comment.id}
node={node}
commentsToFlatNodes,
createCommentLikeRes,
createPostLikeRes,
+ debounce,
editCommentRes,
getCommentIdFromProps,
getIdFromProps,
import { Sidebar } from "../community/sidebar";
import { PostListing } from "./post-listing";
+const commentsShownInterval = 15;
+
interface PostState {
postRes: GetPostResponse;
postId: number;
siteRes: GetSiteResponse;
commentSectionRef?: RefObject<HTMLDivElement>;
showSidebarMobile: boolean;
+ maxCommentsShown: number;
}
export class Post extends Component<any, PostState> {
siteRes: this.isoData.site_res,
commentSectionRef: null,
showSidebarMobile: false,
+ maxCommentsShown: commentsShownInterval,
};
constructor(props: any, context: any) {
componentWillUnmount() {
this.subscription.unsubscribe();
+ document.removeEventListener("scroll", this.trackCommentsBoxScrolling);
window.isoData.path = undefined;
saveScrollPosition(this.context);
}
wsClient.postJoin({ post_id: this.state.postId })
);
autosize(document.querySelectorAll("textarea"));
+
+ document.addEventListener(
+ "scroll",
+ debounce(this.trackCommentsBoxScrolling, 100)
+ );
}
componentDidUpdate(_lastProps: any, lastState: PostState) {
}
}
+ isBottom(el: Element) {
+ return el.getBoundingClientRect().bottom <= window.innerHeight;
+ }
+
+ /**
+ * Shows new comments when scrolling to the bottom of the comments div
+ */
+ trackCommentsBoxScrolling = () => {
+ const wrappedElement = document.getElementsByClassName("comments")[0];
+ if (this.isBottom(wrappedElement)) {
+ this.state.maxCommentsShown += commentsShownInterval;
+ this.setState(this.state);
+ }
+ };
+
get documentTitle(): string {
return `${this.state.postRes.post_view.post.name} - ${this.state.siteRes.site_view.site.name}`;
}
<div>
<CommentNodes
nodes={commentsToFlatNodes(this.state.postRes.comments)}
+ maxCommentsShown={this.state.maxCommentsShown}
noIndent
locked={this.state.postRes.post_view.post.locked}
moderators={this.state.postRes.moderators}
<div>
<CommentNodes
nodes={this.state.commentTree}
+ maxCommentsShown={this.state.maxCommentsShown}
locked={this.state.postRes.post_view.post.locked}
moderators={this.state.postRes.moderators}
admins={this.state.siteRes.admins}