Update.
Some checks failed
CI / test (3.8) (push) Failing after 19s
CI / test (3.10) (push) Failing after 20s
CI / lint (push) Failing after 21s
CI / test (3.11) (push) Failing after 23s
CI / test (3.12) (push) Failing after 22s
CI / test (3.9) (push) Failing after 23s
CI / build (push) Failing after 24s
Some checks failed
CI / test (3.8) (push) Failing after 19s
CI / test (3.10) (push) Failing after 20s
CI / lint (push) Failing after 21s
CI / test (3.11) (push) Failing after 23s
CI / test (3.12) (push) Failing after 22s
CI / test (3.9) (push) Failing after 23s
CI / build (push) Failing after 24s
This commit is contained in:
parent
fdb5674c03
commit
f6673bff70
@ -23,6 +23,8 @@ class RantFeed extends BaseComponent {
|
|||||||
this.blockChangeHandler = () => this.render();
|
this.blockChangeHandler = () => this.render();
|
||||||
this.stateKey = this.buildStateKey();
|
this.stateKey = this.buildStateKey();
|
||||||
this.pendingRestore = null;
|
this.pendingRestore = null;
|
||||||
|
this.isRestoring = false;
|
||||||
|
this.scrollHandler = this.debounce(() => this.onScroll(), 200);
|
||||||
|
|
||||||
this.render();
|
this.render();
|
||||||
this.bindEvents();
|
this.bindEvents();
|
||||||
@ -43,6 +45,11 @@ class RantFeed extends BaseComponent {
|
|||||||
this.stateKey = key;
|
this.stateKey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onScroll() {
|
||||||
|
if (this.isRestoring || this.isLoading) return;
|
||||||
|
this.saveScrollState();
|
||||||
|
}
|
||||||
|
|
||||||
getTopVisibleRant() {
|
getTopVisibleRant() {
|
||||||
const cards = this.$$('rant-card');
|
const cards = this.$$('rant-card');
|
||||||
if (!cards || cards.length === 0) return null;
|
if (!cards || cards.length === 0) return null;
|
||||||
@ -88,13 +95,17 @@ class RantFeed extends BaseComponent {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.isRestoring = true;
|
||||||
this.pendingRestore = state;
|
this.pendingRestore = state;
|
||||||
await this.loadWithLimit(state.skip || this.limit);
|
await this.loadWithLimit(state.skip || this.limit);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
scrollToAnchor() {
|
scrollToAnchor() {
|
||||||
if (!this.pendingRestore) return;
|
if (!this.pendingRestore) {
|
||||||
|
this.isRestoring = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const { anchorRantId, offsetFromTop } = this.pendingRestore;
|
const { anchorRantId, offsetFromTop } = this.pendingRestore;
|
||||||
this.pendingRestore = null;
|
this.pendingRestore = null;
|
||||||
@ -106,7 +117,9 @@ class RantFeed extends BaseComponent {
|
|||||||
const scrollY = window.scrollY + rect.top - offsetFromTop;
|
const scrollY = window.scrollY + rect.top - offsetFromTop;
|
||||||
window.scrollTo(0, Math.max(0, scrollY));
|
window.scrollTo(0, Math.max(0, scrollY));
|
||||||
}
|
}
|
||||||
this.clearScrollState();
|
setTimeout(() => {
|
||||||
|
this.isRestoring = false;
|
||||||
|
}, 100);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -301,6 +314,7 @@ class RantFeed extends BaseComponent {
|
|||||||
this.on(this, 'click', this.handleClick);
|
this.on(this, 'click', this.handleClick);
|
||||||
this.setupInfiniteScroll();
|
this.setupInfiniteScroll();
|
||||||
window.addEventListener('rantii:block-change', this.blockChangeHandler);
|
window.addEventListener('rantii:block-change', this.blockChangeHandler);
|
||||||
|
window.addEventListener('scroll', this.scrollHandler);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
@ -345,7 +359,7 @@ class RantFeed extends BaseComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onDisconnected() {
|
onDisconnected() {
|
||||||
this.saveScrollState();
|
window.removeEventListener('scroll', this.scrollHandler);
|
||||||
if (this.intersectionObserver) {
|
if (this.intersectionObserver) {
|
||||||
this.intersectionObserver.disconnect();
|
this.intersectionObserver.disconnect();
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user