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