From 3ed57873b4f690449756965da6ec50f8b52d15b8 Mon Sep 17 00:00:00 2001 From: Morisse Date: Mon, 22 Oct 2018 18:47:05 +0200 Subject: [PATCH] add server bar --- src/StatsTab.js | 59 +++++++++++++++++++++++++++++++++++++++++++----- src/serverBar.js | 22 ++++++++++++++++++ 2 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/serverBar.js diff --git a/src/StatsTab.js b/src/StatsTab.js index 27a2dca..717ce5b 100644 --- a/src/StatsTab.js +++ b/src/StatsTab.js @@ -1,5 +1,7 @@ import React, { Component } from 'react'; import CardStats from './CardStats'; +import ServerBar from './serverBar'; + import { PageHeader, Panel} from 'react-bootstrap'; @@ -14,6 +16,7 @@ export default class StatsTab extends Component { componentDidMount = () => { this.getStats(); + this.getServerState(); } getStats = async () => { @@ -38,6 +41,29 @@ export default class StatsTab extends Component { }); } + getServerState = async () => { + let serverState; + const homeServer = this.props.server; + const accessToken = this.props.token; + + try { + const serverStateRequest = await fetch(homeServer+ '_matrix/client/r0/watcha_server_state', { + method: 'GET', + headers: { + 'Authorization': 'Bearer '+accessToken, + }, + }); + + serverState = JSON.parse(await serverStateRequest.text()); + } catch (e) { + console.log('error: ' + e); + return; + } + this.setState({ + serverState: serverState, + }); + } + render() { let membersData; @@ -45,6 +71,7 @@ export default class StatsTab extends Component { let bigRoomsData; let oneOnOneData; let activeRooms; + let serverState; const usersLines = []; const roomsLines = []; if (this.state.stats) { @@ -59,6 +86,14 @@ export default class StatsTab extends Component { {label: 'One on One', data: oneOnOneData}, {label: 'Inactive', data: bigRoomsData-activeRooms}); } + if (this.state.serverState) { + serverState = +
+ + + +
; + } return (
@@ -68,13 +103,25 @@ export default class StatsTab extends Component {
- - - Server State +
+ + + Server State + + + { serverState } + + - - Panel content - + + + Server Log + + + log + + +
); } diff --git a/src/serverBar.js b/src/serverBar.js new file mode 100644 index 0000000..8786466 --- /dev/null +++ b/src/serverBar.js @@ -0,0 +1,22 @@ +import React, { Component } from 'react'; +import { ProgressBar } from 'react-bootstrap'; + + +export default class ServerBar extends Component { + constructor(props) { + super(props); + + this.state = { + + }; + } + + render() { + return ( +
+
{ this.props.label }
+ +
+ ); + } +}