mirror of
https://github.com/flarum/framework.git
synced 2025-02-28 10:07:25 +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.
|
* Start scrolling, if appropriate, to a newly-targeted post.
|
||||||
*/
|
*/
|
||||||
triggerScroll() {
|
triggerScroll() {
|
||||||
if (!this.attrs.targetPost) return;
|
if (!this.attrs.targetPost || !this.stream.needsScroll) return;
|
||||||
|
|
||||||
const oldTarget = this.prevTarget;
|
|
||||||
const newTarget = this.attrs.targetPost;
|
const newTarget = this.attrs.targetPost;
|
||||||
|
this.stream.needsScroll = false;
|
||||||
if (oldTarget) {
|
|
||||||
if ('number' in oldTarget && oldTarget.number === newTarget.number) return;
|
|
||||||
if ('index' in oldTarget && oldTarget.index === newTarget.index) return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ('number' in newTarget) {
|
if ('number' in newTarget) {
|
||||||
this.scrollToNumber(newTarget.number, this.stream.animateScroll);
|
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;
|
const backwards = newTarget.index === this.stream.count() - 1;
|
||||||
this.scrollToIndex(newTarget.index, this.stream.animateScroll, backwards);
|
this.scrollToIndex(newTarget.index, this.stream.animateScroll, backwards);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.prevTarget = newTarget;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,6 +103,7 @@ class PostStreamState {
|
|||||||
|
|
||||||
this.loadPromise = this.loadNearNumber(number);
|
this.loadPromise = this.loadNearNumber(number);
|
||||||
|
|
||||||
|
this.needsScroll = true;
|
||||||
this.targetPost = { number };
|
this.targetPost = { number };
|
||||||
this.animateScroll = !noAnimation;
|
this.animateScroll = !noAnimation;
|
||||||
this.number = number;
|
this.number = number;
|
||||||
@ -127,6 +128,7 @@ class PostStreamState {
|
|||||||
|
|
||||||
this.loadPromise = this.loadNearIndex(index);
|
this.loadPromise = this.loadNearIndex(index);
|
||||||
|
|
||||||
|
this.needsScroll = true;
|
||||||
this.targetPost = { index };
|
this.targetPost = { index };
|
||||||
this.animateScroll = !noAnimation;
|
this.animateScroll = !noAnimation;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user