import { DeepPartial } from '@ulangi/extended-types' ; import { ScreenName } from '@ulangi/ulangi-common/enums' ; import { Definition } from '@ulangi/ulangi-common/interfaces' ; import { ObservableDictionaryDefinition , ObservableDictionaryPickerScreen , ObservableTranslation , } from '@ulangi/ulangi-observable' ; import { boundClass } from 'autobind-decorator' ; import { DictionaryEntryDelegate } from '../dictionary/DictionaryEntryDelegate' ; import { NavigatorDelegate } from '../navigator/NavigatorDelegate' ; import { TranslationListDelegate } from '../translation/TranslationListDelegate' ; @ boundClass export class DictionaryPickerScreenDelegate { private observableScreen : ObservableDictionaryPickerScreen ; private dictionaryEntryDelegate : DictionaryEntryDelegate ; private translationListDelegate : TranslationListDelegate ; private navigatorDelegate : NavigatorDelegate ; private onPick : ( definition : DeepPartial < Definition > ) => void ; public constructor ( observableScreen , dictionaryEntryDelegate , translationListDelegate , navigatorDelegate , onPick ) { this . observableScreen = observableScreen ; this . dictionaryEntryDelegate = dictionaryEntryDelegate ; this . translationListDelegate = translationListDelegate ; this . navigatorDelegate = navigatorDelegate ; this . onPick = onPick ; } public getDictionaryEntry ( ) { this . dictionaryEntryDelegate . getDictionaryEntry ( this . observableScreen . currentTerm ) ; } public clearDictionaryEntry ( ) { this . dictionaryEntryDelegate . clearDictionaryEntry ( ) ; } public translate ( ) { this . translationListDelegate . translate ( this . observableScreen . currentTerm , 'google' ) ; } public clearTranslations ( ) { this . translationListDelegate . clearTranslations ( ) ; } public showLink ( link , screenTitle ) { this . navigatorDelegate . showModal ( ScreenName . BROWSER_SCREEN , { link , screenTitle , } ) ; } public close ( ) { this . navigatorDelegate . dismissLightBox ( ) ; } public onPickDictionaryDefinition ( definition ) { definition . isAdded = true ; this . onPick ( { meaning : definition . meaning , wordClasses : definition . wordClasses , source : definition . source , } ) ; } public onPickTranslation ( translation ) { translation . isAdded = true ; this . onPick ( { meaning : translation . translatedText , wordClasses : [ ] , source : translation . translatedBy , } ) ; } }