Min/Max-Werte unter Graf
Aktuelle Werte oben mit dran
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user