import { ActionType , createAction } from '@ulangi/ulangi-action' ; import { SetStatus } from '@ulangi/ulangi-common/enums' ; import { Set } from '@ulangi/ulangi-common/interfaces' ; import { EventBus } from '@ulangi/ulangi-event' ; export class SetListDelegate { private eventBus : EventBus ; public constructor ( eventBus ) { this . eventBus = eventBus ; } public hasActiveSets ( setList ) { const firstActiveSet = setList . find ( ( set ) : boolean => set . setStatus === SetStatus . ACTIVE ) ; return typeof firstActiveSet !== 'undefined' ; } public selectFirstActiveSet ( setList ) { const firstActiveSet = setList . find ( ( set ) : boolean => set . setStatus === SetStatus . ACTIVE ) ; if ( typeof firstActiveSet !== 'undefined' ) { this . eventBus . publish ( createAction ( ActionType . SET__SELECT , { setId : firstActiveSet . setId , } ) ) ; } } }