Skip to content

Commit b6a7c6c

Browse files
committed
Add auto-load on scroll for paged resources list
1 parent 4053b98 commit b6a7c6c

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

frontend/src/app/components/resources/resources.component.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { CommonModule } from '@angular/common';
2-
import { Component, computed, inject, signal } from '@angular/core';
2+
import { Component, HostListener, computed, inject, signal } from '@angular/core';
33
import { FormsModule } from '@angular/forms';
44
import { NavigationEnd, Router, RouterLink } from '@angular/router';
55
import { filter } from 'rxjs';
@@ -45,6 +45,7 @@ export class ResourcesComponent {
4545
readonly isInAppRoute = signal(false);
4646
readonly showAddResourceModal = signal(false);
4747
private searchDebounceRef: ReturnType<typeof setTimeout> | null = null;
48+
private scrollLoadDebounceRef: ReturnType<typeof setTimeout> | null = null;
4849

4950
readonly searchQuery = signal('');
5051
readonly selectedCategoryFilter = signal('all');
@@ -151,6 +152,32 @@ export class ResourcesComponent {
151152
}
152153
}
153154

155+
@HostListener('window:scroll')
156+
onWindowScroll() {
157+
if (!this.hasNext() || this.isLoading() || this.isLoadingMore() || this.showAddResourceModal()) {
158+
return;
159+
}
160+
161+
const scrollTop = window.scrollY || document.documentElement.scrollTop || 0;
162+
const viewportHeight = window.innerHeight || document.documentElement.clientHeight || 0;
163+
const fullHeight = document.documentElement.scrollHeight || document.body.scrollHeight || 0;
164+
const remaining = fullHeight - (scrollTop + viewportHeight);
165+
166+
if (remaining > 220) {
167+
return;
168+
}
169+
170+
if (this.scrollLoadDebounceRef) {
171+
return;
172+
}
173+
174+
this.scrollLoadDebounceRef = setTimeout(() => {
175+
this.scrollLoadDebounceRef = null;
176+
}, 300);
177+
178+
this.loadResources();
179+
}
180+
154181
private scheduleFilterReload() {
155182
if (this.searchDebounceRef) {
156183
clearTimeout(this.searchDebounceRef);

0 commit comments

Comments
 (0)