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

Function fetchAll

src/components/FieldDetailView.tsx:242–260  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

240 lng: coords.reduce((s, c) => s + c[0], 0) / coords.length,
241 };
242 }, [field]);
243
244 // Fetch weather + AQI + soil moisture
245 useEffect(() => {
246 const fetchAll = async () => {
247 setLoading(true);
248 const { lat, lng } = fieldCenter;
249 try {
250 const [weatherRes, aqiRes, soilMoistRes] = await Promise.all([
251 fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&current=temperature_2m,relative_humidity_2m,wind_speed_10m,weather_code`),
252 fetch(`https://air-quality-api.open-meteo.com/v1/air-quality?latitude=${lat}&longitude=${lng}&current=pm2_5,pm10,european_aqi,us_aqi`),
253 fetch(`https://api.open-meteo.com/v1/forecast?latitude=${lat}&longitude=${lng}&hourly=soil_moisture_0_to_7cm&forecast_days=1`),
254 ]);
255 const [wData, aqData, smData] = await Promise.all([weatherRes.json(), aqiRes.json(), soilMoistRes.json()]);
256 setWeather(wData.current || null);
257 if (aqData.current) setAqiData(aqData.current);
258 if (smData.hourly?.soil_moisture_0_to_7cm) {
259 const vals = smData.hourly.soil_moisture_0_to_7cm.filter((v: any) => v != null);
260 if (vals.length) setSoilMoisture(Math.round(vals[vals.length - 1] * 1000) / 10);
261 }
262 } catch { setWeather(null); }
263 finally { setLoading(false); }

Callers 1

FieldDetailViewFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected