diff --git a/src/components/Sidebar.js b/src/components/Sidebar.js index 974d8f1..7192f75 100644 --- a/src/components/Sidebar.js +++ b/src/components/Sidebar.js @@ -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 => {


- Online + {navList(nav.items, props)} diff --git a/src/components/StatusBadge.js b/src/components/StatusBadge.js new file mode 100644 index 0000000..6507a9f --- /dev/null +++ b/src/components/StatusBadge.js @@ -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" + ? + Online + : + Offline + ); + } +} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index 7ef0219..1735aba 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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()