improve useeffects for favicon and system subscription

This commit is contained in:
Henry Dollman
2024-10-19 19:57:35 -04:00
parent b5c158d1b3
commit 6de5dce176
3 changed files with 9 additions and 11 deletions

View File

@@ -73,29 +73,27 @@ const App = () => {
updateUserSettings()
// get alerts after system list is loaded
updateSystemList().then(updateAlerts)
return () => updateFavicon('favicon.svg')
}, [])
// update favicon
useEffect(() => {
if (!authenticated || !systems.length) {
if (!systems.length || !authenticated) {
updateFavicon('favicon.svg')
} else {
let up = false
for (const system of systems) {
if (system.status === 'down') {
updateFavicon('favicon-red.svg')
return () => updateFavicon('favicon.svg')
return
} else if (system.status === 'up') {
up = true
}
}
updateFavicon(up ? 'favicon-green.svg' : 'favicon.svg')
return () => updateFavicon('favicon.svg')
}
return () => {
updateFavicon('favicon.svg')
}
}, [authenticated, systems])
}, [systems])
if (!page) {
return <h1 className="text-3xl text-center my-14">404</h1>