import { Options } from '@ulangi/react-native-navigation' ; import { ActivityState , ScreenName , Theme , VocabularySortType , VocabularyStatus , } from '@ulangi/ulangi-common/enums' ; import { Category } from '@ulangi/ulangi-common/interfaces' ; import { ObservableCategoryDetailScreen , ObservableTitleTopBar , ObservableTopBarButton , ObservableVocabularyListState , } from '@ulangi/ulangi-observable' ; import { observable } from 'mobx' ; import { observer } from 'mobx-react' ; import * as React from 'react' ; import { Container , ContainerPassedProps } from '../../Container' ; import { Images } from '../../constants/Images' ; import { CategoryDetailScreenIds } from '../../constants/ids/CategoryDetailScreenIds' ; import { CategoryDetailScreenFactory } from '../../factories/category/CategoryDetailScreenFactory' ; import { CategoryDetailScreen } from './CategoryDetailScreen' ; import { CategoryDetailScreenStyle } from './CategoryDetailScreenContainer.style' ; export interface CategoryDetailScreenPassedProps { readonly selectedVocabularyStatus : VocabularyStatus ; readonly category : Category ; } @ observer export class CategoryDetailScreenContainer extends Container < CategoryDetailScreenPassedProps > { public static options ( props ) { return props . theme === Theme . LIGHT ? CategoryDetailScreenStyle . SCREEN_FULL_LIGHT_STYLES : CategoryDetailScreenStyle . SCREEN_FULL_DARK_STYLES ; } private screenFactory = new CategoryDetailScreenFactory ( this . props , this . eventBus , this . observer ) ; protected observableScreen = new ObservableCategoryDetailScreen ( this . props . observableConverter . convertToObservableCategory ( this . props . passedProps . category ) , observable . box ( this . props . passedProps . selectedVocabularyStatus ) , observable . box ( VocabularySortType . SORT_BY_NAME_ASC ) , new ObservableVocabularyListState ( null , false , observable . box ( ActivityState . INACTIVE ) , observable . box ( this . props . rootStore . syncStore . currentState === 'SYNCING' ) , observable . box ( false ) , observable . box ( false ) , observable . box ( false ) ) , this . props . componentId , ScreenName . CATEGORY_DETAIL_SCREEN , new ObservableTitleTopBar ( this . props . passedProps . category . categoryName , new ObservableTopBarButton ( CategoryDetailScreenIds . BACK_BTN , null , { light : Images . ARROW_LEFT_BLACK_22X22 , dark : Images . ARROW_LEFT_MILK_22X22 , } , ( ) : void => { this . navigatorDelegate . dismissScreen ( ) ; } ) , null ) ) ; private navigatorDelegate = this . screenFactory . createNavigatorDelegate ( ) ; private screenDelegate = this . screenFactory . createScreenDelegate ( this . observableScreen ) ; public componentDidMount ( ) { this . screenDelegate . autoUpdateEditedVocabulary ( ) ; this . screenDelegate . autoRefreshOnMultipleEdit ( ) ; this . screenDelegate . autoShowRefreshNotice ( ) ; this . screenDelegate . autoShowSyncingInProgress ( ) ; this . screenDelegate . prepareAndFetch ( ) ; } public componentWillUnmount ( ) { this . screenDelegate . clearFetch ( ) ; } public componentDidAppear ( ) { if ( this . observableScreen . vocabularyListState . shouldShowRefreshNotice . get ( ) ) { this . screenDelegate . refresh ( ) ; } } protected onThemeChanged ( theme ) { this . navigatorDelegate . mergeOptions ( theme === Theme . LIGHT ? CategoryDetailScreenStyle . SCREEN_LIGHT_STYLES_ONLY : CategoryDetailScreenStyle . SCREEN_DARK_STYLES_ONLY ) ; } public render ( ) { return ( < CategoryDetailScreen themeStore = { this . props . rootStore . themeStore } observableScreen = { this . observableScreen } screenDelegate = { this . screenDelegate } / > ) ; } }