forked from jsnbuchanan/crowd-funder-for-time-pwa
refactor: improve feed loading and infinite scroll reliability
- Add debouncing and loading state to InfiniteScroll component to prevent duplicate entries - Refactor updateAllFeed into smaller, focused functions for better maintainability - Add proper error handling and type assertions - Optimize test performance with networkidle waits and better selectors - Fix strict mode violations in Playwright tests - Clean up test configuration by commenting out unused browser targets
This commit is contained in:
@@ -14,6 +14,8 @@ export default class InfiniteScroll extends Vue {
|
||||
readonly distance!: number;
|
||||
private observer!: IntersectionObserver;
|
||||
private isInitialRender = true;
|
||||
private isLoading = false;
|
||||
private debounceTimeout: number | null = null;
|
||||
|
||||
updated() {
|
||||
if (!this.observer) {
|
||||
@@ -35,13 +37,28 @@ export default class InfiniteScroll extends Vue {
|
||||
if (this.observer) {
|
||||
this.observer.disconnect();
|
||||
}
|
||||
if (this.debounceTimeout) {
|
||||
window.clearTimeout(this.debounceTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
@Emit("reached-bottom")
|
||||
handleIntersection(entries: IntersectionObserverEntry[]) {
|
||||
const entry = entries[0];
|
||||
if (entry.isIntersecting) {
|
||||
return true;
|
||||
if (entry.isIntersecting && !this.isLoading) {
|
||||
// Debounce the intersection event
|
||||
if (this.debounceTimeout) {
|
||||
window.clearTimeout(this.debounceTimeout);
|
||||
}
|
||||
|
||||
this.debounceTimeout = window.setTimeout(() => {
|
||||
this.isLoading = true;
|
||||
this.$emit("reached-bottom", true);
|
||||
// Reset loading state after a short delay
|
||||
setTimeout(() => {
|
||||
this.isLoading = false;
|
||||
}, 1000);
|
||||
}, 300);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user