1
0
mirror of https://github.com/flarum/core.git synced 2025-08-10 18:35:56 +02:00

Try calculating index before redraw to avoid calling redraw immediately after scroll

This commit is contained in:
Alexander Skvortsov
2020-07-07 19:06:12 -04:00
committed by Franz Liedke
parent 2360745237
commit ef206495cd
2 changed files with 7 additions and 8 deletions

View File

@@ -348,15 +348,12 @@ export default class PostStream extends Component {
} }
} }
return Promise.all([ return Promise.all([$container.promise(), this.state.loadPromise])
$container.promise(), .then(() => {
this.state.loadPromise
]).then(() => {
m.redraw(true); m.redraw(true);
return $(window).scrollTop($(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop()); return $(window).scrollTop($(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop());
}) })
.then(() => { .then(() => {
//if (this.state.locationType == 'number') this.updateScrubber();
return this.calculatePosition(); return this.calculatePosition();
}) })
.then(() => this.state.unpause()); .then(() => this.state.unpause());

View File

@@ -20,10 +20,8 @@ class PostStreamState {
this.loadPageTimeouts = {}; this.loadPageTimeouts = {};
this.pagesLoading = 0; this.pagesLoading = 0;
this.show(includedPosts);
this.locationType = null; this.locationType = null;
this.index = (this.visibleEnd - this.visibleStart) / 2; this.index = 0;
this.number = 1; this.number = 1;
/** /**
@@ -39,6 +37,8 @@ class PostStreamState {
* @type {String} * @type {String}
*/ */
this.description = ''; this.description = '';
this.show(includedPosts);
} }
/** /**
@@ -125,6 +125,7 @@ class PostStreamState {
show(posts) { show(posts) {
this.visibleStart = posts.length ? this.discussion.postIds().indexOf(posts[0].id()) : 0; this.visibleStart = posts.length ? this.discussion.postIds().indexOf(posts[0].id()) : 0;
this.visibleEnd = this.sanitizeIndex(this.visibleStart + posts.length); this.visibleEnd = this.sanitizeIndex(this.visibleStart + posts.length);
this.index = (this.visibleEnd - this.visibleStart) / 2;
} }
/** /**
@@ -137,6 +138,7 @@ class PostStreamState {
reset(start, end) { reset(start, end) {
this.visibleStart = start || 0; this.visibleStart = start || 0;
this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount); this.visibleEnd = this.sanitizeIndex(end || this.constructor.loadCount);
this.index = (this.visibleEnd - this.visibleStart) / 2;
} }
/** /**