blob: b0fd67a624c998fd597f8ce99ec1f15d4b6c089a [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';
simon07b4eb02022-09-29 17:50:26 -04007import { useEffect, useState } from 'react';
8import { Navigate, Route, Routes } from 'react-router-dom';
Larbi Gharibe9af9732021-03-31 15:08:01 +01009
simon07b4eb02022-09-29 17:50:26 -040010import authManager from './AuthManager';
simond47ef9e2022-09-28 22:24:28 -040011import WelcomeAnimation from './components/welcome';
simonfe1de722022-10-02 00:21:43 -040012import NotFoundPage from './pages/404';
13import AccountCreationDialog from './pages/AccountCreation';
14import AccountSelection from './pages/AccountSelection';
15import AccountSettings from './pages/AccountSettings';
16import JamiAccountDialog from './pages/JamiAccountCreation';
17import JamiMessenger from './pages/JamiMessenger';
18import SignInPage from './pages/LoginDialog';
19import ServerSetup from './pages/ServerSetup';
simond47ef9e2022-09-28 22:24:28 -040020import defaultTheme from './themes/default';
ervinanoh8e918042022-09-06 10:30:59 -040021import { ThemeDemonstrator } from './themes/ThemeDemonstrator';
Adrien Béraudab519ff2022-05-03 15:34:48 -040022
idillond858c182022-09-16 13:18:26 -040023// import { useSelector, useDispatch } from 'react-redux'
24// import { useAppSelector, useAppDispatch } from '../redux/hooks'
25
simon218d3d12022-10-01 17:27:01 -040026const Home = () => {
simond47ef9e2022-09-28 22:24:28 -040027 return <Navigate to="/account" />;
28};
Adrien Béraudab519ff2022-05-03 15:34:48 -040029
simon80b7b3b2022-09-28 17:50:10 -040030const App = () => {
idillond858c182022-09-16 13:18:26 -040031 // const count = useSelector(state => state.counter.value)
32 // const dispatch = useDispatch();
33 // const count = useAppSelector((state) => state.counter.value);
34 // const dispatch = useAppDispatch();
Adrien Béraud34995902021-06-07 10:12:00 -040035
idillond858c182022-09-16 13:18:26 -040036 const [state, setState] = useState({
37 loaded: false,
38 auth: authManager.getState(),
39 });
40 const [displayWelcome, setDisplayWelcome] = useState(true);
Larbi Gharibe9af9732021-03-31 15:08:01 +010041
idillond858c182022-09-16 13:18:26 -040042 useEffect(() => {
43 authManager.init((auth) => {
44 setState({ loaded: false, auth });
45 });
46 return () => authManager.deinit();
47 }, []);
Adrien Béraud6c934962021-06-07 10:13:26 -040048
simond47ef9e2022-09-28 22:24:28 -040049 console.log('App render');
idillond858c182022-09-16 13:18:26 -040050
51 if (displayWelcome) {
simond47ef9e2022-09-28 22:24:28 -040052 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />;
idillond858c182022-09-16 13:18:26 -040053 } else if (!state.auth.setupComplete) {
54 return (
55 <Routes>
56 <Route path="/setup" element={<ServerSetup />} />
57 <Route path="/" element={<Navigate to="/setup" replace />} />
simon218d3d12022-10-01 17:27:01 -040058 <Route path="*" element={<Navigate to="/setup" replace />} />
idillond858c182022-09-16 13:18:26 -040059 </Routes>
60 );
61 }
62
63 return (
64 <ThemeProvider theme={defaultTheme}>
65 <Routes>
66 <Route path="/account">
67 <Route index element={<AccountSelection />} />
68 <Route path=":accountId">
idillon7f0b2882022-10-06 13:34:21 -040069 <Route index element={<JamiMessenger />} />
simon218d3d12022-10-01 17:27:01 -040070 <Route path="*" element={<JamiMessenger />} />
idillond858c182022-09-16 13:18:26 -040071 <Route path="settings" element={<AccountSettings />} />
72 </Route>
Adrien Béraudab519ff2022-05-03 15:34:48 -040073 </Route>
idillond858c182022-09-16 13:18:26 -040074 <Route path="/newAccount" element={<AccountCreationDialog />}>
75 <Route path="jami" element={<JamiAccountDialog />} />
76 </Route>
ervinanoh34eb9472022-09-13 04:20:28 -040077 {/* <Route path="/Contacts" element={<ContactList />} /> */}
ervinanoh8e918042022-09-06 10:30:59 -040078 <Route path="/Theme" element={<ThemeDemonstrator />} />
idillond858c182022-09-16 13:18:26 -040079 <Route path="/setup" element={<ServerSetup />} />
simon218d3d12022-10-01 17:27:01 -040080 <Route path="/" element={<Home />} />
idillond858c182022-09-16 13:18:26 -040081 <Route path="*" element={<NotFoundPage />} />
82 </Routes>
simond47ef9e2022-09-28 22:24:28 -040083 {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated} />}
Adrien Béraudab519ff2022-05-03 15:34:48 -040084 </ThemeProvider>
idillond858c182022-09-16 13:18:26 -040085 );
86};
Larbi Gharibe9af9732021-03-31 15:08:01 +010087
simond47ef9e2022-09-28 22:24:28 -040088export default App;