Skip to content

Commit 815d898

Browse files
committed
add notification for favicon when change common status
1 parent 3793b70 commit 815d898

File tree

8 files changed

+316
-7
lines changed

8 files changed

+316
-7
lines changed

img/Fav16-danger.png

352 Bytes
Loading

img/Fav16-warn.png

353 Bytes
Loading

img/Fav16.png

324 Bytes
Loading

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angie-console-light",
3-
"version": "1.3.0",
3+
"version": "1.4.0",
44
"description": "Angie Console Light",
55
"main": "index.js",
66
"scripts": {
@@ -76,6 +76,7 @@
7676
"jest-environment-jsdom": "^29.6.4",
7777
"jest-extended": "^4.0.1",
7878
"resize-observer-polyfill": "^1.5.1",
79-
"webpack-dev-server": "4.9.2"
79+
"webpack-dev-server": "4.9.2",
80+
"copy-webpack-plugin": "6.3.1"
8081
}
8182
}

src/App.jsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import Resolvers from './components/pages/resolvers.jsx';
2828
import Workers from './components/pages/workers.jsx';
2929
import Disclaimer from './components/demo/disclaimer.jsx';
3030
import ConfigFiles from './components/pages/configfiles/configfiles.jsx';
31+
import FaviconManager from './components/favicon-manager/index.js';
3132
import datastore, { STORE, startObserve, play, pause } from './datastore';
3233
import { apiUtils } from './api';
3334
import envUtils from './env';
@@ -123,12 +124,12 @@ export class App extends React.Component {
123124
let subContent = null;
124125

125126
if (error in Errors) {
126-
subContent = <p>{ Errors[error] }</p>;
127+
subContent = <p>{Errors[error]}</p>;
127128
}
128129

129130
content = (
130131
<div className={styles['error-block']}>
131-
{ subContent }
132+
{subContent}
132133
<p>
133134
For&nbsp;more information please refer to&nbsp;the&nbsp;following&nbsp;
134135
<a href="https://angie.software/en/">documentation.</a>
@@ -143,6 +144,7 @@ export class App extends React.Component {
143144

144145
return (
145146
<div className={styles.console}>
147+
<FaviconManager statuses={STORE.__STATUSES} />
146148

147149
{
148150
envUtils.isDemoEnv() ?
@@ -159,7 +161,7 @@ export class App extends React.Component {
159161
: null
160162
}
161163

162-
{ content }
164+
{content}
163165
</div>
164166
</div>
165167
);
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import React from 'react';
2+
3+
const faviconHref = 'assets/images/Fav16.png';
4+
const faviconDangerHref = 'assets/images/Fav16-danger.png';
5+
const faviconWarningHref = 'assets/images/Fav16-warn.png';
6+
7+
export default class FaviconManager extends React.Component {
8+
static changeFavicon(faviconPath) {
9+
let link = document.querySelector("link[rel~='icon']");
10+
if (!link) {
11+
link = document.createElement('link');
12+
link.rel = 'icon';
13+
document.head.appendChild(link);
14+
}
15+
link.href = faviconPath;
16+
}
17+
18+
constructor(props) {
19+
super(props);
20+
this.state = {
21+
odd: false,
22+
intervalID: 0,
23+
};
24+
}
25+
26+
componentDidMount() {
27+
const intervalID = setInterval(() => {
28+
const { odd } = this.state;
29+
this.setState({ odd: !odd });
30+
}, 2000);
31+
this.setState({ intervalID });
32+
}
33+
34+
componentWillUnmount() {
35+
const { intervalID } = this.state;
36+
clearInterval(intervalID);
37+
}
38+
39+
getStatuses() {
40+
const { statuses } = this.props;
41+
42+
if (statuses) {
43+
const values = Object.values(statuses);
44+
let item = values.some(({ status }) => status === 'danger');
45+
if (item) {
46+
return 'danger';
47+
}
48+
49+
item = values.some(({ status }) => status === 'warning');
50+
if (item) {
51+
return 'warning';
52+
}
53+
54+
return 'ok';
55+
}
56+
}
57+
58+
render() {
59+
const { odd } = this.state;
60+
const status = this.getStatuses();
61+
62+
if (!odd) {
63+
if (status === 'ok') {
64+
FaviconManager.changeFavicon(faviconHref);
65+
}
66+
67+
if (status === 'danger') {
68+
FaviconManager.changeFavicon(faviconDangerHref);
69+
}
70+
71+
if (status === 'warning') {
72+
FaviconManager.changeFavicon(faviconWarningHref);
73+
}
74+
} else {
75+
FaviconManager.changeFavicon(faviconHref);
76+
}
77+
78+
return null;
79+
}
80+
}

webpack.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
1212
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1313
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default;
1414
const ESLintPlugin = require('eslint-webpack-plugin');
15+
const CopyWebpackPlugin = require('copy-webpack-plugin');
1516

1617
const packageFile = require('./package.json');
1718

@@ -43,6 +44,12 @@ const plugins = [
4344
}),
4445

4546
new ESLintPlugin(),
47+
48+
new CopyWebpackPlugin({
49+
patterns: [
50+
{ from: './img', to: 'images' }
51+
]
52+
}),
4653
];
4754

4855
if (PRODUCTION_BUILD) {

0 commit comments

Comments
 (0)