-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add notification for favicon when change common status
- Loading branch information
Showing
8 changed files
with
316 additions
and
7 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import React from 'react'; | ||
|
||
const faviconHref = 'assets/images/Fav16.png'; | ||
const faviconDangerHref = 'assets/images/Fav16-danger.png'; | ||
const faviconWarningHref = 'assets/images/Fav16-warn.png'; | ||
|
||
export default class FaviconManager extends React.Component { | ||
static changeFavicon(faviconPath) { | ||
let link = document.querySelector("link[rel~='icon']"); | ||
if (!link) { | ||
link = document.createElement('link'); | ||
link.rel = 'icon'; | ||
document.head.appendChild(link); | ||
} | ||
link.href = faviconPath; | ||
} | ||
|
||
constructor(props) { | ||
super(props); | ||
this.state = { | ||
odd: false, | ||
intervalID: 0, | ||
}; | ||
} | ||
|
||
componentDidMount() { | ||
const intervalID = setInterval(() => { | ||
const { odd } = this.state; | ||
this.setState({ odd: !odd }); | ||
}, 2000); | ||
this.setState({ intervalID }); | ||
} | ||
|
||
componentWillUnmount() { | ||
const { intervalID } = this.state; | ||
clearInterval(intervalID); | ||
} | ||
|
||
getStatuses() { | ||
const { statuses } = this.props; | ||
|
||
if (statuses) { | ||
const values = Object.values(statuses); | ||
let item = values.some(({ status }) => status === 'danger'); | ||
if (item) { | ||
return 'danger'; | ||
} | ||
|
||
item = values.some(({ status }) => status === 'warning'); | ||
if (item) { | ||
return 'warning'; | ||
} | ||
|
||
return 'ok'; | ||
} | ||
} | ||
|
||
render() { | ||
const { odd } = this.state; | ||
const status = this.getStatuses(); | ||
|
||
if (!odd) { | ||
if (status === 'ok') { | ||
FaviconManager.changeFavicon(faviconHref); | ||
} | ||
|
||
if (status === 'danger') { | ||
FaviconManager.changeFavicon(faviconDangerHref); | ||
} | ||
|
||
if (status === 'warning') { | ||
FaviconManager.changeFavicon(faviconWarningHref); | ||
} | ||
} else { | ||
FaviconManager.changeFavicon(faviconHref); | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.