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' |
idillon | 531b6f2 | 2022-09-16 14:02:00 -0400 | [diff] [blame] | 21 | import ContactList from './components/ContactList'; |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 22 | import { ThemeDemonstrator } from './themes/ThemeDemonstrator'; |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 23 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 24 | // import { useSelector, useDispatch } from 'react-redux' |
| 25 | // import { useAppSelector, useAppDispatch } from '../redux/hooks' |
| 26 | |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 27 | const Home = (props) => { |
| 28 | console.log(`home ${props}`) |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 29 | |
| 30 | return <Navigate to="/account" /> |
| 31 | } |
| 32 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 33 | const App = (props) => { |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 34 | // const count = useSelector(state => state.counter.value) |
| 35 | // const dispatch = useDispatch(); |
| 36 | // const count = useAppSelector((state) => state.counter.value); |
| 37 | // const dispatch = useAppDispatch(); |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 38 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 39 | const [state, setState] = useState({ |
| 40 | loaded: false, |
| 41 | auth: authManager.getState(), |
| 42 | }); |
| 43 | const [displayWelcome, setDisplayWelcome] = useState(true); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 44 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 45 | useEffect(() => { |
| 46 | authManager.init((auth) => { |
| 47 | setState({ loaded: false, auth }); |
| 48 | }); |
| 49 | return () => authManager.deinit(); |
| 50 | }, []); |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 51 | |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 52 | console.log("App render"); |
| 53 | |
| 54 | if (displayWelcome) { |
| 55 | return ( |
| 56 | <WelcomeAnimation |
| 57 | showSetup={!state.auth.setupComplete} |
| 58 | onComplete={() => setDisplayWelcome(false)} |
| 59 | /> |
| 60 | ); |
| 61 | } else if (!state.auth.setupComplete) { |
| 62 | return ( |
| 63 | <Routes> |
| 64 | <Route path="/setup" element={<ServerSetup />} /> |
| 65 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
| 66 | <Route index path="*" element={<Navigate to="/setup" replace />} /> |
| 67 | </Routes> |
| 68 | ); |
| 69 | } |
| 70 | |
| 71 | return ( |
| 72 | <ThemeProvider theme={defaultTheme}> |
| 73 | <Routes> |
| 74 | <Route path="/account"> |
| 75 | <Route index element={<AccountSelection />} /> |
| 76 | <Route path=":accountId"> |
| 77 | <Route index path="*" element={<JamiMessenger />} /> |
| 78 | <Route path="settings" element={<AccountSettings />} /> |
| 79 | </Route> |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 80 | </Route> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 81 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 82 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 83 | </Route> |
ervinanoh | 34eb947 | 2022-09-13 04:20:28 -0400 | [diff] [blame] | 84 | {/* <Route path="/Contacts" element={<ContactList />} /> */} |
ervinanoh | 8e91804 | 2022-09-06 10:30:59 -0400 | [diff] [blame] | 85 | <Route path="/Theme" element={<ThemeDemonstrator />} /> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 86 | <Route path="/setup" element={<ServerSetup />} /> |
| 87 | <Route path="/" index element={<Home />} /> |
| 88 | <Route path="*" element={<NotFoundPage />} /> |
| 89 | </Routes> |
| 90 | {!state.auth.authenticated && ( |
| 91 | <SignInPage key="signin" open={!state.auth.authenticated} /> |
| 92 | )} |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 93 | </ThemeProvider> |
idillon | d858c18 | 2022-09-16 13:18:26 -0400 | [diff] [blame] | 94 | ); |
| 95 | }; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 96 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 97 | export default App |