()
| 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}¤t=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 |
no test coverage detected