Adrien BĂ©raud | 4e287b9 | 2021-04-24 16:15:56 -0400 | [diff] [blame] | 1 | import React from 'react'; |
| 2 | import Header from '../components/Header' |
| 3 | import AccountPreferences from '../components/AccountPreferences' |
| 4 | import Container from '@material-ui/core/Container'; |
| 5 | import CircularProgress from '@material-ui/core/CircularProgress'; |
| 6 | import authManager from '../AuthManager' |
| 7 | import Account from '../../../model/Account' |
| 8 | |
| 9 | const ServerOverview = (props) => { |
| 10 | |
| 11 | this.accountId = props.accountId || props.match.params.accountId |
| 12 | this.state = { loaded: false, account: props.account } |
| 13 | this.req = undefined |
| 14 | |
| 15 | componentDidMount() { |
| 16 | this.controller = new AbortController() |
| 17 | if (this.req === undefined) { |
| 18 | this.req = authManager.fetch(`/api/serverConfig`, {signal: this.controller.signal}) |
| 19 | .then(res => res.json()) |
| 20 | .then(result => { |
| 21 | console.log(result) |
| 22 | this.setState({loaded: true, account: Account.from(result)}) |
| 23 | }) |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | componentWillUnmount() { |
| 28 | this.controller.abort() |
| 29 | this.req = undefined |
| 30 | } |
| 31 | |
| 32 | return ( |
| 33 | <Container maxWidth="sm" className="app" > |
| 34 | <Header /> |
| 35 | {this.state.loaded ? <AccountPreferences account={this.state.account} /> : <CircularProgress />} |
| 36 | </Container> |
| 37 | ) |
| 38 | } |
| 39 | |
| 40 | export default ServerOverview; |