Skip to content

Commit

Permalink
PostStream: Fix minor load more issue (#2388)
Browse files Browse the repository at this point in the history
  • Loading branch information
w-4 authored Feb 10, 2021
1 parent a2901ce commit 03231b2
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions js/src/forum/components/PostStream.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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();
});
}

Expand Down

0 comments on commit 03231b2

Please sign in to comment.