Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 1 | /* |
simon | 26e79f7 | 2022-10-05 22:16:08 -0400 | [diff] [blame] | 2 | * 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-sfl | 0e1a0d9 | 2022-10-25 16:52:44 -0400 | [diff] [blame] | 18 | import './dayjsInitializer'; |
| 19 | |
idillon-sfl | 837ea0b | 2022-08-25 11:35:29 -0400 | [diff] [blame] | 20 | import { ThemeProvider } from '@mui/material/styles'; |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 21 | import { useEffect, useState } from 'react'; |
| 22 | import { Navigate, Route, Routes } from 'react-router-dom'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 23 | |
simon | 07b4eb0 | 2022-09-29 17:50:26 -0400 | [diff] [blame] | 24 | import authManager from './AuthManager'; |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 25 | import WelcomeAnimation from './components/welcome'; |
simon | fe1de72 | 2022-10-02 00:21:43 -0400 | [diff] [blame] | 26 | import NotFoundPage from './pages/404'; |
| 27 | import AccountCreationDialog from './pages/AccountCreation'; |
| 28 | import AccountSelection from './pages/AccountSelection'; |
| 29 | import AccountSettings from './pages/AccountSettings'; |
| 30 | import JamiAccountDialog from './pages/JamiAccountCreation'; |
| 31 | import JamiMessenger from './pages/JamiMessenger'; |
| 32 | import SignInPage from './pages/LoginDialog'; |
| 33 | import ServerSetup from './pages/ServerSetup'; |
simon | 3537869 | 2022-10-02 23:25:57 -0400 | [diff] [blame] | 34 | import defaultTheme from './themes/Default'; |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 35 | import { ThemeDemonstrator } from './themes/ThemeDemonstrator'; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 36 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 37 | // import { useSelector, useDispatch } from 'react-redux' |
| 38 | // import { useAppSelector, useAppDispatch } from '../redux/hooks' |
| 39 | |
simon | 218d3d1 | 2022-10-01 17:27:01 -0400 | [diff] [blame] | 40 | const Home = () => { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 41 | return <Navigate to="/account" />; |
| 42 | }; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 43 | |
simon | 80b7b3b | 2022-09-28 17:50:10 -0400 | [diff] [blame] | 44 | const App = () => { |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 45 | // 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éraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 49 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 50 | const [state, setState] = useState({ |
| 51 | loaded: false, |
| 52 | auth: authManager.getState(), |
| 53 | }); |
| 54 | const [displayWelcome, setDisplayWelcome] = useState(true); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 55 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 56 | useEffect(() => { |
| 57 | authManager.init((auth) => { |
| 58 | setState({ loaded: false, auth }); |
| 59 | }); |
| 60 | return () => authManager.deinit(); |
| 61 | }, []); |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 62 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 63 | console.log('App render'); |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 64 | |
| 65 | if (displayWelcome) { |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 66 | return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />; |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 67 | } else if (!state.auth.setupComplete) { |
| 68 | return ( |
| 69 | <Routes> |
| 70 | <Route path="/setup" element={<ServerSetup />} /> |
| 71 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
simon | 218d3d1 | 2022-10-01 17:27:01 -0400 | [diff] [blame] | 72 | <Route path="*" element={<Navigate to="/setup" replace />} /> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 73 | </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"> |
idillon | 7f0b288 | 2022-10-06 13:34:21 -0400 | [diff] [blame] | 83 | <Route index element={<JamiMessenger />} /> |
simon | 218d3d1 | 2022-10-01 17:27:01 -0400 | [diff] [blame] | 84 | <Route path="*" element={<JamiMessenger />} /> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 85 | <Route path="settings" element={<AccountSettings />} /> |
| 86 | </Route> |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 87 | </Route> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 88 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 89 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 90 | </Route> |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 91 | {/* <Route path="/Contacts" element={<ContactList />} /> */} |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 92 | <Route path="/Theme" element={<ThemeDemonstrator />} /> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 93 | <Route path="/setup" element={<ServerSetup />} /> |
simon | 218d3d1 | 2022-10-01 17:27:01 -0400 | [diff] [blame] | 94 | <Route path="/" element={<Home />} /> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 95 | <Route path="*" element={<NotFoundPage />} /> |
| 96 | </Routes> |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 97 | {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated} />} |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 98 | </ThemeProvider> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 99 | ); |
| 100 | }; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 101 | |
simon | d47ef9e | 2022-09-28 22:24:28 -0400 | [diff] [blame] | 102 | export default App; |