blob: 3687dccb9c00258908b463b62db2071f0f6aa711 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001/*
2 Company: Savoir-faire Linux
3 Author: Larbi Gharib <larbi.gharib@savoirfairelinux.com>
Larbi Gharibe9af9732021-03-31 15:08:01 +01004 License: AGPL-3
5*/
Adrien Béraude74741b2021-04-19 13:22:54 -04006import React, { useState, useEffect } from 'react'
Adrien Béraud88a52442021-04-26 12:11:41 -04007import { Route, Switch, Redirect } from 'react-router-dom'
Adrien Béraud6ecaa402021-04-06 17:37:25 -04008import authManager from './AuthManager'
Adrien Béraude74741b2021-04-19 13:22:54 -04009//import logo from './logo.svg'
10import './App.scss'
Larbi Gharibe9af9732021-03-31 15:08:01 +010011
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040012import SignInPage from "./pages/loginDialog.jsx"
Adrien Béraud6c934962021-06-07 10:13:26 -040013import JamiMessenger from "./pages/JamiMessenger.jsx"
Adrien Béraud6ecaa402021-04-06 17:37:25 -040014import AccountSettings from "./pages/accountSettings.jsx"
15import AccountSelection from "./pages/accountSelection.jsx"
Adrien Béraude74741b2021-04-19 13:22:54 -040016import ServerSetup from "./pages/serverSetup.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040017import AccountCreationDialog from "./pages/accountCreation.jsx"
Larbi Gharibe9af9732021-03-31 15:08:01 +010018import NotFoundPage from "./pages/404.jsx"
Adrien Béraud150b4782021-04-21 19:40:59 -040019import LoadingPage from './components/loading'
Adrien Béraud88a52442021-04-26 12:11:41 -040020import JamiAccountDialog from './pages/jamiAccountCreation.jsx'
Adrien Béraud6c934962021-06-07 10:13:26 -040021import { AnimatePresence } from 'framer-motion'
Adrien Béraud34995902021-06-07 10:12:00 -040022import WelcomeAnimation from './components/welcome'
Larbi Gharibe9af9732021-03-31 15:08:01 +010023
Adrien Béraude74741b2021-04-19 13:22:54 -040024const App = (props) => {
Adrien Béraude74741b2021-04-19 13:22:54 -040025 const [state, setState] = useState({
26 loaded: false,
27 auth: authManager.getState()
28 })
Adrien Béraud34995902021-06-07 10:12:00 -040029 const [displayWelcome, setDisplayWelcome] = useState(true)
30
Adrien Béraude74741b2021-04-19 13:22:54 -040031 useEffect(() => {
32 authManager.init(auth => {
Adrien Béraud6c934962021-06-07 10:13:26 -040033 setState({ loaded: false, auth })
Adrien Béraude74741b2021-04-19 13:22:54 -040034 })
35 return () => authManager.deinit()
36 }, []);
Larbi Gharibe9af9732021-03-31 15:08:01 +010037
Adrien Béraud34995902021-06-07 10:12:00 -040038 console.log("App render")
39 if (displayWelcome) {
40 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />
Adrien Béraude74741b2021-04-19 13:22:54 -040041 } else if (!state.auth.setupComplete) {
42 return <Switch>
43 <Route path="/setup" component={ServerSetup} />
44 <Route><Redirect to="/setup" /></Route>
45 </Switch>
46 }
47 return <React.Fragment>
Adrien Béraud6c934962021-06-07 10:13:26 -040048 <Route
49 render={({ location }) => {
50 console.log("App render location")
51
52 return <AnimatePresence exitBeforeEnter initial={false}>
53 <Switch location={location} key={location.pathname}>
54 <Route exact path="/"><Redirect to="/account" /></Route>
55 <Route path="/account/:accountId/settings" component={AccountSettings} />
56 <Route path="/account/:accountId" component={JamiMessenger} />
57 <Route path="/account" component={AccountSelection} />
58 <Route path="/newAccount/jami" component={JamiAccountDialog} />
59 <Route path="/newAccount" component={AccountCreationDialog} />
60 <Route path="/setup"><Redirect to="/account" /></Route>
61 <Route component={NotFoundPage} />
62 </Switch>
63 {!state.auth.authenticated && <SignInPage open={!state.auth.authenticated}/>}
64 </AnimatePresence>}}
65 />
Adrien Béraude74741b2021-04-19 13:22:54 -040066 </React.Fragment>
Larbi Gharibe9af9732021-03-31 15:08:01 +010067}
68
Adrien Béraude74741b2021-04-19 13:22:54 -040069export default App