mirror of
https://github.com/fankes/beszel.git
synced 2025-10-20 02:09:28 +08:00
improve useeffects for favicon and system subscription
This commit is contained in:
@@ -155,7 +155,7 @@ export default function SystemDetail({ name }: { name: string }) {
|
|||||||
return () => {
|
return () => {
|
||||||
pb.collection('systems').unsubscribe(system.id)
|
pb.collection('systems').unsubscribe(system.id)
|
||||||
}
|
}
|
||||||
}, [system])
|
}, [system.id])
|
||||||
|
|
||||||
const chartData: ChartData = useMemo(() => {
|
const chartData: ChartData = useMemo(() => {
|
||||||
const lastCreated = Math.max(
|
const lastCreated = Math.max(
|
||||||
|
@@ -9,7 +9,6 @@ import { timeDay, timeHour } from 'd3-time'
|
|||||||
import { useEffect, useState } from 'react'
|
import { useEffect, useState } from 'react'
|
||||||
import { CpuIcon, HardDriveIcon, MemoryStickIcon, ServerIcon } from 'lucide-react'
|
import { CpuIcon, HardDriveIcon, MemoryStickIcon, ServerIcon } from 'lucide-react'
|
||||||
import { EthernetIcon, ThermometerIcon } from '@/components/ui/icons'
|
import { EthernetIcon, ThermometerIcon } from '@/components/ui/icons'
|
||||||
import { newQueue, Queue } from '@henrygd/queue'
|
|
||||||
|
|
||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs))
|
||||||
@@ -103,8 +102,9 @@ export const formatDay = (timestamp: string) => {
|
|||||||
return dayFormatter.format(new Date(timestamp))
|
return dayFormatter.format(new Date(timestamp))
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateFavicon = (newIcon: string) =>
|
export const updateFavicon = (newIcon: string) => {
|
||||||
((document.querySelector("link[rel='icon']") as HTMLLinkElement).href = `/static/${newIcon}`)
|
;(document.querySelector("link[rel='icon']") as HTMLLinkElement).href = `/static/${newIcon}`
|
||||||
|
}
|
||||||
|
|
||||||
export const isAdmin = () => pb.authStore.model?.role === 'admin'
|
export const isAdmin = () => pb.authStore.model?.role === 'admin'
|
||||||
export const isReadOnlyUser = () => pb.authStore.model?.role === 'readonly'
|
export const isReadOnlyUser = () => pb.authStore.model?.role === 'readonly'
|
||||||
|
@@ -73,29 +73,27 @@ const App = () => {
|
|||||||
updateUserSettings()
|
updateUserSettings()
|
||||||
// get alerts after system list is loaded
|
// get alerts after system list is loaded
|
||||||
updateSystemList().then(updateAlerts)
|
updateSystemList().then(updateAlerts)
|
||||||
|
|
||||||
|
return () => updateFavicon('favicon.svg')
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
// update favicon
|
// update favicon
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!authenticated || !systems.length) {
|
if (!systems.length || !authenticated) {
|
||||||
updateFavicon('favicon.svg')
|
updateFavicon('favicon.svg')
|
||||||
} else {
|
} else {
|
||||||
let up = false
|
let up = false
|
||||||
for (const system of systems) {
|
for (const system of systems) {
|
||||||
if (system.status === 'down') {
|
if (system.status === 'down') {
|
||||||
updateFavicon('favicon-red.svg')
|
updateFavicon('favicon-red.svg')
|
||||||
return () => updateFavicon('favicon.svg')
|
return
|
||||||
} else if (system.status === 'up') {
|
} else if (system.status === 'up') {
|
||||||
up = true
|
up = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
updateFavicon(up ? 'favicon-green.svg' : 'favicon.svg')
|
updateFavicon(up ? 'favicon-green.svg' : 'favicon.svg')
|
||||||
return () => updateFavicon('favicon.svg')
|
|
||||||
}
|
}
|
||||||
return () => {
|
}, [systems])
|
||||||
updateFavicon('favicon.svg')
|
|
||||||
}
|
|
||||||
}, [authenticated, systems])
|
|
||||||
|
|
||||||
if (!page) {
|
if (!page) {
|
||||||
return <h1 className="text-3xl text-center my-14">404</h1>
|
return <h1 className="text-3xl text-center my-14">404</h1>
|
||||||
|
Reference in New Issue
Block a user