blob: 6d2284cf3b4fab71f25bcd874ccc38e035bc24d8 [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éraud6ecaa402021-04-06 17:37:25 -040013import JamiMessenger from "./pages/messenger.jsx"
14import 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éraud34995902021-06-07 10:12:00 -040021import WelcomeAnimation from './components/welcome'
Larbi Gharibe9af9732021-03-31 15:08:01 +010022
Adrien Béraude74741b2021-04-19 13:22:54 -040023const App = (props) => {
Adrien Béraude74741b2021-04-19 13:22:54 -040024 const [state, setState] = useState({
25 loaded: false,
26 auth: authManager.getState()
27 })
Adrien Béraud34995902021-06-07 10:12:00 -040028 const [displayWelcome, setDisplayWelcome] = useState(true)
29
Adrien Béraude74741b2021-04-19 13:22:54 -040030 useEffect(() => {
31 authManager.init(auth => {
32 setState({ loaded: true, auth })
33 })
34 return () => authManager.deinit()
35 }, []);
Larbi Gharibe9af9732021-03-31 15:08:01 +010036
Adrien Béraud34995902021-06-07 10:12:00 -040037 console.log("App render")
38 if (displayWelcome) {
39 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />
Adrien Béraude74741b2021-04-19 13:22:54 -040040 } else if (!state.auth.setupComplete) {
41 return <Switch>
42 <Route path="/setup" component={ServerSetup} />
43 <Route><Redirect to="/setup" /></Route>
44 </Switch>
45 }
46 return <React.Fragment>
Adrien Béraude74741b2021-04-19 13:22:54 -040047 <Switch>
48 <Route exact path="/"><Redirect to="/account" /></Route>
49 <Route path="/account/:accountId/settings" component={AccountSettings} />
50 <Route path="/account/:accountId/addContact/:contactId" component={JamiMessenger} />
51 <Route path="/account/:accountId/conversation/:conversationId" component={JamiMessenger} />
52 <Route path="/account/:accountId" component={JamiMessenger} />
53 <Route path="/account" component={AccountSelection} />
Adrien Béraud88a52442021-04-26 12:11:41 -040054 <Route path="/newAccount/jami" component={JamiAccountDialog} />
55 <Route path="/newAccount" component={AccountCreationDialog} />
Adrien Béraude74741b2021-04-19 13:22:54 -040056 <Route component={NotFoundPage} />
57 </Switch>
58 {!state.auth.authenticated && <SignInPage open={!state.auth.authenticated}/>}
59 </React.Fragment>
Larbi Gharibe9af9732021-03-31 15:08:01 +010060}
61
Adrien Béraude74741b2021-04-19 13:22:54 -040062export default App