blob: 573c190774030ed2ce8f494b76bffad603ad9a89 [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-sfl5d174552022-08-23 14:34:24 -04006import { ThemeProvider, createTheme } 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'
Adrien Béraude74741b2021-04-19 13:22:54 -040010import './App.scss'
Larbi Gharibe9af9732021-03-31 15:08:01 +010011
Adrien Béraud35e7d7c2021-04-13 03:28:39 -040012import SignInPage from "./pages/loginDialog.jsx"
Adrien Béraud6c934962021-06-07 10:13:26 -040013import JamiMessenger from "./pages/JamiMessenger.jsx"
Adrien Béraud6ecaa402021-04-06 17:37:25 -040014import AccountSettings from "./pages/accountSettings.jsx"
15import AccountSelection from "./pages/accountSelection.jsx"
Adrien Béraude74741b2021-04-19 13:22:54 -040016import ServerSetup from "./pages/serverSetup.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040017import AccountCreationDialog from "./pages/accountCreation.jsx"
Larbi Gharibe9af9732021-03-31 15:08:01 +010018import NotFoundPage from "./pages/404.jsx"
Adrien Béraud88a52442021-04-26 12:11:41 -040019import JamiAccountDialog from './pages/jamiAccountCreation.jsx'
Adrien Béraud34995902021-06-07 10:12:00 -040020import WelcomeAnimation from './components/welcome'
Larbi Gharibe9af9732021-03-31 15:08:01 +010021
idillon-sflaf52bf82022-08-23 23:06:37 -040022const theme = createTheme({
idillon-sfla1012092022-08-24 01:34:05 -040023
idillon-sflaf52bf82022-08-23 23:06:37 -040024 typography: {
25 fontFamily: "Ubuntu",
idillon-sfl0c471882022-08-24 00:24:22 -040026 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-sflaf52bf82022-08-23 23:06:37 -040066 },
67 components: {
idillon-sfla1012092022-08-24 01:34:05 -040068 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-sfl0e3ef4e2022-08-25 03:59:37 -0400104 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-sflaf52bf82022-08-23 23:06:37 -0400147 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éraudab519ff2022-05-03 15:34:48 -0400207
208const Home = (props) => {
209 console.log(`home ${props}`)
Adrien Béraudab519ff2022-05-03 15:34:48 -0400210
211 return <Navigate to="/account" />
212}
213
Adrien Béraude74741b2021-04-19 13:22:54 -0400214const App = (props) => {
Adrien Béraude74741b2021-04-19 13:22:54 -0400215 const [state, setState] = useState({
216 loaded: false,
217 auth: authManager.getState()
218 })
Adrien Béraud34995902021-06-07 10:12:00 -0400219 const [displayWelcome, setDisplayWelcome] = useState(true)
220
Adrien Béraude74741b2021-04-19 13:22:54 -0400221 useEffect(() => {
222 authManager.init(auth => {
Adrien Béraud6c934962021-06-07 10:13:26 -0400223 setState({ loaded: false, auth })
Adrien Béraude74741b2021-04-19 13:22:54 -0400224 })
225 return () => authManager.deinit()
226 }, []);
Larbi Gharibe9af9732021-03-31 15:08:01 +0100227
Adrien Béraud34995902021-06-07 10:12:00 -0400228 console.log("App render")
229 if (displayWelcome) {
230 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />
Adrien Béraude74741b2021-04-19 13:22:54 -0400231 } else if (!state.auth.setupComplete) {
Adrien Béraudab519ff2022-05-03 15:34:48 -0400232 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éraude74741b2021-04-19 13:22:54 -0400237 }
Adrien Béraud6c934962021-06-07 10:13:26 -0400238
Adrien Béraudab519ff2022-05-03 15:34:48 -0400239 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 Gharibe9af9732021-03-31 15:08:01 +0100257}
258
Adrien Béraude74741b2021-04-19 13:22:54 -0400259export default App