This commit is contained in:
Dusan Vojacek
2026-03-20 14:30:03 +01:00
parent 2cc5ccfda7
commit 897b95f728
48 changed files with 4034 additions and 842 deletions

View File

@@ -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 }
}