import { Component , Input } from '@angular/core' ; import { JurySessionService } from './session.service' ; import { BehaviorSubject } from 'rxjs' ; import { take } from 'rxjs/operators' ; import { AbstractSubscriberComponent } from '../../../../common/components/abstract-subscriber/abstract-subscriber.component' ; @ Component ( { selector : 'm-jurydutySession__list' , templateUrl : 'list.component.html' , } ) export class JuryDutySessionListComponent extends AbstractSubscriberComponent { @ Input ( ) juryType = 'appeal' ; offset = null ; hasNext = true ; count : number = 0 ; public readonly reports$ : BehaviorSubject < any [ ] > = new BehaviorSubject < any [ ] > ( [ ] ) ; public readonly inProgress$ : BehaviorSubject < boolean > = new BehaviorSubject < boolean > ( true ) ; constructor ( private sessionService ) { super ( ) ; } ngOnInit ( ) { this . load ( ) ; } async load ( ) { this . inProgress$ . next ( true ) ; let result = await this . sessionService . getList ( { juryType : this . juryType , } ) ; this . count = result [ 'count' ] ; this . hasNext = result [ 'has-next' ] ; this . offset = result [ 'load-next' ] ; this . reports$ . next ( result . reports ) ; this . inProgress$ . next ( false ) ; } returns { Promise < void > } async loadMore ( ) { this . inProgress$ . next ( true ) ; let result = await this . sessionService . getList ( { juryType : this . juryType , offset : this . offset , } ) ; this . offset = result [ 'load-next' ] ; this . hasNext = result [ 'has-next' ] ; if ( result && result . reports && result . reports . length ) { this . subscriptions . push ( this . reports$ . pipe ( take ( 1 ) ) . subscribe ( existingReports => { this . reports$ . next ( [ ... existingReports , ... result . reports ] ) ; } ) ) ; } this . inProgress$ . next ( false ) ; } }