From ef206495cd137a0972233ebb56b49c01beffe56a Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Tue, 7 Jul 2020 19:06:12 -0400 Subject: [PATCH] Try calculating index before redraw to avoid calling redraw immediately after scroll --- js/src/forum/components/PostStream.js | 7 ++----- js/src/forum/states/PostStreamState.js | 8 +++++--- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/js/src/forum/components/PostStream.js b/js/src/forum/components/PostStream.js index 1746bddd6..0c72b2253 100644 --- a/js/src/forum/components/PostStream.js +++ b/js/src/forum/components/PostStream.js @@ -348,15 +348,12 @@ export default class PostStream extends Component { } } - return Promise.all([ - $container.promise(), - this.state.loadPromise - ]).then(() => { + return Promise.all([$container.promise(), this.state.loadPromise]) + .then(() => { m.redraw(true); return $(window).scrollTop($(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop()); }) .then(() => { - //if (this.state.locationType == 'number') this.updateScrubber(); return this.calculatePosition(); }) .then(() => this.state.unpause()); diff --git a/js/src/forum/states/PostStreamState.js b/js/src/forum/states/PostStreamState.js index ef2da1af3..0b4b565ed 100644 --- a/js/src/forum/states/PostStreamState.js +++ b/js/src/forum/states/PostStreamState.js @@ -20,10 +20,8 @@ class PostStreamState { this.loadPageTimeouts = {}; this.pagesLoading = 0; - this.show(includedPosts); - this.locationType = null; - this.index = (this.visibleEnd - this.visibleStart) / 2; + this.index = 0; this.number = 1; /** @@ -39,6 +37,8 @@ class PostStreamState { * @type {String} */ this.description = ''; + + this.show(includedPosts); } /** @@ -125,6 +125,7 @@ class PostStreamState { show(posts) { this.visibleStart = posts.length ? this.discussion.postIds().indexOf(posts[0].id()) : 0; this.visibleEnd = this.sanitizeIndex(this.visibleStart + posts.length); + this.index = (this.visibleEnd - this.visibleStart) / 2; } /** @@ -137,6 +138,7 @@ class PostStreamState { reset(start, end) { this.visibleStart = start || 0; this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount); + this.index = (this.visibleEnd - this.visibleStart) / 2; } /**