diff --git a/js/src/forum/components/PostStream.js b/js/src/forum/components/PostStream.js index a9739c8a4..1746bddd6 100644 --- a/js/src/forum/components/PostStream.js +++ b/js/src/forum/components/PostStream.js @@ -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()); } /** diff --git a/js/src/forum/states/PostStreamState.js b/js/src/forum/states/PostStreamState.js index b8583cda4..ef2da1af3 100644 --- a/js/src/forum/states/PostStreamState.js +++ b/js/src/forum/states/PostStreamState.js @@ -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)); }