Newer
Older
import React, { Component } from 'react'
import nodejs from 'nodejs-mobile-react-native'
import { getLicenseFlag, saveEncryptionFlag } from '../local-storage'
import { openDb } from '../db'
import App from './app'
import PasswordPrompt from './password-prompt'
import AppLoadingView from './app-loading'
import { combineReducers } from 'redux'
import { configureStore } from 'redux-starter-kit'
import { Provider } from 'react-redux'
import dateReducer from '../slices/date'
const rootReducer = combineReducers({
dateReducer,
})
const store = configureStore({ reducer: rootReducer })
export default class AppWrapper extends Component {
constructor() {
super()
isCheckingLicenseAgreement: true,
shouldShowLicenseAgreement: false,
shouldShowPasswordPrompt: false,
shouldShowApp: false,
nodejs.start('main.js')
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const isLicenseFlagSet = await getLicenseFlag()
if (!isLicenseFlagSet) {
this.enableShowLicenseAgreement()
} else {
this.setState({ isCheckingLicenseAgreement: false })
}
}
async checkDbPasswordSet() {
const canConnectToDb = await openDb()
if (canConnectToDb) {
this.enableShowApp()
await saveEncryptionFlag(false)
return false
}
this.setState({ shouldShowPasswordPrompt: true })
await saveEncryptionFlag(true)
}
enableShowLicenseAgreement = () => {
this.setState({
shouldShowLicenseAgreement: true,
isCheckingLicenseAgreement: false
})
}
disableShowLicenseAgreement = () => {
this.setState({ shouldShowLicenseAgreement: false })
}
enableShowApp = () => {
this.setState({
shouldShowApp: true,
shouldShowPasswordPrompt: false
})
const {
isCheckingLicenseAgreement,
shouldShowLicenseAgreement,
shouldShowPasswordPrompt,
shouldShowApp,
} = this.state
if (isCheckingLicenseAgreement) {
initialView = <AppLoadingView />
} else if (shouldShowLicenseAgreement) {
initialView = <License setLicense={this.disableShowLicenseAgreement}/>
} else if (shouldShowPasswordPrompt) {
initialView = <PasswordPrompt enableShowApp={this.enableShowApp} />
} else if (shouldShowApp) {
initialView = <App />
return <Provider store={store}>{initialView}</Provider>