|
1 | 1 | import { CommonModule } from '@angular/common'; |
2 | | -import { Component, computed, inject, signal } from '@angular/core'; |
| 2 | +import { Component, HostListener, computed, inject, signal } from '@angular/core'; |
3 | 3 | import { FormsModule } from '@angular/forms'; |
4 | 4 | import { NavigationEnd, Router, RouterLink } from '@angular/router'; |
5 | 5 | import { filter } from 'rxjs'; |
@@ -45,6 +45,7 @@ export class ResourcesComponent { |
45 | 45 | readonly isInAppRoute = signal(false); |
46 | 46 | readonly showAddResourceModal = signal(false); |
47 | 47 | private searchDebounceRef: ReturnType<typeof setTimeout> | null = null; |
| 48 | + private scrollLoadDebounceRef: ReturnType<typeof setTimeout> | null = null; |
48 | 49 |
|
49 | 50 | readonly searchQuery = signal(''); |
50 | 51 | readonly selectedCategoryFilter = signal('all'); |
@@ -151,6 +152,32 @@ export class ResourcesComponent { |
151 | 152 | } |
152 | 153 | } |
153 | 154 |
|
| 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 | + |
154 | 181 | private scheduleFilterReload() { |
155 | 182 | if (this.searchDebounceRef) { |
156 | 183 | clearTimeout(this.searchDebounceRef); |
|
0 commit comments