blob: 3e5de94896191ac87438b33452931cb6bdcf77ad [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001/*
simon26e79f72022-10-05 22:16:08 -04002 * Copyright (C) 2022 Savoir-faire Linux Inc.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Affero General Public License as
6 * published by the Free Software Foundation; either version 3 of the
7 * License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Affero General Public License for more details.
13 *
14 * You should have received a copy of the GNU Affero General Public
15 * License along with this program. If not, see
16 * <https://www.gnu.org/licenses/>.
17 */
idillon-sfl0e1a0d92022-10-25 16:52:44 -040018import './dayjsInitializer';
19
idillon-sfl837ea0b2022-08-25 11:35:29 -040020import { ThemeProvider } from '@mui/material/styles';
simon07b4eb02022-09-29 17:50:26 -040021import { useEffect, useState } from 'react';
22import { Navigate, Route, Routes } from 'react-router-dom';
Larbi Gharibe9af9732021-03-31 15:08:01 +010023
simon07b4eb02022-09-29 17:50:26 -040024import authManager from './AuthManager';
simond47ef9e2022-09-28 22:24:28 -040025import WelcomeAnimation from './components/welcome';
simonfe1de722022-10-02 00:21:43 -040026import NotFoundPage from './pages/404';
27import AccountCreationDialog from './pages/AccountCreation';
28import AccountSelection from './pages/AccountSelection';
29import AccountSettings from './pages/AccountSettings';
30import JamiAccountDialog from './pages/JamiAccountCreation';
31import JamiMessenger from './pages/JamiMessenger';
32import SignInPage from './pages/LoginDialog';
33import ServerSetup from './pages/ServerSetup';
simon35378692022-10-02 23:25:57 -040034import defaultTheme from './themes/Default';
ervinanoh8e918042022-09-06 10:30:59 -040035import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
Adrien Béraudab519ff2022-05-03 15:34:48 -040036
idillond858c182022-09-16 13:18:26 -040037// import { useSelector, useDispatch } from 'react-redux'
38// import { useAppSelector, useAppDispatch } from '../redux/hooks'
39
simon218d3d12022-10-01 17:27:01 -040040const Home = () => {
simond47ef9e2022-09-28 22:24:28 -040041 return <Navigate to="/account" />;
42};
Adrien Béraudab519ff2022-05-03 15:34:48 -040043
simon80b7b3b2022-09-28 17:50:10 -040044const App = () => {
idillond858c182022-09-16 13:18:26 -040045 // const count = useSelector(state => state.counter.value)
46 // const dispatch = useDispatch();
47 // const count = useAppSelector((state) => state.counter.value);
48 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040049
idillond858c182022-09-16 13:18:26 -040050 const [state, setState] = useState({
51 loaded: false,
52 auth: authManager.getState(),
53 });
54 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010055
idillond858c182022-09-16 13:18:26 -040056 useEffect(() => {
57 authManager.init((auth) => {
58 setState({ loaded: false, auth });
59 });
60 return () => authManager.deinit();
61 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040062
simond47ef9e2022-09-28 22:24:28 -040063 console.log('App render');
idillond858c182022-09-16 13:18:26 -040064
65 if (displayWelcome) {
simond47ef9e2022-09-28 22:24:28 -040066 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />;
idillond858c182022-09-16 13:18:26 -040067 } else if (!state.auth.setupComplete) {
68 return (
69 <Routes>
70 <Route path="/setup" element={<ServerSetup />} />
71 <Route path="/" element={<Navigate to="/setup" replace />} />
simon218d3d12022-10-01 17:27:01 -040072 <Route path="*" element={<Navigate to="/setup" replace />} />
idillond858c182022-09-16 13:18:26 -040073 </Routes>
74 );
75 }
76
77 return (
78 <ThemeProvider theme={defaultTheme}>
79 <Routes>
80 <Route path="/account">
81 <Route index element={<AccountSelection />} />
82 <Route path=":accountId">
idillon7f0b2882022-10-06 13:34:21 -040083 <Route index element={<JamiMessenger />} />
simon218d3d12022-10-01 17:27:01 -040084 <Route path="*" element={<JamiMessenger />} />
idillond858c182022-09-16 13:18:26 -040085 <Route path="settings" element={<AccountSettings />} />
86 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040087 </Route>
idillond858c182022-09-16 13:18:26 -040088 <Route path="/newAccount" element={<AccountCreationDialog />}>
89 <Route path="jami" element={<JamiAccountDialog />} />
90 </Route>
ervinanoh34eb9472022-09-13 04:20:28 -040091 {/* <Route path="/Contacts" element={<ContactList />} /> */}
ervinanoh8e918042022-09-06 10:30:59 -040092 <Route path="/Theme" element={<ThemeDemonstrator />} />
idillond858c182022-09-16 13:18:26 -040093 <Route path="/setup" element={<ServerSetup />} />
simon218d3d12022-10-01 17:27:01 -040094 <Route path="/" element={<Home />} />
idillond858c182022-09-16 13:18:26 -040095 <Route path="*" element={<NotFoundPage />} />
96 </Routes>
simond47ef9e2022-09-28 22:24:28 -040097 {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated} />}
Adrien Béraudab519ff2022-05-03 15:34:48 -040098 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040099 );
100};
Larbi Gharibe9af9732021-03-31 15:08:01 +0100101
simond47ef9e2022-09-28 22:24:28 -0400102export default App;