mirror of
https://github.com/prymitive/karma
synced 2026-05-21 04:33:07 +00:00
feat(ui): add favicon.js support
Alert count will be displayed in the favicon, backported feature from old UI
This commit is contained in:
5
ui/package-lock.json
generated
5
ui/package-lock.json
generated
@@ -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",
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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}
|
||||
|
||||
57
ui/src/Components/FaviconBadge/index.js
Normal file
57
ui/src/Components/FaviconBadge/index.js
Normal 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 };
|
||||
Reference in New Issue
Block a user