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

Function fetchAqi

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

Source from the content-addressed store, hash-verified

286 useEffect(() => {
287 if (!effectiveField) { setAqiData(null); return; }
288 const fetchAqi = async () => {
289 setAqiLoading(true);
290 try {
291 const { lat, lng } = getFieldCenter(effectiveField);
292 const res = await fetch(`https://air-quality-api.open-meteo.com/v1/air-quality?latitude=${lat}&longitude=${lng}&current=pm2_5,pm10,european_aqi,us_aqi`);
293 const data = await res.json();
294 if (data.current) {
295 setAqiData({
296 pm2_5: data.current.pm2_5,
297 pm10: data.current.pm10,
298 european_aqi: data.current.european_aqi,
299 us_aqi: data.current.us_aqi,
300 });
301 }
302 } catch { setAqiData(null); }
303 finally { setAqiLoading(false); }
304 };
305 fetchAqi();
306 }, [effectiveField]);
307

Callers 1

WeatherViewFunction · 0.85

Calls 1

getFieldCenterFunction · 0.70

Tested by

no test coverage detected