import { ActionType } from '@ulangi/ulangi-action' ; import { ScreenName } from '@ulangi/ulangi-common/enums' ; import { EventBus , group , on } from '@ulangi/ulangi-event' ; import { ObservableSearchScreen , ObservableVocabulary , } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { VocabularyActionMenuDelegate } from '../vocabulary/VocabularyActionMenuDelegate' ; import { VocabularyBulkActionMenuDelegate } from '../vocabulary/VocabularyBulkActionMenuDelegate' ; import { VocabularyEventDelegate } from '../vocabulary/VocabularyEventDelegate' ; import { VocabularySelectionDelegate } from '../vocabulary/VocabularySelectionDelegate' ; import { SearchVocabularyDelegate } from './SearchVocabularyDelegate' ; @ boundClass export class SearchScreenDelegate { private eventBus : EventBus ; private observableScreen : ObservableSearchScreen ; private searchVocabularyDelegate : SearchVocabularyDelegate ; private vocabularyEventDelegate : VocabularyEventDelegate ; private vocabularyActionMenuDelegate : VocabularyActionMenuDelegate ; private vocabularyBulkActionMenuDelegate : VocabularyBulkActionMenuDelegate ; private vocabularySelectionDelegate : VocabularySelectionDelegate ; private navigatorDelegate : NavigatorDelegate ; public constructor ( eventBus , observableScreen , searchVocabularyDelegate , vocabularyEventDelegate , vocabularyActionMenuDelegate , vocabularyBulkActionMenuDelegate , vocabularySelectionDelegate , navigatorDelegate ) { this . eventBus = eventBus ; this . observableScreen = observableScreen ; this . searchVocabularyDelegate = searchVocabularyDelegate ; this . vocabularyEventDelegate = vocabularyEventDelegate ; this . vocabularyActionMenuDelegate = vocabularyActionMenuDelegate ; this . vocabularyBulkActionMenuDelegate = vocabularyBulkActionMenuDelegate ; this . vocabularySelectionDelegate = vocabularySelectionDelegate ; this . navigatorDelegate = navigatorDelegate ; } public handleSearchInputEnd ( ) { this . refresh ( this . observableScreen . searchInput ) ; } public prepareAndSearch ( searchTerm ) { this . searchVocabularyDelegate . prepareAndSearch ( searchTerm ) ; } public search ( ) { this . searchVocabularyDelegate . search ( ) ; } public clearSearch ( ) { this . searchVocabularyDelegate . clearSearch ( ) ; } public refresh ( searchTerm ) { this . searchVocabularyDelegate . refresh ( searchTerm ) ; } public refreshCurrentList ( ) { this . refresh ( this . observableScreen . searchInput ) ; } public autoRefreshOnSetChange ( ) { this . eventBus . subscribe ( on ( ActionType . SET__SELECT , ( ) : void => this . refreshCurrentList ( ) ) ) ; } public autoRefreshOnMultipleEdit ( ) { this . eventBus . subscribe ( on ( ActionType . VOCABULARY__EDIT_MULTIPLE_SUCCEEDED , ( ) : void => { this . refreshCurrentList ( ) ; } ) ) ; } public autoShowSyncCompleted ( ) { this . vocabularyEventDelegate . onDownloadVocabularyCompleted ( ( ) : void => { this . observableScreen . vocabularyListState . shouldShowRefreshNotice . set ( true ) ; } ) ; } public autoShowSyncingInProgress ( ) { this . eventBus . subscribe ( group ( on ( [ ActionType . SYNC__STOP , ActionType . SYNC__SYNC_COMPLETED ] , ( ) : void => { this . observableScreen . vocabularyListState . shouldShowSyncingNotice . set ( false ) ; } ) , on ( ActionType . SYNC__SYNCING , ( ) : void => { this . observableScreen . vocabularyListState . shouldShowSyncingNotice . set ( true ) ; } ) ) ) ; } public showVocabularyDetail ( vocabulary ) { this . navigatorDelegate . push ( ScreenName . VOCABULARY_DETAIL_SCREEN , { vocabulary , } ) ; } public showVocabularyActionMenu ( vocabulary ) { this . vocabularyActionMenuDelegate . show ( vocabulary ) ; } public showVocabularyBulkActionMenu ( ) { this . vocabularyBulkActionMenuDelegate . show ( ) ; } public toggleSelection ( vocabularyId ) { this . vocabularySelectionDelegate . toggleSelection ( vocabularyId ) ; } public clearSelections ( ) { this . vocabularySelectionDelegate . clearSelections ( ) ; } }