Min/Max-Werte unter Graf

Aktuelle Werte oben mit dran
This commit is contained in:
rxf
2026-02-09 16:27:44 +01:00
parent c03ffe839d
commit db1e2fd737
3 changed files with 48 additions and 20 deletions

View File

@@ -9,14 +9,36 @@ function App() {
const [lastUpdate, setLastUpdate] = useState(null)
useEffect(() => {
// Prüfe ob eingebettete Daten vorhanden sind
if (window.__WEATHER_DATA__) {
setWeatherData(window.__WEATHER_DATA__)
setLastUpdate(new Date())
setLoading(false)
} else {
setError('Keine Wetterdaten verfügbar')
setLoading(false)
const fetchData = async () => {
try {
// Prüfe ob eingebettete Daten vorhanden sind (statischer Build)
if (window.__WEATHER_DATA__) {
setWeatherData(window.__WEATHER_DATA__)
setLastUpdate(new Date())
setLoading(false)
} else {
// Entwicklungsmodus: Daten von API holen
const response = await fetch('http://localhost:8000/weather/history?hours=24')
if (!response.ok) {
throw new Error('API-Fehler: ' + response.status)
}
const data = await response.json()
setWeatherData(data)
setLastUpdate(new Date())
setLoading(false)
}
} catch (err) {
setError(err.message)
setLoading(false)
}
}
fetchData()
// Automatisches Update alle 5 Minuten (nur im Entwicklungsmodus)
if (!window.__WEATHER_DATA__) {
const interval = setInterval(fetchData, 5 * 60 * 1000)
return () => clearInterval(interval)
}
}, [])