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({ |
idillon-sfl | a101209 | 2022-08-24 01:34:05 -0400 | [diff] [blame] | 23 | |
idillon-sfl | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 24 | typography: { |
| 25 | fontFamily: "Ubuntu", |
idillon-sfl | 0c47188 | 2022-08-24 00:24:22 -0400 | [diff] [blame] | 26 | h1: { |
| 27 | fontWeight: 400, |
| 28 | fontSize: "26px", |
| 29 | lineHeight: "36px", |
| 30 | }, |
| 31 | h2: { |
| 32 | fontWeight: 400, |
| 33 | fontSize: "22px", |
| 34 | lineHeight: "30px", |
| 35 | }, |
| 36 | h3: { |
| 37 | fontWeight: 400, |
| 38 | fontSize: "18px", |
| 39 | lineHeight: "26px", |
| 40 | }, |
| 41 | h4: { |
| 42 | fontWeight: 500, |
| 43 | fontSize: "15px", |
| 44 | lineHeight: "22px", |
| 45 | }, |
| 46 | h5: { |
| 47 | fontWeight: 500, |
| 48 | fontSize: "13px", |
| 49 | lineHeight: "19px", |
| 50 | }, |
| 51 | body1: { |
| 52 | fontWeight: 400, |
| 53 | fontSize: "15px", |
| 54 | lineHeight: "22px" |
| 55 | }, |
| 56 | body2: { |
| 57 | fontWeight: 400, |
| 58 | fontSize: "13px", |
| 59 | lineHeight: "19px", |
| 60 | }, |
| 61 | caption: { |
| 62 | fontWeight: 400, |
| 63 | fontSize: "12px", |
| 64 | lineHeight: "16px", |
| 65 | }, |
idillon-sfl | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 66 | }, |
| 67 | components: { |
idillon-sfl | a101209 | 2022-08-24 01:34:05 -0400 | [diff] [blame] | 68 | MuiButton: { |
| 69 | styleOverrides: { |
| 70 | root: { |
| 71 | height: "46px", |
| 72 | fontWeight: 700, |
| 73 | fontSize: "15px", |
| 74 | lineHeight: "17px", |
| 75 | textTransform: "none", |
| 76 | }, |
| 77 | sizeSmall: { |
| 78 | height: "36px", |
| 79 | }, |
| 80 | contained: { |
| 81 | background: "#005699", |
| 82 | "&:hover": { |
| 83 | background: "#0071C9", |
| 84 | }, |
| 85 | }, |
| 86 | outlined: { |
| 87 | background: "#FFF", |
| 88 | borderColor: "#0056995C", |
| 89 | color: "#005699", |
| 90 | "&:hover": { |
| 91 | background: "#0056991A", |
| 92 | borderColor: "#005699", |
| 93 | }, |
| 94 | }, |
| 95 | text: { |
| 96 | background: "#fff", |
| 97 | color: "#005699", |
| 98 | "&:hover": { |
| 99 | background: "#0056991A", |
| 100 | }, |
| 101 | }, |
| 102 | }, |
| 103 | }, |
idillon-sfl | 0e3ef4e | 2022-08-25 03:59:37 -0400 | [diff] [blame^] | 104 | MuiSwitch: { |
| 105 | defaultProps: { |
| 106 | disableRipple: true, |
| 107 | }, |
| 108 | styleOverrides: { |
| 109 | root: { |
| 110 | width: "60px", |
| 111 | height: "30px", |
| 112 | padding: 0, |
| 113 | }, |
| 114 | switchBase: { |
| 115 | padding: 0, |
| 116 | "&.Mui-checked": { |
| 117 | transform: `translateX(30px)`, |
| 118 | }, |
| 119 | }, |
| 120 | thumb: { |
| 121 | width: "28px", |
| 122 | height: "28px", |
| 123 | border: "1px solid #005699", |
| 124 | ".Mui-checked.Mui-checked &": { |
| 125 | width: "30px", |
| 126 | height: "30px", |
| 127 | border: "none", |
| 128 | } |
| 129 | }, |
| 130 | track: { |
| 131 | backgroundColor: "#0056991A", |
| 132 | borderRadius: "30px", |
| 133 | opacity: 1, |
| 134 | ".Mui-checked.Mui-checked + &": { |
| 135 | backgroundColor: "#0056991A", |
| 136 | opacity: 1, |
| 137 | } |
| 138 | }, |
| 139 | colorPrimary: { |
| 140 | color: "#fff", |
| 141 | "&.Mui-checked": { |
| 142 | color: "#005699", |
| 143 | }, |
| 144 | }, |
| 145 | }, |
| 146 | }, |
idillon-sfl | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 147 | MuiCssBaseline: { |
| 148 | styleOverrides: ` |
| 149 | @font-face { |
| 150 | font-family: "Ubuntu"; |
| 151 | src: url("./fonts/Ubuntu-Th.ttf"); |
| 152 | font-weight: 100; |
| 153 | font-style: normal; |
| 154 | } |
| 155 | @font-face { |
| 156 | font-family: "Ubuntu"; |
| 157 | src: url("./fonts/Ubuntu-L.ttf"); |
| 158 | font-weight: 300; |
| 159 | font-style: normal; |
| 160 | } |
| 161 | @font-face { |
| 162 | font-family: "Ubuntu"; |
| 163 | src: url("./fonts/Ubuntu-LI.ttf"); |
| 164 | font-weight: 300; |
| 165 | font-style: italic; |
| 166 | } |
| 167 | @font-face { |
| 168 | font-family: "Ubuntu"; |
| 169 | src: url("./fonts/Ubuntu-R.ttf"); |
| 170 | font-weight: 400; |
| 171 | font-style: normal; |
| 172 | } |
| 173 | @font-face { |
| 174 | font-family: "Ubuntu"; |
| 175 | src: url("./fonts/Ubuntu-RI.ttf"); |
| 176 | font-weight: 400; |
| 177 | font-style: italic; |
| 178 | } |
| 179 | @font-face { |
| 180 | font-family: "Ubuntu"; |
| 181 | src: url("./fonts/Ubuntu-M.ttf"); |
| 182 | font-weight: 500; |
| 183 | font-style: normal; |
| 184 | } |
| 185 | @font-face { |
| 186 | font-family: "Ubuntu"; |
| 187 | src: url("./fonts/Ubuntu-MI.ttf"); |
| 188 | font-weight: 500; |
| 189 | font-style: italic; |
| 190 | } |
| 191 | @font-face { |
| 192 | font-family: "Ubuntu"; |
| 193 | src: url("./fonts/Ubuntu-B.ttf"); |
| 194 | font-weight: 700; |
| 195 | font-style: normal; |
| 196 | } |
| 197 | @font-face { |
| 198 | font-family: "Ubuntu"; |
| 199 | src: url("./fonts/Ubuntu-BI.ttf"); |
| 200 | font-weight: 700; |
| 201 | font-style: italic; |
| 202 | } |
| 203 | `, |
| 204 | }, |
| 205 | }, |
| 206 | }); |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 207 | |
| 208 | const Home = (props) => { |
| 209 | console.log(`home ${props}`) |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 210 | |
| 211 | return <Navigate to="/account" /> |
| 212 | } |
| 213 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 214 | const App = (props) => { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 215 | const [state, setState] = useState({ |
| 216 | loaded: false, |
| 217 | auth: authManager.getState() |
| 218 | }) |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 219 | const [displayWelcome, setDisplayWelcome] = useState(true) |
| 220 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 221 | useEffect(() => { |
| 222 | authManager.init(auth => { |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 223 | setState({ loaded: false, auth }) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 224 | }) |
| 225 | return () => authManager.deinit() |
| 226 | }, []); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 227 | |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 228 | console.log("App render") |
| 229 | if (displayWelcome) { |
| 230 | return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} /> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 231 | } else if (!state.auth.setupComplete) { |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 232 | return <Routes> |
| 233 | <Route path="/setup" element={<ServerSetup />} /> |
| 234 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
| 235 | <Route index path="*" element={<Navigate to="/setup" replace />} /> |
| 236 | </Routes> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 237 | } |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 238 | |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 239 | return <ThemeProvider theme={theme}> |
| 240 | <Routes> |
| 241 | <Route path="/account"> |
| 242 | <Route index element={<AccountSelection />} /> |
| 243 | <Route path=":accountId"> |
| 244 | <Route index path="*" element={<JamiMessenger />} /> |
| 245 | <Route path="settings" element={<AccountSettings />} /> |
| 246 | </Route> |
| 247 | </Route> |
| 248 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 249 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 250 | </Route> |
| 251 | <Route path="/setup" element={<ServerSetup />} /> |
| 252 | <Route path="/" index element={<Home />} /> |
| 253 | <Route path="*" element={<NotFoundPage />} /> |
| 254 | </Routes> |
| 255 | {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated}/>} |
| 256 | </ThemeProvider> |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 257 | } |
| 258 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 259 | export default App |