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 | */ |
| 6 | |
| 7 | import React from 'react'; |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 8 | import CssBaseline from '@material-ui/core/CssBaseline'; |
| 9 | import authManager from './AuthManager' |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 10 | //import logo from './logo.svg'; |
Adrien Béraud | fe56ba3 | 2021-04-08 00:32:11 -0400 | [diff] [blame] | 11 | import './App.scss'; |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 12 | |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 13 | import { BrowserRouter as Router, Route, Switch, Link, Redirect } from 'react-router-dom'; |
| 14 | |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 15 | import SignInPage from "./pages/loginDialog.jsx" |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 16 | import JamiMessenger from "./pages/messenger.jsx" |
| 17 | import AccountSettings from "./pages/accountSettings.jsx" |
| 18 | import AccountSelection from "./pages/accountSelection.jsx" |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 19 | import AddContactPage from "./pages/addContactPage.jsx" |
| 20 | |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 21 | import NotFoundPage from "./pages/404.jsx" |
| 22 | |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 23 | class App extends React.Component { |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 24 | constructor(props) { |
| 25 | super(props); |
| 26 | this.state = { |
| 27 | authenticated: authManager.isAuthenticated(), |
| 28 | }; |
| 29 | authManager.setOnAuthChanged(authenticated => this.setState({authenticated})) |
| 30 | } |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 31 | |
| 32 | render() { |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 33 | console.log("App render") |
| 34 | console.log(this.props) |
| 35 | |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 36 | return <React.Fragment> |
| 37 | <CssBaseline /> |
| 38 | <Router> |
| 39 | <Switch> |
| 40 | <Route exact path="/"><Redirect to="/account" /></Route> |
Adrien Béraud | 995e802 | 2021-04-08 13:46:51 -0400 | [diff] [blame] | 41 | <Route path="/account/:accountId/settings" component={AccountSettings} /> |
Adrien Béraud | 35e7d7c | 2021-04-13 03:28:39 -0400 | [diff] [blame] | 42 | <Route path="/account/:accountId/addContact/:contactId" component={JamiMessenger} /> |
| 43 | <Route path="/account/:accountId/conversation/:conversationId" component={JamiMessenger} /> |
| 44 | <Route path="/account/:accountId" component={JamiMessenger} /> |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 45 | <Route path="/account" component={AccountSelection} /> |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 46 | <Route component={NotFoundPage} /> |
| 47 | </Switch> |
| 48 | </Router> |
| 49 | {!this.state.authenticated && <SignInPage open={!this.state.authenticated}/>} |
| 50 | </React.Fragment> |
Larbi Gharib | e9af973 | 2021-03-31 15:08:01 +0100 | [diff] [blame] | 51 | } |
| 52 | } |
| 53 | |
Adrien Béraud | 6ecaa40 | 2021-04-06 17:37:25 -0400 | [diff] [blame] | 54 | export default App |