Display the current status in the sidebar (used to be static)

Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
Mcat12
2018-06-02 12:54:12 -04:00
parent a4b7365b4f
commit 98bdb6ef8d
3 changed files with 39 additions and 1 deletions
+2 -1
View File
@@ -14,6 +14,7 @@ import { Nav, NavItem } from 'reactstrap';
import logo from '../img/logo.svg';
import { mobileSidebarHide } from "./Header";
import { api } from "../utils";
import StatusBadge from "./StatusBadge";
const nav = {
items: [
@@ -126,7 +127,7 @@ export default props => {
</p>
<br/>
<span style={{textTransform: "initial", paddingLeft: "15px"}}>
<i className="fa fa-circle text-success"/> Online
<StatusBadge/>
</span>
</li>
{navList(nav.items, props)}
+34
View File
@@ -0,0 +1,34 @@
import React, { Component } from 'react';
import { api, makeCancelable, ignoreCancel } from '../utils';
export default class StatusBadge extends Component {
state = {
status: "enabled"
};
updateStatus = () => {
this.updateHandler = makeCancelable(api.getStatus(), { repeat: this.updateStatus, interval: 5000 });
this.updateHandler.promise
.then(res => {
this.setState({ status: res.status });
})
.catch(ignoreCancel)
.catch(() => {
this.setState({ status: "unknown" });
});
};
componentDidMount() {
this.updateStatus();
}
render() {
return (
this.state.status === "enabled"
?
<span><i className="fa fa-circle text-success"/> Online</span>
:
<span><i className="fa fa-circle text-danger"/> Offline</span>
);
}
}
+3
View File
@@ -117,6 +117,9 @@ export const api = {
removeWildlist(domain) {
return api.delete("dns/wildlist/" + domain);
},
getStatus() {
return api.get("dns/status")
},
get(url) {
return fetch(api.urlFor(url), {
credentials: this.credentialType()