refactor: AppContext and App entrypoints

This commit is contained in:
Sérgio Salgado 2021-03-03 17:05:26 +00:00 committed by Josh Harvey
parent 442e7cd8d9
commit dd0abc8a8b
7 changed files with 32 additions and 10 deletions

View file

@ -2,3 +2,4 @@ SKIP_PREFLIGHT_CHECK=true
HTTPS=true
REACT_APP_TYPE_CHECK_SANCTUARY=false
PORT=3001
REACT_APP_BUILD_TARGET=LAMASSU

View file

@ -88,7 +88,9 @@
"eject": "react-scripts eject",
"storybook": "start-storybook -p 9009 -s public",
"postinstall": "patch-package",
"build-storybook": "build-storybook -s public"
"build-storybook": "build-storybook -s public",
"start-lamassu": "REACT_APP_BUILD_TARGET=LAMASSU react-scripts start",
"start-pazuz": "REACT_APP_BUILD_TARGET=PAZUZ react-scripts start"
},
"browserslist": {
"production": [

View file

@ -9,13 +9,14 @@ import {
} from '@material-ui/core/styles'
import { create } from 'jss'
import extendJss from 'jss-plugin-extend'
import React, { createContext, useContext, useState } from 'react'
import React, { useContext, useState } from 'react'
import {
useLocation,
useHistory,
BrowserRouter as Router
} from 'react-router-dom'
import AppContext from 'src/AppContext'
import Sidebar from 'src/components/layout/Sidebar'
import TitleSection from 'src/components/layout/TitleSection'
import ApolloProvider from 'src/utils/apollo'
@ -69,8 +70,6 @@ const useStyles = makeStyles({
}
})
const AppContext = createContext()
const Main = () => {
const classes = useStyles()
const location = useLocation()
@ -148,4 +147,3 @@ const App = () => {
}
export default App
export { AppContext }

View file

@ -0,0 +1,3 @@
import React from 'react'
export default React.createContext()

View file

@ -1,10 +1,28 @@
import React from 'react'
import ReactDOM from 'react-dom'
import App from './App'
import * as serviceWorker from './serviceWorker'
ReactDOM.render(<App />, document.getElementById('root'))
function importBuildTarget() {
if (process.env.REACT_APP_BUILD_TARGET === 'LAMASSU') {
return import('./App')
} else if (process.env.REACT_APP_BUILD_TARGET === 'PAZUZ') {
return import('./pazuz/App')
} else {
return Promise.reject(
new Error('No such build target: ' + process.env.REACT_APP_BUILD_TARGET)
)
}
}
importBuildTarget().then(({ default: Environment }) =>
ReactDOM.render(
<React.StrictMode>
<Environment />
</React.StrictMode>,
document.getElementById('root')
)
)
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.

View file

@ -5,7 +5,7 @@ import gql from 'graphql-tag'
import React, { useState, useContext } from 'react'
import { useHistory } from 'react-router-dom'
import { AppContext } from 'src/App'
import AppContext from 'src/AppContext'
import { getWizardStep, STEPS } from 'src/pages/Wizard/helper'
import { backgroundColor } from 'src/styling/variables'

View file

@ -12,7 +12,7 @@ import {
useLocation
} from 'react-router-dom'
import { AppContext } from 'src/App'
import AppContext from 'src/AppContext'
import AuthRegister from 'src/pages/AuthRegister'
import Blacklist from 'src/pages/Blacklist'
import Cashout from 'src/pages/Cashout'