diff --git a/js/src/forum/components/PostStream.js b/js/src/forum/components/PostStream.js index 77a45320b7..b02c8f8400 100644 --- a/js/src/forum/components/PostStream.js +++ b/js/src/forum/components/PostStream.js @@ -149,6 +149,11 @@ export default class PostStream extends Component { */ onscroll(top = window.pageYOffset) { if (this.stream.paused) return; + + this.updateScrubber(top); + + if (this.stream.pagesLoading) return; + const marginTop = this.getMarginTop(); const viewportHeight = $(window).height() - marginTop; const viewportTop = top + marginTop; @@ -174,8 +179,6 @@ export default class PostStream extends Component { // viewport) to 100ms. clearTimeout(this.calculatePositionTimeout); this.calculatePositionTimeout = setTimeout(this.calculatePosition.bind(this, top), 100); - - this.updateScrubber(top); } updateScrubber(top = window.pageYOffset) { diff --git a/js/src/forum/states/PostStreamState.js b/js/src/forum/states/PostStreamState.js index 577a3f7b11..1adf6b293c 100644 --- a/js/src/forum/states/PostStreamState.js +++ b/js/src/forum/states/PostStreamState.js @@ -238,23 +238,26 @@ class PostStreamState { * @param {Boolean} backwards */ loadPage(start, end, backwards = false) { - m.redraw(); + this.pagesLoading++; + + const redraw = () => { + if (start < this.visibleStart || end > this.visibleEnd) return; + + const anchorIndex = backwards ? this.visibleEnd - 1 : this.visibleStart; + anchorScroll(`.PostStream-item[data-index="${anchorIndex}"]`, m.redraw.sync); + }; + redraw(); this.loadPageTimeouts[start] = setTimeout( () => { this.loadRange(start, end).then(() => { - if (start >= this.visibleStart && end <= this.visibleEnd) { - const anchorIndex = backwards ? this.visibleEnd - 1 : this.visibleStart; - anchorScroll(`.PostStream-item[data-index="${anchorIndex}"]`, () => m.redraw.sync()); - } + redraw(); this.pagesLoading--; }); this.loadPageTimeouts[start] = null; }, - this.pagesLoading ? 1000 : 0 + this.pagesLoading - 1 ? 1000 : 0 ); - - this.pagesLoading++; } /**