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 | 5d17455 | 2022-08-23 14:34:24 -0400 | [diff] [blame] | 6 | import { ThemeProvider, createTheme } 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' |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 10 | import './App.scss' |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 11 | |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 12 | import SignInPage from "./pages/loginDialog.jsx" |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 13 | import JamiMessenger from "./pages/JamiMessenger.jsx" |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 14 | import AccountSettings from "./pages/accountSettings.jsx" |
| 15 | import AccountSelection from "./pages/accountSelection.jsx" |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 16 | import ServerSetup from "./pages/serverSetup.jsx" |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 17 | import AccountCreationDialog from "./pages/accountCreation.jsx" |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 18 | import NotFoundPage from "./pages/404.jsx" |
Adrien Béraud | 88a5244 | 2021-04-26 12:11:41 -0400 | [diff] [blame] | 19 | import JamiAccountDialog from './pages/jamiAccountCreation.jsx' |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 20 | import WelcomeAnimation from './components/welcome' |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 21 | |
idillon-sfl | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 22 | const theme = createTheme({ |
| 23 | typography: { |
| 24 | fontFamily: "Ubuntu", |
idillon-sfl | 0c47188 | 2022-08-24 00:24:22 -0400 | [diff] [blame^] | 25 | h1: { |
| 26 | fontWeight: 400, |
| 27 | fontSize: "26px", |
| 28 | lineHeight: "36px", |
| 29 | }, |
| 30 | h2: { |
| 31 | fontWeight: 400, |
| 32 | fontSize: "22px", |
| 33 | lineHeight: "30px", |
| 34 | }, |
| 35 | h3: { |
| 36 | fontWeight: 400, |
| 37 | fontSize: "18px", |
| 38 | lineHeight: "26px", |
| 39 | }, |
| 40 | h4: { |
| 41 | fontWeight: 500, |
| 42 | fontSize: "15px", |
| 43 | lineHeight: "22px", |
| 44 | }, |
| 45 | h5: { |
| 46 | fontWeight: 500, |
| 47 | fontSize: "13px", |
| 48 | lineHeight: "19px", |
| 49 | }, |
| 50 | body1: { |
| 51 | fontWeight: 400, |
| 52 | fontSize: "15px", |
| 53 | lineHeight: "22px" |
| 54 | }, |
| 55 | body2: { |
| 56 | fontWeight: 400, |
| 57 | fontSize: "13px", |
| 58 | lineHeight: "19px", |
| 59 | }, |
| 60 | caption: { |
| 61 | fontWeight: 400, |
| 62 | fontSize: "12px", |
| 63 | lineHeight: "16px", |
| 64 | }, |
idillon-sfl | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 65 | }, |
| 66 | components: { |
| 67 | MuiCssBaseline: { |
| 68 | styleOverrides: ` |
| 69 | @font-face { |
| 70 | font-family: "Ubuntu"; |
| 71 | src: url("./fonts/Ubuntu-Th.ttf"); |
| 72 | font-weight: 100; |
| 73 | font-style: normal; |
| 74 | } |
| 75 | @font-face { |
| 76 | font-family: "Ubuntu"; |
| 77 | src: url("./fonts/Ubuntu-L.ttf"); |
| 78 | font-weight: 300; |
| 79 | font-style: normal; |
| 80 | } |
| 81 | @font-face { |
| 82 | font-family: "Ubuntu"; |
| 83 | src: url("./fonts/Ubuntu-LI.ttf"); |
| 84 | font-weight: 300; |
| 85 | font-style: italic; |
| 86 | } |
| 87 | @font-face { |
| 88 | font-family: "Ubuntu"; |
| 89 | src: url("./fonts/Ubuntu-R.ttf"); |
| 90 | font-weight: 400; |
| 91 | font-style: normal; |
| 92 | } |
| 93 | @font-face { |
| 94 | font-family: "Ubuntu"; |
| 95 | src: url("./fonts/Ubuntu-RI.ttf"); |
| 96 | font-weight: 400; |
| 97 | font-style: italic; |
| 98 | } |
| 99 | @font-face { |
| 100 | font-family: "Ubuntu"; |
| 101 | src: url("./fonts/Ubuntu-M.ttf"); |
| 102 | font-weight: 500; |
| 103 | font-style: normal; |
| 104 | } |
| 105 | @font-face { |
| 106 | font-family: "Ubuntu"; |
| 107 | src: url("./fonts/Ubuntu-MI.ttf"); |
| 108 | font-weight: 500; |
| 109 | font-style: italic; |
| 110 | } |
| 111 | @font-face { |
| 112 | font-family: "Ubuntu"; |
| 113 | src: url("./fonts/Ubuntu-B.ttf"); |
| 114 | font-weight: 700; |
| 115 | font-style: normal; |
| 116 | } |
| 117 | @font-face { |
| 118 | font-family: "Ubuntu"; |
| 119 | src: url("./fonts/Ubuntu-BI.ttf"); |
| 120 | font-weight: 700; |
| 121 | font-style: italic; |
| 122 | } |
| 123 | `, |
| 124 | }, |
| 125 | }, |
| 126 | }); |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 127 | |
| 128 | const Home = (props) => { |
| 129 | console.log(`home ${props}`) |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 130 | |
| 131 | return <Navigate to="/account" /> |
| 132 | } |
| 133 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 134 | const App = (props) => { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 135 | const [state, setState] = useState({ |
| 136 | loaded: false, |
| 137 | auth: authManager.getState() |
| 138 | }) |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 139 | const [displayWelcome, setDisplayWelcome] = useState(true) |
| 140 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 141 | useEffect(() => { |
| 142 | authManager.init(auth => { |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 143 | setState({ loaded: false, auth }) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 144 | }) |
| 145 | return () => authManager.deinit() |
| 146 | }, []); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 147 | |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 148 | console.log("App render") |
| 149 | if (displayWelcome) { |
| 150 | return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} /> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 151 | } else if (!state.auth.setupComplete) { |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 152 | return <Routes> |
| 153 | <Route path="/setup" element={<ServerSetup />} /> |
| 154 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
| 155 | <Route index path="*" element={<Navigate to="/setup" replace />} /> |
| 156 | </Routes> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 157 | } |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 158 | |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 159 | return <ThemeProvider theme={theme}> |
| 160 | <Routes> |
| 161 | <Route path="/account"> |
| 162 | <Route index element={<AccountSelection />} /> |
| 163 | <Route path=":accountId"> |
| 164 | <Route index path="*" element={<JamiMessenger />} /> |
| 165 | <Route path="settings" element={<AccountSettings />} /> |
| 166 | </Route> |
| 167 | </Route> |
| 168 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 169 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 170 | </Route> |
| 171 | <Route path="/setup" element={<ServerSetup />} /> |
| 172 | <Route path="/" index element={<Home />} /> |
| 173 | <Route path="*" element={<NotFoundPage />} /> |
| 174 | </Routes> |
| 175 | {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated}/>} |
| 176 | </ThemeProvider> |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 177 | } |
| 178 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 179 | export default App |