diff --git a/js/src/forum/components/PostStream.js b/js/src/forum/components/PostStream.js index b02c8f840..c121b37ca 100644 --- a/js/src/forum/components/PostStream.js +++ b/js/src/forum/components/PostStream.js @@ -142,8 +142,6 @@ export default class PostStream extends Component { } /** - * When the window is scrolled, check if either extreme of the post stream is - * in the viewport, and if so, trigger loading the next/previous page. * * @param {Integer} top */ @@ -154,6 +152,21 @@ export default class PostStream extends Component { if (this.stream.pagesLoading) return; + this.loadPostsIfNeeded(top); + + // Throttle calculation of our position (start/end numbers of posts in the + // viewport) to 100ms. + clearTimeout(this.calculatePositionTimeout); + this.calculatePositionTimeout = setTimeout(this.calculatePosition.bind(this, top), 100); + } + + /** + * Check if either extreme of the post stream is in the viewport, + * and if so, trigger loading the next/previous page. + * + * @param {Integer} top + */ + loadPostsIfNeeded(top = window.pageYOffset) { const marginTop = this.getMarginTop(); const viewportHeight = $(window).height() - marginTop; const viewportTop = top + marginTop; @@ -174,11 +187,6 @@ export default class PostStream extends Component { this.stream.loadNext(); } } - - // Throttle calculation of our position (start/end numbers of posts in the - // viewport) to 100ms. - clearTimeout(this.calculatePositionTimeout); - this.calculatePositionTimeout = setTimeout(this.calculatePosition.bind(this, top), 100); } updateScrubber(top = window.pageYOffset) { @@ -399,6 +407,8 @@ export default class PostStream extends Component { this.calculatePosition(); this.stream.paused = false; + // Check if we need to load more posts after scrolling. + this.loadPostsIfNeeded(); }); }