mirror of
https://github.com/gosticks/web.git
synced 2026-12-03 17:51:39 +00:00
Display the current status in the sidebar (used to be static)
Signed-off-by: Mcat12 <newtoncat12@yahoo.com>
This commit is contained in:
@@ -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)}
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user