mirror of
https://github.com/flarum/framework.git
synced 2024-12-02 06:53:47 +08:00
Fix multiple scrolls to same post in PostStream (#2264)
While more pleasant from an FSM standpoint, comparing the current targetPost to the previous one does not work if goToNumber is called twice in a row for the same post. For instance, if a user clicks the mentions link to a post twice, the post stream breaks.
This commit is contained in:
parent
8e8cfe28ec
commit
2696f02ce1
|
@ -121,15 +121,10 @@ export default class PostStream extends Component {
|
|||
* Start scrolling, if appropriate, to a newly-targeted post.
|
||||
*/
|
||||
triggerScroll() {
|
||||
if (!this.attrs.targetPost) return;
|
||||
if (!this.attrs.targetPost || !this.stream.needsScroll) return;
|
||||
|
||||
const oldTarget = this.prevTarget;
|
||||
const newTarget = this.attrs.targetPost;
|
||||
|
||||
if (oldTarget) {
|
||||
if ('number' in oldTarget && oldTarget.number === newTarget.number) return;
|
||||
if ('index' in oldTarget && oldTarget.index === newTarget.index) return;
|
||||
}
|
||||
this.stream.needsScroll = false;
|
||||
|
||||
if ('number' in newTarget) {
|
||||
this.scrollToNumber(newTarget.number, this.stream.animateScroll);
|
||||
|
@ -137,8 +132,6 @@ export default class PostStream extends Component {
|
|||
const backwards = newTarget.index === this.stream.count() - 1;
|
||||
this.scrollToIndex(newTarget.index, this.stream.animateScroll, backwards);
|
||||
}
|
||||
|
||||
this.prevTarget = newTarget;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -103,6 +103,7 @@ class PostStreamState {
|
|||
|
||||
this.loadPromise = this.loadNearNumber(number);
|
||||
|
||||
this.needsScroll = true;
|
||||
this.targetPost = { number };
|
||||
this.animateScroll = !noAnimation;
|
||||
this.number = number;
|
||||
|
@ -127,6 +128,7 @@ class PostStreamState {
|
|||
|
||||
this.loadPromise = this.loadNearIndex(index);
|
||||
|
||||
this.needsScroll = true;
|
||||
this.targetPost = { index };
|
||||
this.animateScroll = !noAnimation;
|
||||
this.index = index;
|
||||
|
|
Loading…
Reference in New Issue
Block a user