@@ -100,6 +100,7 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
100100
101101 private previousReqQuery : Record < string , any > = { } ;
102102 private availableFilters : PartnerProgramFields [ ] = [ ] ;
103+ private currentFilters : Record < string , any > = { } ;
103104
104105 searchForm : FormGroup ;
105106 filterForm : FormGroup ;
@@ -244,18 +245,21 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
244245
245246 if ( JSON . stringify ( reqQuery ) !== JSON . stringify ( this . previousReqQuery ) ) {
246247 this . previousReqQuery = reqQuery ;
248+ this . currentFilters = reqQuery [ "filters" ] || { } ;
247249
248250 const hasFilters =
249251 reqQuery && reqQuery [ "filters" ] && Object . keys ( reqQuery [ "filters" ] ) . length > 0 ;
250252 const params = new HttpParams ( { fromObject : { offset : 0 , limit : this . perPage } } ) ;
251253
252254 if ( hasFilters ) {
253- return this . programService . createProgramFilters ( programId , reqQuery [ "filters" ] ) . pipe (
254- catchError ( err => {
255- console . error ( "createFilters failed, fallback to getAllProjects()" , err ) ;
256- return this . programService . getAllProjects ( programId , params ) ;
257- } )
258- ) ;
255+ return this . programService
256+ . createProgramFilters ( programId , reqQuery [ "filters" ] , params )
257+ . pipe (
258+ catchError ( err => {
259+ console . error ( "createFilters failed, fallback to getAllProjects()" , err ) ;
260+ return this . programService . getAllProjects ( programId , params ) ;
261+ } )
262+ ) ;
259263 }
260264
261265 return this . programService . getAllProjects ( programId , params ) . pipe (
@@ -308,7 +312,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
308312 this . subscriptions$ . push ( queryParams$ ) ;
309313 }
310314
311- // Методы фильтрации
312315 setValue ( event : Event ) : void {
313316 event . stopPropagation ( ) ;
314317 this . filterForm . get ( "filterTag" ) ?. setValue ( ! this . filterForm . get ( "filterTag" ) ?. value ) ;
@@ -320,7 +323,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
320323 } ) ;
321324 }
322325
323- // Универсальный метод скролла
324326 private onScroll ( ) {
325327 if ( this . listTotalCount && this . list . length >= this . listTotalCount ) return of ( { } ) ;
326328
@@ -330,11 +332,9 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
330332 let shouldFetch = false ;
331333
332334 if ( this . listType === "rating" ) {
333- // Логика для rating
334335 const scrollBottom = target . scrollHeight - target . scrollTop - target . clientHeight ;
335336 shouldFetch = scrollBottom <= 0 ;
336337 } else {
337- // Логика для projects и members
338338 const diff =
339339 target . scrollTop -
340340 this . listRoot ! . nativeElement . getBoundingClientRect ( ) . height +
@@ -351,30 +351,47 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
351351 return of ( { } ) ;
352352 }
353353
354- // Универсальный метод загрузки данных
355354 private onFetch ( ) {
356355 const programId = this . route . parent ?. snapshot . params [ "programId" ] ;
357356 const offset = this . listPage * this . itemsPerPage ;
357+ const hasFilters = this . currentFilters && Object . keys ( this . currentFilters ) . length > 0 ;
358+ const params = new HttpParams ( { fromObject : { offset, limit : this . itemsPerPage } } ) ;
358359
359360 switch ( this . listType ) {
360361 case "projects" :
361- return this . programService
362- . getAllProjects (
363- programId ,
364- new HttpParams ( { fromObject : { offset, limit : this . itemsPerPage } } )
365- )
366- . pipe (
367- tap ( ( projects : ApiPagination < Project > ) => {
368- this . listTotalCount = projects . count ;
369- if ( this . listPage === 0 ) {
370- this . list = projects . results ;
371- } else {
372- this . list = [ ...this . list , ...projects . results ] ;
373- }
374- this . searchedList = this . list ;
375- this . cdref . detectChanges ( ) ;
376- } )
377- ) ;
362+ if ( hasFilters ) {
363+ return this . programService
364+ . createProgramFilters ( programId , this . currentFilters , params )
365+ . pipe (
366+ tap ( ( projects : ApiPagination < Project > ) => {
367+ this . listTotalCount = projects . count ;
368+ if ( this . listPage === 0 ) {
369+ this . list = projects . results ;
370+ } else {
371+ this . list = [ ...this . list , ...projects . results ] ;
372+ }
373+ this . searchedList = this . list ;
374+ this . cdref . detectChanges ( ) ;
375+ } ) ,
376+ catchError ( err => {
377+ console . error ( "Pagination with filters failed" , err ) ;
378+ return of ( { results : [ ] , count : 0 } ) ;
379+ } )
380+ ) ;
381+ }
382+
383+ return this . programService . getAllProjects ( programId , params ) . pipe (
384+ tap ( ( projects : ApiPagination < Project > ) => {
385+ this . listTotalCount = projects . count ;
386+ if ( this . listPage === 0 ) {
387+ this . list = projects . results ;
388+ } else {
389+ this . list = [ ...this . list , ...projects . results ] ;
390+ }
391+ this . searchedList = this . list ;
392+ this . cdref . detectChanges ( ) ;
393+ } )
394+ ) ;
378395
379396 case "members" :
380397 return this . programService . getAllMembers ( programId , offset , this . itemsPerPage ) . pipe (
@@ -411,7 +428,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
411428 }
412429 }
413430
414- // Построение запроса для фильтров (только для проектов)
415431 private buildFilterQuery ( q : any ) : Record < string , any > {
416432 if ( this . listType !== "projects" ) return { } ;
417433
@@ -439,7 +455,6 @@ export class ProgramListComponent implements OnInit, OnDestroy, AfterViewInit {
439455 this . availableFilters = filters ;
440456 }
441457
442- // Swipe логика для мобильных устройств
443458 private swipeStartY = 0 ;
444459 private swipeThreshold = 50 ;
445460 private isSwiping = false ;
0 commit comments