2 lines
2.8 KiB
JavaScript
2 lines
2.8 KiB
JavaScript
import{r as h,j as e,O as f,p as S,w}from"./index-9FS9bw8D.js";const L=()=>{const[j,v]=h.useState([]),[s,p]=h.useState({}),[N,x]=h.useState(!0),[u,g]=h.useState(null);return h.useEffect(()=>{(async()=>{var d,l;try{x(!0);const r=((l=(d=(await S.getAll()).data)==null?void 0:d.data)==null?void 0:l.properties)||[];v(r);const i=r.filter(a=>a.latitude&&a.longitude).map(a=>a.id),y=await Promise.allSettled(i.map(a=>w.getCurrent(a))),o={};y.forEach((a,m)=>{const n=i[m];a.status==="fulfilled"&&(o[n]={weather:a.value.data.data.weather})}),(await Promise.allSettled(i.map(a=>w.getForecast(a)))).forEach((a,m)=>{const n=i[m];a.status==="fulfilled"&&(o[n]=o[n]||{},o[n].forecast=a.value.data.data.forecast)}),p(o),g(null)}catch(c){console.error("Failed to load weather:",c),g("Failed to load weather")}finally{x(!1)}})()},[]),e.jsxs("div",{className:"p-6",children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900 mb-6",children:"Weather"}),N?e.jsx("div",{className:"card",children:"Loading…"}):u?e.jsx("div",{className:"card text-red-700",children:u}):e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 xl:grid-cols-3 gap-4",children:j.map(t=>{var d,l,c;return e.jsxs("div",{className:"bg-white rounded-lg shadow p-4",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsx("div",{className:"font-semibold",children:t.name}),e.jsx("div",{className:"text-xs text-gray-500",children:t.address})]}),!t.latitude||!t.longitude?e.jsx("div",{className:"text-sm text-gray-600",children:"No coordinates set"}):(d=s[t.id])!=null&&d.weather?e.jsxs("div",{className:"flex items-center",children:[e.jsx("img",{alt:"",width:"50",height:"50",src:`${f.apiBaseUrl}/weather/icon/${s[t.id].weather.current.icon}?size=2x`}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("div",{className:"text-xl font-bold",children:[s[t.id].weather.current.temperature,"°F"]}),e.jsx("div",{className:"text-sm text-gray-700",children:s[t.id].weather.current.conditions}),e.jsxs("div",{className:"text-xs text-gray-500 mt-1",children:["Humidity ",s[t.id].weather.current.humidity,"% • Wind ",Math.round(s[t.id].weather.current.windSpeed)," mph"]})]})]}):e.jsx("div",{className:"text-sm text-gray-600",children:"Loading weather…"}),((c=(l=s[t.id])==null?void 0:l.forecast)==null?void 0:c.daily)&&e.jsx("div",{className:"mt-3 grid grid-cols-5 gap-2 text-center",children:s[t.id].forecast.daily.map((r,i)=>e.jsxs("div",{className:"text-xs text-gray-700",children:[e.jsx("div",{className:"font-medium",children:new Date(r.date).toLocaleDateString(void 0,{weekday:"short"})}),e.jsx("img",{alt:"",className:"mx-auto",width:"40",height:"40",src:`${f.apiBaseUrl}/weather/icon/${r.icon}?size=2x`}),e.jsxs("div",{children:[r.temperatureHigh,"° / ",r.temperatureLow,"°"]})]},i))})]},t.id)})})]})};export{L as default};
|