Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 1 | /* |
| 2 | Company: Savoir-faire Linux |
| 3 | Author: Larbi Gharib <larbi.gharib@savoirfairelinux.com> |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 4 | License: AGPL-3 |
| 5 | */ |
idillon-sfl | 837ea0b | 2022-08-25 11:35:29 -0400 | [diff] [blame] | 6 | import { ThemeProvider } from '@mui/material/styles'; |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 7 | import React, { useState, useEffect } from 'react' |
idillon-sfl | 5d17455 | 2022-08-23 14:34:24 -0400 | [diff] [blame] | 8 | import { Route, Routes, Navigate } from 'react-router-dom' |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 9 | import authManager from './AuthManager' |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 10 | |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 11 | import SignInPage from "./pages/loginDialog.jsx" |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 12 | import JamiMessenger from "./pages/JamiMessenger.jsx" |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 13 | import AccountSettings from "./pages/accountSettings.jsx" |
| 14 | import AccountSelection from "./pages/accountSelection.jsx" |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 15 | import ServerSetup from "./pages/serverSetup.jsx" |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 16 | import AccountCreationDialog from "./pages/accountCreation.jsx" |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 17 | import NotFoundPage from "./pages/404.jsx" |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 18 | import JamiAccountDialog from './pages/jamiAccountCreation.jsx' |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 19 | import WelcomeAnimation from './components/welcome' |
idillon-sfl | 837ea0b | 2022-08-25 11:35:29 -0400 | [diff] [blame] | 20 | import defaultTheme from './themes/default' |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 21 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 22 | // import { useSelector, useDispatch } from 'react-redux' |
| 23 | // import { useAppSelector, useAppDispatch } from '../redux/hooks' |
| 24 | |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 25 | const Home = (props) => { |
| 26 | console.log(`home ${props}`) |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 27 | |
| 28 | return <Navigate to="/account" /> |
| 29 | } |
| 30 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 31 | const App = (props) => { |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 32 | // const count = useSelector(state => state.counter.value) |
| 33 | // const dispatch = useDispatch(); |
| 34 | // const count = useAppSelector((state) => state.counter.value); |
| 35 | // const dispatch = useAppDispatch(); |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 36 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 37 | const [state, setState] = useState({ |
| 38 | loaded: false, |
| 39 | auth: authManager.getState(), |
| 40 | }); |
| 41 | const [displayWelcome, setDisplayWelcome] = useState(true); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 42 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 43 | useEffect(() => { |
| 44 | authManager.init((auth) => { |
| 45 | setState({ loaded: false, auth }); |
| 46 | }); |
| 47 | return () => authManager.deinit(); |
| 48 | }, []); |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 49 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 50 | console.log("App render"); |
| 51 | |
| 52 | if (displayWelcome) { |
| 53 | return ( |
| 54 | <WelcomeAnimation |
| 55 | showSetup={!state.auth.setupComplete} |
| 56 | onComplete={() => setDisplayWelcome(false)} |
| 57 | /> |
| 58 | ); |
| 59 | } else if (!state.auth.setupComplete) { |
| 60 | return ( |
| 61 | <Routes> |
| 62 | <Route path="/setup" element={<ServerSetup />} /> |
| 63 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
| 64 | <Route index path="*" element={<Navigate to="/setup" replace />} /> |
| 65 | </Routes> |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | return ( |
| 70 | <ThemeProvider theme={defaultTheme}> |
| 71 | <Routes> |
| 72 | <Route path="/account"> |
| 73 | <Route index element={<AccountSelection />} /> |
| 74 | <Route path=":accountId"> |
| 75 | <Route index path="*" element={<JamiMessenger />} /> |
| 76 | <Route path="settings" element={<AccountSettings />} /> |
| 77 | </Route> |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 78 | </Route> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 79 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 80 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 81 | </Route> |
| 82 | <Route path="/setup" element={<ServerSetup />} /> |
| 83 | <Route path="/" index element={<Home />} /> |
| 84 | <Route path="*" element={<NotFoundPage />} /> |
| 85 | </Routes> |
| 86 | {!state.auth.authenticated && ( |
| 87 | <SignInPage key="signin" open={!state.auth.authenticated} /> |
| 88 | )} |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 89 | </ThemeProvider> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 90 | ); |
| 91 | }; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 92 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 93 | export default App |