@@ -29,6 +29,7 @@ import {
29
29
switchMap ,
30
30
takeUntil ,
31
31
tap ,
32
+ throttleTime ,
32
33
withLatestFrom ,
33
34
} from "rxjs/operators" ;
34
35
import { fadeInOut } from "../../../../shared" ;
@@ -83,6 +84,7 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
83
84
} ;
84
85
85
86
private destroy$ = new Subject < void > ( ) ;
87
+ private scrollSubject = new Subject < void > ( ) ;
86
88
87
89
public usagers : UsagerFormModel [ ] = [ ] ;
88
90
public me ! : UserStructure | null ;
@@ -139,6 +141,10 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
139
141
this . pageSize = 50 ;
140
142
this . filters . page = 0 ;
141
143
this . titleService . setTitle ( "Gestion des domiciliés - DomiFa" ) ;
144
+
145
+ this . scrollSubject . pipe ( throttleTime ( 500 ) ) . subscribe ( ( ) => {
146
+ this . handleScroll ( ) ;
147
+ } ) ;
142
148
}
143
149
144
150
public ngOnInit ( ) : void {
@@ -155,7 +161,7 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
155
161
"input"
156
162
) . pipe (
157
163
map ( ( event : InputEvent ) => ( event . target as HTMLInputElement ) . value ) ,
158
- debounceTime ( 200 ) ,
164
+ debounceTime ( 300 ) ,
159
165
map ( ( value : string ) => value . trim ( ) ) ,
160
166
filter ( ( value : string ) => value !== this . filters . searchString ) ,
161
167
withLatestFrom ( this . chargerTousRadies$ ) ,
@@ -188,7 +194,7 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
188
194
189
195
this . subscription . add (
190
196
combineLatest ( [ this . filters$ , allUsagers$ ] )
191
- . pipe ( debounceTime ( 200 ) , takeUntil ( this . destroy$ ) )
197
+ . pipe ( debounceTime ( 300 ) , takeUntil ( this . destroy$ ) )
192
198
. subscribe ( ( [ filters , allUsagers ] ) => {
193
199
this . applyFilters ( { filters, allUsagers } ) ;
194
200
} )
@@ -453,13 +459,17 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
453
459
454
460
@HostListener ( "window:scroll" , [ "$event" ] )
455
461
public onScroll ( ) : void {
462
+ this . scrollSubject . next ( ) ;
463
+ }
464
+
465
+ private handleScroll ( ) : void {
456
466
const pos =
457
467
( document . documentElement . scrollTop || document . body . scrollTop ) +
458
468
document . documentElement . offsetHeight ;
459
469
const max = document . documentElement . scrollHeight ;
460
470
const pourcent = ( pos / max ) * 100 ;
461
471
462
- if ( pourcent >= 85 && this . usagers . length < this . nbResults ) {
472
+ if ( pourcent >= 70 && this . usagers . length < this . nbResults ) {
463
473
this . filters . page = this . filters . page + 1 ;
464
474
this . filters$ . next ( this . filters ) ;
465
475
}
0 commit comments