()
| 149 | const cached = cache[fieldId]; |
| 150 | if (cached && Date.now() - cached.timestamp < 3600000) { setData(cached.data); return; } |
| 151 | const fetchGrowthStage = async () => { |
| 152 | setLoading(true); |
| 153 | try { |
| 154 | const result = await invokeWithRetry<any>( |
| 155 | "ndvi-timeseries", |
| 156 | { polygon }, |
| 157 | { retries: 3, isEmpty: (d: any) => !d?.growth_stage } |
| 158 | ); |
| 159 | const gs = result?.growth_stage ? { |
| 160 | stage: result.growth_stage, progress: result.growth_progress, |
| 161 | current_ndvi: result.latest_ndvi, date_range: result.date_range, |
| 162 | } : null; |
| 163 | setData(gs); |
| 164 | if (gs) setCache(GROWTH_STAGE_CACHE_KEY, fieldId, gs); |
| 165 | } catch (e) { console.error("Growth stage error:", e); setData(null); } |
| 166 | finally { setLoading(false); } |
| 167 | }; |
| 168 | fetchGrowthStage(); |
| 169 | }, [fieldId]); |
| 170 |
no test coverage detected