import { Options } from '@ulangi/react-native-navigation' ; import { ActivityState , DiscoverListType , ScreenName , Theme , } from '@ulangi/ulangi-common/enums' ; import { ObservableDiscoverScreen , ObservablePublicSetListState , ObservablePublicVocabularyListState , ObservableTouchableTopBar , ObservableTranslationListState , } from '@ulangi/ulangi-observable' ; import { observable } from 'mobx' ; import { observer } from 'mobx-react' ; import * as React from 'react' ; import { Container , ContainerPassedProps } from '../../Container' ; import { DiscoverScreenIds } from '../../constants/ids/DiscoverScreenIds' ; import { DiscoverScreenFactory } from '../../factories/discover/DiscoverScreenFactory' ; import { DiscoverScreen } from './DiscoverScreen' ; import { DiscoverScreenStyle } from './DiscoverScreenContainer.style' ; @ observer export class DiscoverScreenContainer extends Container { public static options ( props ) { return props . theme === Theme . LIGHT ? DiscoverScreenStyle . SCREEN_FULL_LIGHT_STYLES : DiscoverScreenStyle . SCREEN_FULL_DARK_STYLES ; } private screenFactory = new DiscoverScreenFactory ( this . props , this . eventBus , this . observer ) ; private setSelectionMenuDelegate = this . screenFactory . createSetSelectionMenuDelegateWithStyles ( ) ; private navigatorDelegate = this . screenFactory . createNavigatorDelegate ( ) ; protected observableScreen = new ObservableDiscoverScreen ( observable . box ( '' ) , observable . box ( false ) , observable . box ( false ) , observable . box ( null ) , observable . box ( null ) , new ObservablePublicSetListState ( null , false , observable . box ( ActivityState . INACTIVE ) , observable . box ( false ) ) , new ObservablePublicVocabularyListState ( null , false , observable . box ( ActivityState . INACTIVE ) , observable . box ( false ) ) , new ObservableTranslationListState ( null , null , observable . box ( ActivityState . INACTIVE ) , observable . box ( undefined ) , observable . box ( false ) ) , this . props . componentId , ScreenName . DISCOVER_SCREEN , new ObservableTouchableTopBar ( DiscoverScreenIds . SHOW_SET_SELECTION_MENU_BTN , this . setSelectionMenuDelegate . getCurrentSetName ( ) , this . setSelectionMenuDelegate . getCurrentFlagIcon ( ) , ( ) : void => { this . setSelectionMenuDelegate . showActiveSetsForSetSelection ( ) ; } , null , null ) ) ; private screenDelegate = this . screenFactory . createScreenDelegate ( this . observableScreen ) ; public componentDidMount ( ) { this . setSelectionMenuDelegate . autoUpdateSubtitleOnSetChange ( this . observableScreen ) ; this . screenDelegate . autoRefreshOnSetChange ( ) ; if ( this . props . rootStore . setStore . existingCurrentSet . shouldShowPremadeFlashcards ) { this . observableScreen . listType . set ( DiscoverListType . PREMADE_SET_LIST ) ; this . screenDelegate . prepareAndSearch ( ) ; } } public componentWillUnmount ( ) { this . screenDelegate . clearAllList ( ) ; } protected onThemeChanged ( theme ) { this . navigatorDelegate . mergeOptions ( theme === Theme . LIGHT ? DiscoverScreenStyle . SCREEN_LIGHT_STYLES_ONLY : DiscoverScreenStyle . SCREEN_DARK_STYLES_ONLY ) ; } public render ( ) { return ( < DiscoverScreen setStore = { this . props . rootStore . setStore } themeStore = { this . props . rootStore . themeStore } observableScreen = { this . observableScreen } screenDelegate = { this . screenDelegate } / > ) ; } }