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
270 useEffect(() => {
271 if (!effectiveField) return;
272 const fetchLive = async () => {
273 setLiveLoading(true);
274 try {
275 const { lat, lng } = getFieldCenter(effectiveField);
276 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`);
277 const data = await res.json();
278 const c = data.current;
279 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) });
280 } catch {setLiveWeather(null);} finally
281 {setLiveLoading(false);}
282 };
283 fetchLive();
284 }, [effectiveField]);

Callers 1

WeatherViewFunction · 0.85

Calls 1

getFieldCenterFunction · 0.70

Tested by

no test coverage detected