x
This commit is contained in:
@@ -23,10 +23,12 @@ export type TelemetryChartPoint = {
|
||||
export function useTelemetryToday(siteId: number | null) {
|
||||
const [points, setPoints] = useState<TelemetryChartPoint[]>([])
|
||||
const [ready, setReady] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
|
||||
const load = useCallback(async () => {
|
||||
if (siteId == null) {
|
||||
setPoints([])
|
||||
setError(null)
|
||||
setReady(true)
|
||||
return
|
||||
}
|
||||
@@ -37,6 +39,7 @@ export function useTelemetryToday(siteId: number | null) {
|
||||
})
|
||||
if (!Array.isArray(rows) || rows.length === 0) {
|
||||
setPoints([])
|
||||
setError(null)
|
||||
return
|
||||
}
|
||||
const mapped: TelemetryChartPoint[] = rows.map((r) => {
|
||||
@@ -55,8 +58,10 @@ export function useTelemetryToday(siteId: number | null) {
|
||||
}
|
||||
})
|
||||
setPoints(mapped)
|
||||
setError(null)
|
||||
} catch {
|
||||
setPoints([])
|
||||
setError('Hodinová data auditu se nepodařila načíst')
|
||||
} finally {
|
||||
setReady(true)
|
||||
}
|
||||
@@ -68,5 +73,5 @@ export function useTelemetryToday(siteId: number | null) {
|
||||
return () => window.clearInterval(id)
|
||||
}, [load])
|
||||
|
||||
return { points, ready, hasChartData: points.length > 0 }
|
||||
return { points, ready, error, hasChartData: points.length > 0, reload: load }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user