Skip to content
Snippets Groups Projects
app-wrapper.js 1.18 KiB
Newer Older
import React, { Component } from 'react'
import { View } from 'react-native'
import nodejs from 'nodejs-mobile-react-native'
import App from './app'
import PasswordPrompt from './password-prompt'
Julia Friesel's avatar
Julia Friesel committed
import License from './license'
import { getLicenseFlag } from '../local-storage'

export default class AppWrapper extends Component {
  constructor() {
    super()
Julia Friesel's avatar
Julia Friesel committed
    this.state = {
      retrievingLicenseSetting: true
Julia Friesel's avatar
Julia Friesel committed
    }
    nodejs.start('main.js')
Julia Friesel's avatar
Julia Friesel committed
    this.checkLicenseAgreement()
Julia Friesel's avatar
Julia Friesel committed

  async checkLicenseAgreement() {
    const agreed = await getLicenseFlag()
    this.setState({retrievingLicenseSetting: false})
    if (!agreed) this.setState({showLicense: true})
Julia Friesel's avatar
Julia Friesel committed
  }

    const whiteScreen = <View style={{ flex: 1 }}></View>
    const licenseScreen = <License setLicense={() => {
      this.setState({showLicense: false})
    }}/>
    const passwordPrompt = <PasswordPrompt showApp={() => {
      this.setState({showApp: true})
    }}/>

    if (this.state.retrievingLicenseSetting) {
      return whiteScreen
    } else if (this.state.showLicense) {
      return licenseScreen
    } else if (!this.state.showApp) {
      return passwordPrompt
    } else {
      return <App/>
    }