blob: c05265e972f865d85e7cf1779939450b14ecf4fa [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';
ervinanoh8e918042022-09-06 10:30:59 -040022import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
Adrien Béraudab519ff2022-05-03 15:34:48 -040023
idillond858c182022-09-16 13:18:26 -040024// import { useSelector, useDispatch } from 'react-redux'
25// import { useAppSelector, useAppDispatch } from '../redux/hooks'
26
Adrien Béraudab519ff2022-05-03 15:34:48 -040027const Home = (props) => {
28 console.log(`home ${props}`)
Adrien Béraudab519ff2022-05-03 15:34:48 -040029
30 return <Navigate to="/account" />
31}
32
Adrien Béraude74741b2021-04-19 13:22:54 -040033const App = (props) => {
idillond858c182022-09-16 13:18:26 -040034 // 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éraud34995902021-06-07 10:12:00 -040038
idillond858c182022-09-16 13:18:26 -040039 const [state, setState] = useState({
40 loaded: false,
41 auth: authManager.getState(),
42 });
43 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010044
idillond858c182022-09-16 13:18:26 -040045 useEffect(() => {
46 authManager.init((auth) => {
47 setState({ loaded: false, auth });
48 });
49 return () => authManager.deinit();
50 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040051
idillond858c182022-09-16 13:18:26 -040052 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éraudab519ff2022-05-03 15:34:48 -040080 </Route>
idillond858c182022-09-16 13:18:26 -040081 <Route path="/newAccount" element={<AccountCreationDialog />}>
82 <Route path="jami" element={<JamiAccountDialog />} />
83 </Route>
ervinanoh34eb9472022-09-13 04:20:28 -040084 {/* <Route path="/Contacts" element={<ContactList />} /> */}
ervinanoh8e918042022-09-06 10:30:59 -040085 <Route path="/Theme" element={<ThemeDemonstrator />} />
idillond858c182022-09-16 13:18:26 -040086 <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éraudab519ff2022-05-03 15:34:48 -040093 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040094 );
95};
Larbi Gharibe9af9732021-03-31 15:08:01 +010096
Adrien Béraude74741b2021-04-19 13:22:54 -040097export default App