blob: 373a4385f56af3e1d2a2360a4dd87adee0592d85 [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-sflaf52bf82022-08-23 23:06:37 -0400104 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éraudab519ff2022-05-03 15:34:48 -0400164
165const Home = (props) => {
166 console.log(`home ${props}`)
Adrien Béraudab519ff2022-05-03 15:34:48 -0400167
168 return <Navigate to="/account" />
169}
170
Adrien Béraude74741b2021-04-19 13:22:54 -0400171const App = (props) => {
Adrien Béraude74741b2021-04-19 13:22:54 -0400172 const [state, setState] = useState({
173 loaded: false,
174 auth: authManager.getState()
175 })
Adrien Béraud34995902021-06-07 10:12:00 -0400176 const [displayWelcome, setDisplayWelcome] = useState(true)
177
Adrien Béraude74741b2021-04-19 13:22:54 -0400178 useEffect(() => {
179 authManager.init(auth => {
Adrien Béraud6c934962021-06-07 10:13:26 -0400180 setState({ loaded: false, auth })
Adrien Béraude74741b2021-04-19 13:22:54 -0400181 })
182 return () => authManager.deinit()
183 }, []);
Larbi Gharibe9af9732021-03-31 15:08:01 +0100184
Adrien Béraud34995902021-06-07 10:12:00 -0400185 console.log("App render")
186 if (displayWelcome) {
187 return <WelcomeAnimation showSetup={!state.auth.setupComplete} onComplete={() => setDisplayWelcome(false)} />
Adrien Béraude74741b2021-04-19 13:22:54 -0400188 } else if (!state.auth.setupComplete) {
Adrien Béraudab519ff2022-05-03 15:34:48 -0400189 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éraude74741b2021-04-19 13:22:54 -0400194 }
Adrien Béraud6c934962021-06-07 10:13:26 -0400195
Adrien Béraudab519ff2022-05-03 15:34:48 -0400196 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 Gharibe9af9732021-03-31 15:08:01 +0100214}
215
Adrien Béraude74741b2021-04-19 13:22:54 -0400216export default App