PageSourceSearch

https://askweather.ai/assets/RainToday-LxxqsiT6.js

js askweather.ai collected 2026-10-05 11:48:28 UTC 12,590 bytes, 1 lines download raw bytes

1import{u as ye,r as C,b as be,j as e,H as U,f as je,C as p,a as u,L as g,e as re,h as ae,i as se,g as W,N as Ne}from"./index-nJY5RPz9.js";import{c as we,f as ve}from"./fetchBundle-BhkDh08G.js";import{C as ke}from"./circle-alert-C3yX294J.js";import{U as Re}from"./umbrella-9Dtn-gDT.js";function $e(t){return t.split(" ").map(r=>r.charAt(0).toUpperCase()+r.slice(1)).join(" ")}function S(t){const[r]=t.split(":"),a=parseInt(r,10);return a===0?"12 AM":a===12?"12 PM":a<12?`${a} AM`:`${a-12} PM`}function Ce(t){if(t.length===0)return 1;const r=Math.max(...t.map(a=>a.precipprob||0));return r<=10?1:r<=20?2:r<=30?4:r<=50?5:r<=65?7:r<=80?8:10}function Se(t){return t<=2?"No umbrella needed":t<=4?"Probably not needed":t<=6?"Take one just in case":t<=8?"Definitely bring it":"Essential today"}function ne(t){return t<=2?"text-yellow-400":t<=4?"text-green-400":t<=6?"text-blue-300":t<=8?"text-blue-500":"text-indigo-400"}function Pe(t){return t>=70?"bg-blue-500":t>=40?"bg-blue-400":t>=20?"bg-blue-300":t>=5?"bg-blue-900":"bg-gray-700"}function He(t){const r=t.filter(h=>(h.precipprob||0)>=50);if(r.length===0)return null;const a=r.reduce((h,N)=>(h.precipprob||0)>(N.precipprob||0)?h:N);return S(a.datetime)}function Ae(t){const r=t.find(a=>(a.precipprob||0)>=50);return r?S(r.datetime):null}function De(){var B,Z,J;const[t,r]=ye("/:slug/rain-today"),[a,h]=C.useState({today:null,tomorrowHours:[],currentPrecip:0,currentConditions:"",timezone:"America/New_York",isRainingNow:null,isSnowingNow:null}),[N,D]=C.useState(!0),[ie,_]=C.useState(null),d=r!=null&&r.slug?decodeURIComponent(r.slug):"",w=d.split("-"),P=w.length>=2?w[w.length-1].toUpperCase():"",oe=w.slice(0,-1).join(" "),i=$e(oe),z=P?`${i}, ${P}`:i,H=be(d),A=H.city,le=new Date().getFullYear(),ce=a.timezone||"America/New_York",E=parseInt(new Date().toLocaleString("en-US",{timeZone:ce,hour:"numeric",hour12:!1}),10),f=`Will It Rain Today in ${i}? (Hourly Rain Forecast)`,y=`Live rain forecast for ${z}. ${le} precipitation probability, hourly rain outlook, and AI-powered answer for today's weather.`,F=`https://askweather.ai/${d}/rain-today`;if(C.useEffect(()=>{if(!t||!d)return;(async()=>{var c,R;try{D(!0);let o;const K=we(x=>{var ee,te;return!!((te=(ee=x==null?void 0:x.forecast)==null?void 0:ee.days)!=null&&te.length)&&!!(x!=null&&x.current)});K?o=K:o=await ve({slug:d,days:2});const V=o.data.timezone||"America/New_York",M=((c=o.data.forecast)==null?void 0:c.days)||[],ge=new Date().toLocaleDateString("en-CA",{timeZone:V}),G=M.findIndex(x=>x.datetime===ge),Q=G>=0?G:1,m=M[Q]||null,fe=((R=M[Q+1])==null?void 0:R.hours)||[],X=o.data.current||{},T=o.data.isRainingNow??null,L=o.data.isSnowingNow??null;let $;L===!0||T===!0?$=100:T===!1&&L!==!0?$=0:$=X.precipprob??(m==null?void 0:m.precipprob)??0,h({today:m,tomorrowHours:fe,currentPrecip:$,currentConditions:X.conditions||(m==null?void 0:m.conditions)||"",timezone:V,isRainingNow:T,isSnowingNow:L}),_(null)}catch(o){_(o instanceof Error?o.message:"Failed to load weather data")}finally{D(!1)}})();const n=`rain-today-pinged-${d}`;localStorage.getItem(n)||(localStorage.setItem(n,"1"),fetch("/api/sitemap/record-rain-today",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:d})}).catch(()=>{}))},[t,d]),!t)return null;const de=[...((B=a.today)==null?void 0:B.hours)||[],...a.tomorrowHours||[]],l=[];let O=!1;for(const s of de)parseInt(s.datetime.split(":")[0]||"0",10)===E&&(O=!0),O&&l.length<24&&l.push(s);l.length>0&&(l[0]={...l[0],precipprob:a.currentPrecip});const I=l.length>0?l.reduce((s,n)=>Math.max(s,n.precipprob||0),0):((Z=a.today)==null?void 0:Z.precipprob)??0,b=(((J=a.today)==null?void 0:J.hours)||[]).filter(s=>parseInt(s.datetime.split(":")[0]||"0",10)>=E).map((s,n)=>n===0?{...s,precipprob:a.currentPrecip}:s),Y=b.length>0?b.reduce((s,n)=>Math.max(s,n.precipprob||0),0):0,v=Ce(b),q=He(l);Ae(l);const xe=Y>=40,me=I>=40,k=b,he=b.some(s=>(s.precipprob||0)>=5),j=Math.round(Y),pe=Math.round(I),ue=xe?`There's a ${j}% chance of rain today in ${i}.${q?` Rain is heaviest around ${q}.`:""}`:j>10?`Rain today is possible in ${i} with a ${j}% chance, but unlikely to be significant.`:`No significant rain is expected in ${i} today. Only a ${j}% chance of precipitation.`;return N?e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-gray-900 to-gray-800 flex items-center justify-center",children:[e.jsxs(U,{children:[e.jsx("title",{children:f}),e.jsx("meta",{name:"description",content:y})]}),e.jsxs("div",{className:"text-center",children:[e.jsx(je,{className:"w-10 h-10 animate-spin text-blue-400 mx-auto mb-3"}),e.jsxs("p",{className:"text-gray-400 text-sm",children:["Loading rain forecast for ",i,"..."]})]})]}):ie?e.jsxs("div",{className:"min-h-screen bg-gradient-to-b from-gray-900 to-gray-800 flex items-center justify-center p-4",children:[e.jsxs(U,{children:[e.jsx("title",{children:f}),e.jsx("meta",{name:"description",content:y})]}),e.jsx(p,{className:"bg-gray-800 border-gray-700 max-w-md",children:e.jsx(u,{className:"pt-6",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ke,{className:"w-5 h-5 text-red-400 mt-0.5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("h3",{className:"text-white font-semibold mb-1",children:"Unable to load forecast"}),e.jsx("p",{className:"text-gray-400 text-sm",children:"Weather data is temporarily unavailable. Please try again in a moment."}),e.jsxs(g,{href:A,className:"text-blue-400 hover:text-blue-300 text-sm mt-3 inline-block",children:["View ",i," weather →"]})]})]})})})]}):e.jsxs("div",{role:"main",className:"min-h-screen bg-gradient-to-b from-gray-900 via-gray-900 to-gray-800",children:[e.jsxs(U,{children:[e.jsx("title",{children:f}),e.jsx("meta",{name:"description",content:y}),e.jsx("link",{rel:"canonical",href:F}),e.jsx("meta",{property:"og:type",content:"website"}),e.jsx("meta",{property:"og:url",content:F}),e.jsx("meta",{property:"og:title",content:f}),e.jsx("meta",{property:"og:description",content:y}),e.jsx("meta",{property:"og:site_name",content:"AskWeather"}),e.jsx("meta",{name:"twitter:card",content:"summary"}),e.jsx("meta",{name:"twitter:title",content:f}),e.jsx("meta",{name:"twitter:description",content:y})]}),e.jsxs("div",{className:"max-w-2xl mx-auto px-4 py-8 space-y-4",children:[e.jsxs(g,{href:A,className:"text-lg font-semibold text-blue-400 hover:text-blue-300 transition-colors flex items-center gap-1 mb-3 px-3 py-1.5 rounded-lg bg-blue-900/40","data-testid":"link-back-city",children:["← ",i,", ",P," weather"]}),e.jsx(p,{className:"bg-gray-800 border-gray-700","data-testid":"card-direct-answer",children:e.jsx(u,{className:"pt-6 pb-6",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:"mt-1 flex-shrink-0",children:me?e.jsx(re,{className:"w-8 h-8 text-blue-400"}):I>20?e.jsx(ae,{className:"w-8 h-8 text-gray-400"}):e.jsx(se,{className:"w-8 h-8 text-yellow-400"})}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("h1",{className:"text-2xl font-bold text-white leading-tight","data-testid":"text-question",children:["Will It Rain Today in ",z,"?"]}),e.jsx("p",{className:"text-white text-base leading-relaxed","data-testid":"text-ai-answer",children:ue})]})]})})}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsx(p,{className:"bg-gray-800 border-gray-700","data-testid":"card-precip-probability",children:e.jsxs(u,{className:"pt-5 pb-5",children:[e.jsx("p",{className:"text-gray-400 text-xs mb-1",children:"Today's rain chance"}),e.jsxs("p",{className:"text-3xl font-bold text-white","data-testid":"text-precip-prob",children:[j,"%"]}),e.jsxs("p",{className:"text-gray-500 text-xs mt-1",children:["Next 24h: ",pe,"%"]})]})}),e.jsx(p,{className:"bg-gray-800 border-gray-700","data-testid":"card-umbrella-index",children:e.jsxs(u,{className:"pt-5 pb-5",children:[e.jsx("p",{className:"text-gray-400 text-xs mb-1",children:"Umbrella index"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Re,{className:`w-5 h-5 flex-shrink-0 ${ne(v)}`}),e.jsxs("p",{className:`text-lg font-bold ${ne(v)}`,"data-testid":"text-umbrella-score",children:[v,"/10"]})]}),e.jsx("p",{className:"text-gray-400 text-xs mt-1","data-testid":"text-umbrella-label",children:Se(v)})]})})]}),k.length>0&&e.jsx(p,{className:"bg-gray-800 border-gray-700","data-testid":"card-hourly-rain",children:e.jsxs(u,{className:"pt-5 pb-4",children:[e.jsx("p",{className:"text-gray-300 text-sm font-medium mb-4",children:"Hourly rain probability"}),he?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("div",{style:{minWidth:`${k.length*32}px`},children:[e.jsx("div",{className:"flex items-end gap-1.5",style:{height:"100px"},children:k.map((s,n)=>{const c=Math.round(s.precipprob||0),R=c>0?Math.max(8,c/100*80):3;return e.jsxs("div",{className:"flex flex-col items-center gap-1",style:{minWidth:"28px",flex:"1 0 28px"},"data-testid":`bar-hour-${n}`,children:[e.jsx("span",{className:"text-gray-300 text-xs",children:c>=5?`${c}`:""}),e.jsx("div",{className:`w-full rounded-sm transition-all ${Pe(c)}`,style:{height:`${R}px`},title:`${S(s.datetime)}: ${c}%`})]},n)})}),e.jsx("div",{className:"flex items-start gap-1.5 mt-1.5",children:k.map((s,n)=>e.jsx("div",{className:"text-center",style:{minWidth:"28px",flex:"1 0 28px"},children:e.jsx("span",{className:"text-gray-300 text-xs",children:S(s.datetime)})},n))})]})}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-4 gap-1",children:[e.jsx(se,{className:"w-6 h-6 text-yellow-400 opacity-70"}),e.jsx("p",{className:"text-gray-500 text-sm",children:"No significant rain expected in the next 24 hours"})]})]})}),e.jsx(p,{className:"bg-gray-800 border-gray-700","data-testid":"card-related-links",children:e.jsxs(u,{className:"pt-5 pb-5",children:[e.jsxs("p",{className:"text-gray-400 text-xs font-medium uppercase tracking-wide mb-3",children:["More ",i," weather"]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(g,{href:A,className:"flex items-center justify-between py-2 px-3 rounded-md hover-elevate group","data-testid":"link-full-forecast",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ae,{className:"w-4 h-4 text-gray-500"}),e.jsxs("span",{className:"text-gray-300 text-sm",children:["Full ",i," forecast"]})]}),e.jsx(W,{className:"w-3.5 h-3.5 text-gray-600 group-hover:text-gray-400 transition-colors"})]}),e.jsxs(g,{href:H.isItRainingNow,className:"flex items-center justify-between py-2 px-3 rounded-md hover-elevate group","data-testid":"link-is-raining-now",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(re,{className:"w-4 h-4 text-gray-500"}),e.jsxs("span",{className:"text-gray-300 text-sm",children:["Is it raining in ",i," right now?"]})]}),e.jsx(W,{className:"w-3.5 h-3.5 text-gray-600 group-hover:text-gray-400 transition-colors"})]}),e.jsxs(g,{href:H.radar,className:"flex items-center justify-between py-2 px-3 rounded-md hover-elevate group","data-testid":"link-live-radar",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ne,{className:"w-4 h-4 text-gray-500"}),e.jsxs("span",{className:"text-gray-300 text-sm",children:["Live rain radar for ",i]})]}),e.jsx(W,{className:"w-3.5 h-3.5 text-gray-600 group-hover:text-gray-400 transition-colors"})]})]})]})}),e.jsx("div",{className:"text-center pb-4",children:e.jsx(g,{href:"/will-it-rain-today?noredirect=1",className:"text-gray-500 hover:text-gray-400 text-xs transition-colors","data-testid":"link-national-hub",children:"Rain forecasts for other US cities →"})}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-4 pt-3 border-t border-gray-700/50","data-testid":"text-data-attribution",children:["Real-time conditions from 82,000+ weather stations worldwide, in addition to weather data aggregated from"," ",e.jsx("a",{href:"https://www.weather.gov",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-foreground transition-colors",children:"NWS"}),","," ",e.jsx("a",{href:"https://www.noaa.gov",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-foreground transition-colors",children:"NOAA"}),","," ",e.jsx("a",{href:"https://www.ecmwf.int",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-foreground transition-colors",children:"ECMWF"}),","," ",e.jsx("a",{href:"https://www.metoffice.gov.uk",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-foreground transition-colors",children:"Met Office"}),","," ","and other government agencies via third-party services. Processed by AskWeather.ai."]})]})]})}export{De as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.