blob: d0043df992404b710b272dfeaf5c81cb69002db5 [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*/
idillon-sfl837ea0b2022-08-25 11:35:29 -04006import { ThemeProvider } from '@mui/material/styles';
Adrien Béraude74741b2021-04-19 13:22:54 -04007import React, { useState, useEffect } from 'react'
idillon-sfl5d174552022-08-23 14:34:24 -04008import { Route, Routes, Navigate } from 'react-router-dom'
Adrien Béraud6ecaa402021-04-06 17:37:25 -04009import authManager from './AuthManager'
Larbi Gharibe9af9732021-03-31 15:08:01 +010010
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040011import SignInPage from "./pages/loginDialog.jsx"
Adrien Béraud6c934962021-06-07 10:13:26 -040012import JamiMessenger from "./pages/JamiMessenger.jsx"
Adrien Béraud6ecaa402021-04-06 17:37:25 -040013import AccountSettings from "./pages/accountSettings.jsx"
14import AccountSelection from "./pages/accountSelection.jsx"
Adrien Béraude74741b2021-04-19 13:22:54 -040015import ServerSetup from "./pages/serverSetup.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040016import AccountCreationDialog from "./pages/accountCreation.jsx"
Larbi Gharibe9af9732021-03-31 15:08:01 +010017import NotFoundPage from "./pages/404.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040018import JamiAccountDialog from './pages/jamiAccountCreation.jsx'
Adrien Béraud34995902021-06-07 10:12:00 -040019import WelcomeAnimation from './components/welcome'
idillon-sfl837ea0b2022-08-25 11:35:29 -040020import defaultTheme from './themes/default'
Adrien Béraudab519ff2022-05-03 15:34:48 -040021
idillond858c182022-09-16 13:18:26 -040022// import { useSelector, useDispatch } from 'react-redux'
23// import { useAppSelector, useAppDispatch } from '../redux/hooks'
24
Adrien Béraudab519ff2022-05-03 15:34:48 -040025const Home = (props) => {
26 console.log(`home ${props}`)
Adrien Béraudab519ff2022-05-03 15:34:48 -040027
28 return <Navigate to="/account" />
29}
30
Adrien Béraude74741b2021-04-19 13:22:54 -040031const App = (props) => {
idillond858c182022-09-16 13:18:26 -040032 // const count = useSelector(state => state.counter.value)
33 // const dispatch = useDispatch();
34 // const count = useAppSelector((state) => state.counter.value);
35 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040036
idillond858c182022-09-16 13:18:26 -040037 const [state, setState] = useState({
38 loaded: false,
39 auth: authManager.getState(),
40 });
41 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010042
idillond858c182022-09-16 13:18:26 -040043 useEffect(() => {
44 authManager.init((auth) => {
45 setState({ loaded: false, auth });
46 });
47 return () => authManager.deinit();
48 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040049
idillond858c182022-09-16 13:18:26 -040050 console.log("App render");
51
52 if (displayWelcome) {
53 return (
54 <WelcomeAnimation
55 showSetup={!state.auth.setupComplete}
56 onComplete={() => setDisplayWelcome(false)}
57 />
58 );
59 } else if (!state.auth.setupComplete) {
60 return (
61 <Routes>
62 <Route path="/setup" element={<ServerSetup />} />
63 <Route path="/" element={<Navigate to="/setup" replace />} />
64 <Route index path="*" element={<Navigate to="/setup" replace />} />
65 </Routes>
66 );
67 }
68
69 return (
70 <ThemeProvider theme={defaultTheme}>
71 <Routes>
72 <Route path="/account">
73 <Route index element={<AccountSelection />} />
74 <Route path=":accountId">
75 <Route index path="*" element={<JamiMessenger />} />
76 <Route path="settings" element={<AccountSettings />} />
77 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040078 </Route>
idillond858c182022-09-16 13:18:26 -040079 <Route path="/newAccount" element={<AccountCreationDialog />}>
80 <Route path="jami" element={<JamiAccountDialog />} />
81 </Route>
82 <Route path="/setup" element={<ServerSetup />} />
83 <Route path="/" index element={<Home />} />
84 <Route path="*" element={<NotFoundPage />} />
85 </Routes>
86 {!state.auth.authenticated && (
87 <SignInPage key="signin" open={!state.auth.authenticated} />
88 )}
Adrien Béraudab519ff2022-05-03 15:34:48 -040089 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040090 );
91};
Larbi Gharibe9af9732021-03-31 15:08:01 +010092
Adrien Béraude74741b2021-04-19 13:22:54 -040093export default App