feat(ui): add favicon.js support

Alert count will be displayed in the favicon, backported feature from old UI
This commit is contained in:
Łukasz Mierzwa
2018-08-12 19:57:48 +01:00
parent 3153707d40
commit cb421737dd
4 changed files with 65 additions and 0 deletions

5
ui/package-lock.json generated
View File

@@ -4092,6 +4092,11 @@
"resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.1.tgz",
"integrity": "sha1-0eJkOzipTXWDtHkGDmxK/8lAcfg="
},
"favico.js": {
"version": "0.3.10",
"resolved": "https://registry.npmjs.org/favico.js/-/favico.js-0.3.10.tgz",
"integrity": "sha1-gFhuJ6EX8kqNUcGKmb3HFNQzkwE="
},
"faye-websocket": {
"version": "0.11.1",
"resolved": "https://registry.npmjs.org/faye-websocket/-/faye-websocket-0.11.1.tgz",

View File

@@ -13,6 +13,7 @@
"bootswatch": "4.1.3",
"copy-to-clipboard": "3.0.8",
"fast-deep-equal": "2.0.1",
"favico.js": "0.3.10",
"lodash.debounce": "4.0.8",
"lodash.throttle": "4.1.1",
"lodash.uniqueid": "4.0.1",

View File

@@ -9,6 +9,7 @@ import { SilenceFormStore } from "Stores/SilenceFormStore";
import { NavBar } from "Components/NavBar";
import { Grid } from "Components/Grid";
import { Fetcher } from "Components/Fetcher";
import { FaviconBadge } from "Components/FaviconBadge";
import "./App.css";
@@ -49,6 +50,7 @@ class App extends Component {
render() {
return (
<React.Fragment>
<FaviconBadge alertStore={this.alertStore} />
<NavBar
alertStore={this.alertStore}
settingsStore={this.settingsStore}

View File

@@ -0,0 +1,57 @@
import React, { Component } from "react";
import PropTypes from "prop-types";
import { observer } from "mobx-react";
import * as Favico from "favico.js";
const FaviconBadge = observer(
class FaviconBadge extends Component {
static propTypes = {
alertStore: PropTypes.object.isRequired
};
constructor(props) {
super(props);
this.favicon = new Favico({
animation: "none",
position: "up",
bgColor: "#000",
textColor: "#fff",
fontStyle: "lighter"
});
}
updateBadge = () => {
const { alertStore } = this.props;
if (alertStore.status.error !== null) {
this.favicon.badge("?");
} else {
this.favicon.badge(alertStore.info.totalAlerts);
}
};
componentDidMount() {
this.updateBadge();
}
componentDidUpdate() {
this.updateBadge();
}
render() {
const { alertStore } = this.props;
return (
<span
data-total-alerts={alertStore.info.totalAlerts}
data-status-error={alertStore.status.error}
/>
);
}
}
);
export { FaviconBadge };