Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PostStream: Fix minor load more issue #2388

Merged
merged 5 commits into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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