1
0
mirror of https://github.com/flarum/core.git synced 2025-08-08 09:26:34 +02:00

Fix jumping around on page reload

This commit is contained in:
Alexander Skvortsov
2020-07-07 18:10:51 -04:00
committed by Franz Liedke
parent cc10eaadd2
commit 2360745237
2 changed files with 17 additions and 16 deletions

View File

@@ -290,7 +290,7 @@ export default class PostStream extends Component {
console.log('scrollToNumber');
const $item = this.$(`.PostStream-item[data-number=${number}]`);
return this.scrollToItem($item, noAnimation).done(this.flashItem.bind(this, $item));
return this.scrollToItem($item, noAnimation).then(this.flashItem.bind(this, $item));
}
/**
@@ -306,7 +306,7 @@ export default class PostStream extends Component {
console.log('scrollToIndex');
const $item = this.$(`.PostStream-item[data-index=${index}]`);
return this.scrollToItem($item, noAnimation, true, bottom).done(() => {
return this.scrollToItem($item, noAnimation, true, bottom).then(() => {
if (index == this.state.count() - 1) {
this.flashItem(this.$('.PostStream-item:last-child'));
}
@@ -348,18 +348,18 @@ export default class PostStream extends Component {
}
}
return $container.promise().then(() => {
return Promise.all([
$container.promise(),
this.state.loadPromise
.then(() => {
m.redraw(true);
$(window).scrollTop($(`.PostStream-item[data-index=${$item.data('index')}]`).offset().top - this.getMarginTop());
})
.then(() => {
this.calculatePosition();
if (this.state.locationType == 'number') this.updateScrubber();
})
.then(() => this.state.unpause());
});
]).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());
}
/**

View File

@@ -20,8 +20,10 @@ class PostStreamState {
this.loadPageTimeouts = {};
this.pagesLoading = 0;
this.show(includedPosts);
this.locationType = null;
this.index = 0;
this.index = (this.visibleEnd - this.visibleStart) / 2;
this.number = 1;
/**
@@ -37,8 +39,6 @@ class PostStreamState {
* @type {String}
*/
this.description = '';
this.show(includedPosts);
}
/**
@@ -270,6 +270,7 @@ class PostStreamState {
() => {
this.loadRange(start, end).then(() => {
if (start >= this.visibleStart && end <= this.visibleEnd) {
console.log('anchoring!');
const anchorIndex = backwards ? this.visibleEnd - 1 : this.visibleStart;
anchorScroll(`.PostStream-item[data-index="${anchorIndex}"]`, () => m.redraw(true));
}