blob: b10d30383801d58e9d4922cff344cb903200be99 [file] [log] [blame]
Larbi Gharibe9af9732021-03-31 15:08:01 +01001/*
2 Company: Savoir-faire Linux
3 Author: Larbi Gharib <larbi.gharib@savoirfairelinux.com>
Larbi Gharibe9af9732021-03-31 15:08:01 +01004 License: AGPL-3
5*/
idillon-sfl837ea0b2022-08-25 11:35:29 -04006import { ThemeProvider } from '@mui/material/styles';
Adrien Béraude74741b2021-04-19 13:22:54 -04007import React, { useState, useEffect } from 'react'
idillon-sfl5d174552022-08-23 14:34:24 -04008import { Route, Routes, Navigate } from 'react-router-dom'
Adrien Béraud6ecaa402021-04-06 17:37:25 -04009import authManager from './AuthManager'
Larbi Gharibe9af9732021-03-31 15:08:01 +010010
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040011import SignInPage from "./pages/loginDialog.jsx"
Adrien Béraud6c934962021-06-07 10:13:26 -040012import JamiMessenger from "./pages/JamiMessenger.jsx"
Adrien Béraud6ecaa402021-04-06 17:37:25 -040013import AccountSettings from "./pages/accountSettings.jsx"
14import AccountSelection from "./pages/accountSelection.jsx"
Adrien Béraude74741b2021-04-19 13:22:54 -040015import ServerSetup from "./pages/serverSetup.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040016import AccountCreationDialog from "./pages/accountCreation.jsx"
Larbi Gharibe9af9732021-03-31 15:08:01 +010017import NotFoundPage from "./pages/404.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040018import JamiAccountDialog from './pages/jamiAccountCreation.jsx'
Adrien Béraud34995902021-06-07 10:12:00 -040019import WelcomeAnimation from './components/welcome'
idillon-sfl837ea0b2022-08-25 11:35:29 -040020import defaultTheme from './themes/default'
idillon531b6f22022-09-16 14:02:00 -040021import ContactList from './components/ContactList';
22
23const theme = createTheme();
24const useStyles = makeStyles((theme) => {
25 root: {
26 // some CSS that access to theme
27 }
28})
Adrien Béraudab519ff2022-05-03 15:34:48 -040029
idillond858c182022-09-16 13:18:26 -040030// import { useSelector, useDispatch } from 'react-redux'
31// import { useAppSelector, useAppDispatch } from '../redux/hooks'
32
Adrien Béraudab519ff2022-05-03 15:34:48 -040033const Home = (props) => {
34 console.log(`home ${props}`)
Adrien Béraudab519ff2022-05-03 15:34:48 -040035
36 return <Navigate to="/account" />
37}
38
Adrien Béraude74741b2021-04-19 13:22:54 -040039const App = (props) => {
idillond858c182022-09-16 13:18:26 -040040 // const count = useSelector(state => state.counter.value)
41 // const dispatch = useDispatch();
42 // const count = useAppSelector((state) => state.counter.value);
43 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040044
idillond858c182022-09-16 13:18:26 -040045 const [state, setState] = useState({
46 loaded: false,
47 auth: authManager.getState(),
48 });
49 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010050
idillond858c182022-09-16 13:18:26 -040051 useEffect(() => {
52 authManager.init((auth) => {
53 setState({ loaded: false, auth });
54 });
55 return () => authManager.deinit();
56 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040057
idillond858c182022-09-16 13:18:26 -040058 console.log("App render");
59
60 if (displayWelcome) {
61 return (
62 <WelcomeAnimation
63 showSetup={!state.auth.setupComplete}
64 onComplete={() => setDisplayWelcome(false)}
65 />
66 );
67 } else if (!state.auth.setupComplete) {
68 return (
69 <Routes>
70 <Route path="/setup" element={<ServerSetup />} />
71 <Route path="/" element={<Navigate to="/setup" replace />} />
72 <Route index path="*" element={<Navigate to="/setup" replace />} />
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">
83 <Route index path="*" element={<JamiMessenger />} />
84 <Route path="settings" element={<AccountSettings />} />
85 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040086 </Route>
idillond858c182022-09-16 13:18:26 -040087 <Route path="/newAccount" element={<AccountCreationDialog />}>
88 <Route path="jami" element={<JamiAccountDialog />} />
89 </Route>
idillon531b6f22022-09-16 14:02:00 -040090 <Route path="/Contacts" element={<ContactList />} />
idillond858c182022-09-16 13:18:26 -040091 <Route path="/setup" element={<ServerSetup />} />
92 <Route path="/" index element={<Home />} />
93 <Route path="*" element={<NotFoundPage />} />
94 </Routes>
95 {!state.auth.authenticated && (
96 <SignInPage key="signin" open={!state.auth.authenticated} />
97 )}
Adrien Béraudab519ff2022-05-03 15:34:48 -040098 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040099 );
100};
Larbi Gharibe9af9732021-03-31 15:08:01 +0100101
Adrien Béraude74741b2021-04-19 13:22:54 -0400102export default App