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 | af52bf8 | 2022-08-23 23:06:37 -0400 | [diff] [blame] | 104 | MuiCssBaseline: { |
| 105 | styleOverrides: ` |
| 106 | @font-face { |
| 107 | font-family: "Ubuntu"; |
| 108 | src: url("./fonts/Ubuntu-Th.ttf"); |
| 109 | font-weight: 100; |
| 110 | font-style: normal; |
| 111 | } |
| 112 | @font-face { |
| 113 | font-family: "Ubuntu"; |
| 114 | src: url("./fonts/Ubuntu-L.ttf"); |
| 115 | font-weight: 300; |
| 116 | font-style: normal; |
| 117 | } |
| 118 | @font-face { |
| 119 | font-family: "Ubuntu"; |
| 120 | src: url("./fonts/Ubuntu-LI.ttf"); |
| 121 | font-weight: 300; |
| 122 | font-style: italic; |
| 123 | } |
| 124 | @font-face { |
| 125 | font-family: "Ubuntu"; |
| 126 | src: url("./fonts/Ubuntu-R.ttf"); |
| 127 | font-weight: 400; |
| 128 | font-style: normal; |
| 129 | } |
| 130 | @font-face { |
| 131 | font-family: "Ubuntu"; |
| 132 | src: url("./fonts/Ubuntu-RI.ttf"); |
| 133 | font-weight: 400; |
| 134 | font-style: italic; |
| 135 | } |
| 136 | @font-face { |
| 137 | font-family: "Ubuntu"; |
| 138 | src: url("./fonts/Ubuntu-M.ttf"); |
| 139 | font-weight: 500; |
| 140 | font-style: normal; |
| 141 | } |
| 142 | @font-face { |
| 143 | font-family: "Ubuntu"; |
| 144 | src: url("./fonts/Ubuntu-MI.ttf"); |
| 145 | font-weight: 500; |
| 146 | font-style: italic; |
| 147 | } |
| 148 | @font-face { |
| 149 | font-family: "Ubuntu"; |
| 150 | src: url("./fonts/Ubuntu-B.ttf"); |
| 151 | font-weight: 700; |
| 152 | font-style: normal; |
| 153 | } |
| 154 | @font-face { |
| 155 | font-family: "Ubuntu"; |
| 156 | src: url("./fonts/Ubuntu-BI.ttf"); |
| 157 | font-weight: 700; |
| 158 | font-style: italic; |
| 159 | } |
| 160 | `, |
| 161 | }, |
| 162 | }, |
| 163 | }); |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 164 | |
| 165 | const Home = (props) => { |
| 166 | console.log(`home ${props}`) |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 167 | |
| 168 | return <Navigate to="/account" /> |
| 169 | } |
| 170 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 171 | const App = (props) => { |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 172 | const [state, setState] = useState({ |
| 173 | loaded: false, |
| 174 | auth: authManager.getState() |
| 175 | }) |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 176 | const [displayWelcome, setDisplayWelcome] = useState(true) |
| 177 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 178 | useEffect(() => { |
| 179 | authManager.init(auth => { |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 180 | setState({ loaded: false, auth }) |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 181 | }) |
| 182 | return () => authManager.deinit() |
| 183 | }, []); |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 184 | |
Adrien Béraud | 3499590 | 2021-06-07 10:12:00 -0400 | [diff] [blame] | 185 | console.log("App render") |
| 186 | if (displayWelcome) { |
| 187 | return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} /> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 188 | } else if (!state.auth.setupComplete) { |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 189 | return <Routes> |
| 190 | <Route path="/setup" element={<ServerSetup />} /> |
| 191 | <Route path="/" element={<Navigate to="/setup" replace />} /> |
| 192 | <Route index path="*" element={<Navigate to="/setup" replace />} /> |
| 193 | </Routes> |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 194 | } |
Adrien Béraud | 6c93496 | 2021-06-07 10:13:26 -0400 | [diff] [blame] | 195 | |
Adrien Béraud | ab519ff | 2022-05-03 15:34:48 -0400 | [diff] [blame] | 196 | return <ThemeProvider theme={theme}> |
| 197 | <Routes> |
| 198 | <Route path="/account"> |
| 199 | <Route index element={<AccountSelection />} /> |
| 200 | <Route path=":accountId"> |
| 201 | <Route index path="*" element={<JamiMessenger />} /> |
| 202 | <Route path="settings" element={<AccountSettings />} /> |
| 203 | </Route> |
| 204 | </Route> |
| 205 | <Route path="/newAccount" element={<AccountCreationDialog />}> |
| 206 | <Route path="jami" element={<JamiAccountDialog />} /> |
| 207 | </Route> |
| 208 | <Route path="/setup" element={<ServerSetup />} /> |
| 209 | <Route path="/" index element={<Home />} /> |
| 210 | <Route path="*" element={<NotFoundPage />} /> |
| 211 | </Routes> |
| 212 | {!state.auth.authenticated && <SignInPage key="signin" open={!state.auth.authenticated}/>} |
| 213 | </ThemeProvider> |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 214 | } |
| 215 | |
Adrien Béraud | e74741b | 2021-04-19 13:22:54 -0400 | [diff] [blame] | 216 | export default App |