PostStream: Fix minor load more issue (#2388)

This commit is contained in:
Wadim Kalmykov 2021-02-11 02:22:26 +07:00 committed by GitHub
parent a2901cef23
commit 03231b2931
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
});
}