blob: 65c9400abf30336c1e1e4dee3627999198fe0d95 [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';
simond47ef9e2022-09-28 22:24:28 -04007import { useState, useEffect } from 'react';
8import { Route, Routes, Navigate } from 'react-router-dom';
9import authManager from './AuthManager';
Larbi Gharibe9af9732021-03-31 15:08:01 +010010
simond47ef9e2022-09-28 22:24:28 -040011import SignInPage from './pages/loginDialog.jsx';
12import JamiMessenger from './pages/JamiMessenger.jsx';
13import AccountSettings from './pages/accountSettings.jsx';
14import AccountSelection from './pages/accountSelection.jsx';
15import ServerSetup from './pages/serverSetup.jsx';
16import AccountCreationDialog from './pages/accountCreation.jsx';
17import NotFoundPage from './pages/404.jsx';
18import JamiAccountDialog from './pages/jamiAccountCreation.jsx';
19import WelcomeAnimation from './components/welcome';
20import defaultTheme from './themes/default';
ervinanoh8e918042022-09-06 10:30:59 -040021import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
Adrien Béraudab519ff2022-05-03 15:34:48 -040022
idillond858c182022-09-16 13:18:26 -040023// import { useSelector, useDispatch } from 'react-redux'
24// import { useAppSelector, useAppDispatch } from '../redux/hooks'
25
Adrien Béraudab519ff2022-05-03 15:34:48 -040026const Home = (props) => {
simond47ef9e2022-09-28 22:24:28 -040027 console.log(`home ${props}`);
Adrien Béraudab519ff2022-05-03 15:34:48 -040028
simond47ef9e2022-09-28 22:24:28 -040029 return <Navigate to="/account" />;
30};
Adrien Béraudab519ff2022-05-03 15:34:48 -040031
Adrien Béraude74741b2021-04-19 13:22:54 -040032const App = (props) => {
idillond858c182022-09-16 13:18:26 -040033 // const count = useSelector(state => state.counter.value)
34 // const dispatch = useDispatch();
35 // const count = useAppSelector((state) => state.counter.value);
36 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040037
idillond858c182022-09-16 13:18:26 -040038 const [state, setState] = useState({
39 loaded: false,
40 auth: authManager.getState(),
41 });
42 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010043
idillond858c182022-09-16 13:18:26 -040044 useEffect(() => {
45 authManager.init((auth) => {
46 setState({ loaded: false, auth });
47 });
48 return () => authManager.deinit();
49 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040050
simond47ef9e2022-09-28 22:24:28 -040051 console.log('App render');
idillond858c182022-09-16 13:18:26 -040052
53 if (displayWelcome) {
simond47ef9e2022-09-28 22:24:28 -040054 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />;
idillond858c182022-09-16 13:18:26 -040055 } else if (!state.auth.setupComplete) {
56 return (
57 <Routes>
58 <Route path="/setup" element={<ServerSetup />} />
59 <Route path="/" element={<Navigate to="/setup" replace />} />
60 <Route index path="*" element={<Navigate to="/setup" replace />} />
61 </Routes>
62 );
63 }
64
65 return (
66 <ThemeProvider theme={defaultTheme}>
67 <Routes>
68 <Route path="/account">
69 <Route index element={<AccountSelection />} />
70 <Route path=":accountId">
71 <Route index path="*" element={<JamiMessenger />} />
72 <Route path="settings" element={<AccountSettings />} />
73 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040074 </Route>
idillond858c182022-09-16 13:18:26 -040075 <Route path="/newAccount" element={<AccountCreationDialog />}>
76 <Route path="jami" element={<JamiAccountDialog />} />
77 </Route>
ervinanoh34eb9472022-09-13 04:20:28 -040078 {/* <Route path="/Contacts" element={<ContactList />} /> */}
ervinanoh8e918042022-09-06 10:30:59 -040079 <Route path="/Theme" element={<ThemeDemonstrator />} />
idillond858c182022-09-16 13:18:26 -040080 <Route path="/setup" element={<ServerSetup />} />
81 <Route path="/" index element={<Home />} />
82 <Route path="*" element={<NotFoundPage />} />
83 </Routes>
simond47ef9e2022-09-28 22:24:28 -040084 {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated} />}
Adrien Béraudab519ff2022-05-03 15:34:48 -040085 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040086 );
87};
Larbi Gharibe9af9732021-03-31 15:08:01 +010088
simond47ef9e2022-09-28 22:24:28 -040089export default App;