blob: accedf8c17615341e42a09e2c2ebaa15f4b8e3f9 [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-sfl837ea0b2022-08-25 11:35:29 -040018import { ThemeProvider } from '@mui/material/styles';
simon07b4eb02022-09-29 17:50:26 -040019import { useEffect, useState } from 'react';
20import { Navigate, Route, Routes } from 'react-router-dom';
Larbi Gharibe9af9732021-03-31 15:08:01 +010021
simon07b4eb02022-09-29 17:50:26 -040022import authManager from './AuthManager';
simond47ef9e2022-09-28 22:24:28 -040023import WelcomeAnimation from './components/welcome';
simonfe1de722022-10-02 00:21:43 -040024import NotFoundPage from './pages/404';
25import AccountCreationDialog from './pages/AccountCreation';
26import AccountSelection from './pages/AccountSelection';
27import AccountSettings from './pages/AccountSettings';
28import JamiAccountDialog from './pages/JamiAccountCreation';
29import JamiMessenger from './pages/JamiMessenger';
30import SignInPage from './pages/LoginDialog';
31import ServerSetup from './pages/ServerSetup';
simon35378692022-10-02 23:25:57 -040032import defaultTheme from './themes/Default';
ervinanoh8e918042022-09-06 10:30:59 -040033import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
Adrien Béraudab519ff2022-05-03 15:34:48 -040034
idillond858c182022-09-16 13:18:26 -040035// import { useSelector, useDispatch } from 'react-redux'
36// import { useAppSelector, useAppDispatch } from '../redux/hooks'
37
simon218d3d12022-10-01 17:27:01 -040038const Home = () => {
simond47ef9e2022-09-28 22:24:28 -040039 return <Navigate to="/account" />;
40};
Adrien Béraudab519ff2022-05-03 15:34:48 -040041
simon80b7b3b2022-09-28 17:50:10 -040042const App = () => {
idillond858c182022-09-16 13:18:26 -040043 // const count = useSelector(state => state.counter.value)
44 // const dispatch = useDispatch();
45 // const count = useAppSelector((state) => state.counter.value);
46 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040047
idillond858c182022-09-16 13:18:26 -040048 const [state, setState] = useState({
49 loaded: false,
50 auth: authManager.getState(),
51 });
52 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010053
idillond858c182022-09-16 13:18:26 -040054 useEffect(() => {
55 authManager.init((auth) => {
56 setState({ loaded: false, auth });
57 });
58 return () => authManager.deinit();
59 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040060
simond47ef9e2022-09-28 22:24:28 -040061 console.log('App render');
idillond858c182022-09-16 13:18:26 -040062
63 if (displayWelcome) {
simond47ef9e2022-09-28 22:24:28 -040064 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />;
idillond858c182022-09-16 13:18:26 -040065 } else if (!state.auth.setupComplete) {
66 return (
67 <Routes>
68 <Route path="/setup" element={<ServerSetup />} />
69 <Route path="/" element={<Navigate to="/setup" replace />} />
simon218d3d12022-10-01 17:27:01 -040070 <Route path="*" element={<Navigate to="/setup" replace />} />
idillond858c182022-09-16 13:18:26 -040071 </Routes>
72 );
73 }
74
75 return (
76 <ThemeProvider theme={defaultTheme}>
77 <Routes>
78 <Route path="/account">
79 <Route index element={<AccountSelection />} />
80 <Route path=":accountId">
idillon7f0b2882022-10-06 13:34:21 -040081 <Route index element={<JamiMessenger />} />
simon218d3d12022-10-01 17:27:01 -040082 <Route path="*" element={<JamiMessenger />} />
idillond858c182022-09-16 13:18:26 -040083 <Route path="settings" element={<AccountSettings />} />
84 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040085 </Route>
idillond858c182022-09-16 13:18:26 -040086 <Route path="/newAccount" element={<AccountCreationDialog />}>
87 <Route path="jami" element={<JamiAccountDialog />} />
88 </Route>
ervinanoh34eb9472022-09-13 04:20:28 -040089 {/* <Route path="/Contacts" element={<ContactList />} /> */}
ervinanoh8e918042022-09-06 10:30:59 -040090 <Route path="/Theme" element={<ThemeDemonstrator />} />
idillond858c182022-09-16 13:18:26 -040091 <Route path="/setup" element={<ServerSetup />} />
simon218d3d12022-10-01 17:27:01 -040092 <Route path="/" element={<Home />} />
idillond858c182022-09-16 13:18:26 -040093 <Route path="*" element={<NotFoundPage />} />
94 </Routes>
simond47ef9e2022-09-28 22:24:28 -040095 {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated} />}
Adrien Béraudab519ff2022-05-03 15:34:48 -040096 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040097 );
98};
Larbi Gharibe9af9732021-03-31 15:08:01 +010099
simond47ef9e2022-09-28 22:24:28 -0400100export default App;