import { Options } from '@ulangi/react-native-navigation' ; import { PublicVocabularyConverter } from '@ulangi/ulangi-common/converters' ; import { ContactUsFormType , ScreenName } from '@ulangi/ulangi-common/enums' ; import { PublicVocabulary , SelectionItem , } from '@ulangi/ulangi-common/interfaces' ; import { ObservableLightBox , ObservableSetStore , } from '@ulangi/ulangi-observable' ; import * as _ from 'lodash' ; import { PublicVocabularyActionMenuIds } from '../../constants/ids/PublicVocabularyActionMenuIds' ; import { NavigatorDelegate } from '../../delegates/navigator/NavigatorDelegate' ; export class PublicVocabularyActionMenuDelegate { private publicVocabularyConverter = new PublicVocabularyConverter ( ) ; private observableLightBox : ObservableLightBox ; private setStore : ObservableSetStore ; private navigatorDelegate : NavigatorDelegate ; private styles : { light : Options ; dark : Options ; } ; public constructor ( observableLightBox , setStore , navigatorDelegate , styles ) { this . observableLightBox = observableLightBox ; this . setStore = setStore ; this . navigatorDelegate = navigatorDelegate ; this . styles = styles ; } public show ( publicVocabulary ) { const items = [ this . getEditBeforeAddingButton ( publicVocabulary ) , this . getReportAnErrorButton ( publicVocabulary ) , ] ; this . observableLightBox . actionMenu = { testID : PublicVocabularyActionMenuIds . ACTION_MENU , title : 'Action' , items , } ; this . navigatorDelegate . showLightBox ( ScreenName . LIGHT_BOX_ACTION_MENU_SCREEN , { } , this . styles ) ; } private getEditBeforeAddingButton ( publicVocabulary ) { return { testID : PublicVocabularyActionMenuIds . EDIT_BEFORE_ADDING_BTN , text : 'Show editor' , onPress : ( ) : void => { const vocabulary = this . publicVocabularyConverter . convertToVocabulary ( publicVocabulary , _ . first ( publicVocabulary . categories ) ) ; this . navigatorDelegate . push ( ScreenName . ADD_VOCABULARY_SCREEN , { vocabulary , closeOnSaveSucceeded : true , } ) ; this . navigatorDelegate . dismissLightBox ( ) ; } , } ; } private getReportAnErrorButton ( publicVocabulary ) { return { testID : PublicVocabularyActionMenuIds . REPORT_ERRORS_BTN , text : 'Report an error' , onPress : ( ) : void => { const message = [ `Term: ${ publicVocabulary . vocabularyText }` , `Sources: ${ publicVocabulary . definitions . map ( ( definition ) : string => definition . source ) . join ( ', ' ) }` , `Languages: ${ this . setStore . existingCurrentSet . learningLanguageCode + '-' + this . setStore . existingCurrentSet . translatedToLanguageCode }` , 'Comments (optional): ' , ] . join ( '\n' ) ; this . navigatorDelegate . push ( ScreenName . CONTACT_US_SCREEN , { initialFormType : ContactUsFormType . REPORT_AN_ERROR , message , } ) ; this . navigatorDelegate . dismissLightBox ( ) ; } , } ; } }