@@ -51,7 +51,7 @@ import { UserStructure } from "@domifa/common";
51
51
import { MatomoTracker } from "ngx-matomo-client" ;
52
52
import { AuthService , CustomToastService } from "../../../shared/services" ;
53
53
54
- const AUTO_REFRESH_PERIOD = 300000 ; // 5 minutes
54
+ const FIVE_MINUTES = 5 * 60 * 1000 ;
55
55
56
56
@Component ( {
57
57
animations : [ fadeInOut ] ,
@@ -152,12 +152,6 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
152
152
if ( ! searchPageLoadedUsagersData . dataLoaded ) {
153
153
this . loadDataFromAPI ( ) ;
154
154
} else {
155
- if (
156
- searchPageLoadedUsagersData . usagersRadiesFirsts . length >=
157
- searchPageLoadedUsagersData . usagersRadiesTotalCount
158
- ) {
159
- this . chargerTousRadies$ . next ( true ) ;
160
- }
161
155
this . updateComponentState ( searchPageLoadedUsagersData ) ;
162
156
}
163
157
}
@@ -173,9 +167,9 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
173
167
map ( ( value : string ) => value . trim ( ) ) ,
174
168
filter ( ( value : string ) => value !== this . filters . searchString ) ,
175
169
withLatestFrom ( this . chargerTousRadies$ ) ,
176
- switchMap ( ( [ searchString , chargerTousRadies ] ) =>
177
- this . findRemoteUsagers ( chargerTousRadies , searchString )
178
- ) ,
170
+ switchMap ( ( [ searchString , chargerTousRadies ] ) => {
171
+ return this . findRemoteUsagers ( chargerTousRadies , searchString ) ;
172
+ } ) ,
179
173
tap ( ( searchString : string ) => {
180
174
this . filters . searchString = searchString ?? null ;
181
175
this . filters . page = 0 ;
@@ -189,6 +183,20 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
189
183
} )
190
184
) ;
191
185
186
+ this . subscription . add (
187
+ timer ( FIVE_MINUTES , FIVE_MINUTES )
188
+ . pipe (
189
+ tap ( ( ) => {
190
+ this . searching = true ;
191
+ } ) ,
192
+ switchMap ( ( ) => this . usagerService . updateManage ( ) )
193
+ )
194
+ . subscribe ( ( ) => {
195
+ this . searching = false ;
196
+ this . filters$ . next ( this . filters ) ;
197
+ } )
198
+ ) ;
199
+
192
200
this . subscription . add (
193
201
this . filters$ . subscribe ( ( filters ) => {
194
202
this . applyFilters ( {
@@ -201,31 +209,22 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
201
209
202
210
private loadDataFromAPI ( ) {
203
211
this . subscription . add (
204
- timer ( 0 , AUTO_REFRESH_PERIOD )
212
+ this . chargerTousRadies$
205
213
. pipe (
206
214
tap ( ( ) => {
207
215
this . searching = true ;
208
216
} ) ,
217
+ switchMap ( ( chargerTousRadies ) =>
218
+ this . usagerService . getSearchPageUsagerData ( { chargerTousRadies } )
219
+ ) ,
209
220
switchMap ( ( ) => this . chargerTousRadies$ ) ,
210
- switchMap ( ( chargerTousRadies ) => {
211
- this . searching = true ;
212
- return this . usagerService . getSearchPageUsagerData ( {
213
- chargerTousRadies,
214
- } ) ;
215
- } ) ,
216
- switchMap ( ( ) => this . chargerTousRadies$ ) ,
217
- switchMap ( ( chargerTousRadies ) => {
218
- // Call remote usagers to update list
219
- if ( ! chargerTousRadies ) {
220
- return this . findRemoteUsagers (
221
- chargerTousRadies ,
222
- this . filters . searchString
223
- ) ;
224
- }
225
- return of ( chargerTousRadies ) ;
226
- } )
221
+ switchMap ( ( chargerTousRadies ) =>
222
+ this . findRemoteUsagers ( chargerTousRadies , this . filters . searchString )
223
+ )
227
224
)
228
- . subscribe ( )
225
+ . subscribe ( ( ) => {
226
+ this . searching = false ;
227
+ } )
229
228
) ;
230
229
}
231
230
@@ -235,7 +234,7 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
235
234
) : Observable < string > {
236
235
if (
237
236
! chargerTousRadies &&
238
- searchString . length >= 3 &&
237
+ searchString ? .length >= 3 &&
239
238
( this . filters . statut === "TOUS" || this . filters . statut === "RADIE" )
240
239
) {
241
240
this . searching = true ;
0 commit comments