From 98bdb6ef8db38fb713f5db691d8faff211492002 Mon Sep 17 00:00:00 2001
From: Mcat12
Date: Thu, 15 Mar 2018 13:39:19 -0700
Subject: [PATCH] Display the current status in the sidebar (used to be static)
Signed-off-by: Mcat12
---
src/components/Sidebar.js | 3 ++-
src/components/StatusBadge.js | 34 ++++++++++++++++++++++++++++++++++
src/utils.js | 3 +++
3 files changed, 39 insertions(+), 1 deletion(-)
create mode 100644 src/components/StatusBadge.js
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()