MCPcopy Create free account
hub / github.com/Thanas-R/Virdis / fetchLive

Function fetchLive

src/components/WeatherView.tsx:271–281  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

269 useEffect(() => {
270 if (!effectiveField) return;
271 const fetchLive = async () => {
272 setLiveLoading(true);
273 try {
274 const { lat, lng } = getFieldCenter(effectiveField);
275 const res = await fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,relative_humidity_2m,wind_speed_10m,apparent_temperature,weather_code&timezone=auto`);
276 const data = await res.json();
277 const c = data.current;
278 setLiveWeather({ temperature: Math.round(c.temperature_2m), humidity: c.relative_humidity_2m, windSpeed: Math.round(c.wind_speed_10m), weatherCode: c.weather_code, feelsLike: Math.round(c.apparent_temperature) });
279 } catch {setLiveWeather(null);} finally
280 {setLiveLoading(false);}
281 };
282 fetchLive();
283 }, [effectiveField]);
284

Callers 1

WeatherViewFunction · 0.85

Calls 1

getFieldCenterFunction · 0.70

Tested by

no test coverage detected