PageSourceSearch

https://indiancaucus.org/_next/static/chunks/pages/app/admin/polls-5b20c74f6f4a502c.js

js indiancaucus.org collected 2026-09-24 14:27:10 UTC 11,011 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9930],{27110:(e,t,r)=>{"use strict";function o(e){if(!e)return null;let t=String(e).match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/);if(!t){let t=new Date(e);return isNaN(t)?null:t.toISOString()}let[,r,o,n,a,i]=t.map(Number),s=Date.UTC(r,o-1,n,a,i),l=function(e,t){let r=new Intl.DateTimeFormat("en-US",{timeZone:t,hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}).formatToParts(e).reduce((e,t)=>(e[t.type]=t.value,e),{});return Date.UTC(+r.year,r.month-1,+r.day,+r.hour,+r.minute,+r.second)-e.getTime()}(new Date(s),"America/New_York");return new Date(s-l).toISOString()}function n(){let e=new Intl.DateTimeFormat("en-CA",{timeZone:"America/New_York",hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).formatToParts(new Date).reduce((e,t)=>(e[t.type]=t.value,e),{});return`${e.year}-${e.month}-${e.day}T${e.hour}:${e.minute}`}function a(e){if(!e)return"";let t=e instanceof Date?e:new Date(e);if(isNaN(t))return"";let r=new Intl.DateTimeFormat("en-CA",{timeZone:"America/New_York",hourCycle:"h23",year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"}).formatToParts(t).reduce((e,t)=>(e[t.type]=t.value,e),{});return`${r.year}-${r.month}-${r.day}T${r.hour}:${r.minute}`}function i(e,t={month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}){if(!e)return"";let r=e instanceof Date?e:new Date(e);return isNaN(r)?"":r.toLocaleString("en-US",{...t,timeZone:"America/New_York"})+" ET"}function s(e,t={month:"short",day:"numeric",year:"numeric"}){if(!e)return"";let r=e instanceof Date?e:new Date(e);return isNaN(r)?"":r.toLocaleDateString("en-US",{...t,timeZone:"America/New_York"})}function l(e){let t=String(e||"").match(/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2})/);if(!t)return"";let[,r,o,n,a,i]=t.map(Number);return new Date(r,o-1,n,a,i).toLocaleString("en-US",{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"})+" ET"}r.d(t,{$e:()=>o,S4:()=>n,b3:()=>i,lQ:()=>s,sX:()=>l,y4:()=>a})},67684:(e,t,r)=>{(window.__NEXT_P=window.__NEXT_P||[]).push(["/app/admin/polls",function(){return r(94182)}])},94182:(e,t,r)=>{"use strict";r.r(t),r.d(t,{default:()=>m});var o=r(37876),n=r(14232),a=r(89099),i=r(62422),s=r(62406),l=r(94430),d=r(27110);let c=e=>e?new Date(e).toLocaleString("en-US",{timeZone:"America/New_York",month:"short",day:"numeric",hour:"numeric",minute:"2-digit"}):"",u={question:"",kind:"single",options:["",""],closesAt:""};function m(){let e=(0,a.useRouter)(),{member:t,loading:r}=(0,s.IG)(),{confirm:m,toast:h,promptText:p}=(0,l.j)(),[x,f]=(0,n.useState)(u),[g,b]=(0,n.useState)(null),[y,w]=(0,n.useState)(""),[N,k]=(0,n.useState)(!1),[j,v]=(0,n.use
1State)(!1),C=t&&"admin"===t.staff_role;function S(){fetch("/api/member/mod/polls").then(e=>e.json()).then(e=>b(e.polls||[])).catch(()=>b([]))}async function D(){let e=await p({title:"Draft with AI",message:'What should the poll be about? A few words is enough — e.g. "best time for a weekend cricket meetup" or "which festival to host next".',placeholder:"Poll topic",confirmLabel:"Draft"});if(e&&e.trim()){v(!0);try{let t=await fetch("/api/member/mod/draft-poll",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({topic:e})}),r=await t.json().catch(()=>({}));if(!t.ok)throw Error(r.error||"Could not draft");f(e=>({...e,question:r.question||e.question,options:r.options&&r.options.length>=2?r.options.slice(0,30):e.options})),h("Draft ready — edit it before posting.","success")}catch(e){h(e.message,"error")}finally{v(!1)}}}async function T(){let e=x.options.map(e=>e.trim()).filter(Boolean);if(!x.question.trim())return void h("Add a question.","error");if(e.length<2)return void h("Add at least two options.","error");k(!0);try{let t=await fetch("/api/member/mod/polls",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({question:x.question,kind:x.kind,options:e,closesAt:x.closesAt||null})}),r=await t.json().catch(()=>({}));if(!t.ok)throw Error(r.error||"Could not create poll");h("Poll created.","success"),f(u),S()}catch(e){h(e.message,"error")}finally{k(!1)}}async function $(e){let t="open"===e.status?"closed":"open";try{if(!(await fetch("/api/member/mod/polls",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:e.id,status:t})})).ok)throw Error();h("closed"===t?"Poll closed.":"Poll reopened.","success"),b(r=>(r||[]).map(r=>r.id===e.id?{...r,status:t}:r))}catch{h("Could not update","error")}}async function _(e){if(await m({title:"Delete this poll?",message:"Its options and all votes will be removed.",confirmLabel:"Delete",danger:!0}))try{if(!(await fetch(`/api/member/mod/polls?id=${e.id}`,{method:"DELETE"})).ok)throw Error();h("Deleted.","success"),b(t=>(t||[]).filter(t=>t.id!==e.id))}catch{h("Could not delete","error")}}(0,n.useEffect)(()=>{if(!r){if(t&&!C)return void e.replace("/app");S()}},[r,t]);let A="w-full border border-orange-100 rounded-xl px-4 py-2.5 text-sm";return(0,o.jsxs)(i.Ay,{title:"Polls",active:"/app/admin",children:[(0,o.jsx)("div",{className:"app-fade-up flex items-center gap-2 mb-3",children:(0,o.jsx)("h1",{className:"text-xl font-extrabold text-brand-navy dark:text-white",children:"Polls & surveys"})}),(0,o.jsx)("p",{className:"app-fade-up text-gray-500 dark:text-white/55 text-sm mb-4",children:"Create a poll for the community. Members vote in the app under Polls; results update live here."}),(0,o.jsxs)("div",{className:"bg-white border border-orange-100 rounded-2xl p-4 shadow-xs mb-5",children:[(0,o.jsx)("button",{type:"button",onClick:D,disabled:j,className:"w-full mb-3 flex items-center justify-center gap-2 border border-orange-200 text-brand-orange dark:text-brand-saffron text-sm font-bold rounded-xl px-4 py-2.5 active:scale-[0.99] disabled:opacity-50",children:j?"Drafting…":"Draft with AI"}),(0,o.jsx)("textarea",{className:`${A} mb-2`,rows:2,placeholder:"Question",value:x.question,onChange:e=>f({...x,question:e.target.value}),maxLength:1e3}),(0,o.jsxs)("div",{className:"flex gap-2 mb-2",children:[(0,o.jsx)("button",{onClick:()=>f({...x,kind:"single"}),className:`flex-1 text-sm font-bold rounded-xl px-3 py-2 border ${"single"===x.kind?"border-brand-orange bg-orange-50 text-brand-navy dark:text-white":"border-orange-100 text-gray-500 dark:text-white/55"}`,children:"Single choice"}),(0,o.jsx)("button",{onClick:()=>f({...x,kind:"multi"}),className:`flex-1 text-sm font-bold rounded-xl px-3 py-2 border ${"multi"===x.kind?"border-brand-orange bg-orange-50 text-brand-navy dark:text-white":"border-orange-100 text-gray-500 dark:text-white/55"}`,children:"Multiple choice"})]}),(0,o.jsx)("div",{className:"space-y-2 mb-2",children:x.options.map((e,t)=>(0,o.jsxs)("div",{className:"flex items-center gap-2",children:[(0,o.jsx)("input",{className:A,placeholder:`Option ${t+1}
1`,value:e,onChange:e=>{var r;return r=e.target.value,void f(e=>({...e,options:e.options.map((e,o)=>o===t?r:e)}))},maxLength:300}),x.options.length>2&&(0,o.jsx)("button",{onClick:()=>{f(e=>e.options.length<=2?e:{...e,options:e.options.filter((e,r)=>r!==t)})},"aria-label":"Remove option",className:"text-gray-300 dark:text-white/30 hover:text-red-500 shrink-0",children:(0,o.jsx)("svg",{width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"2",viewBox:"0 0 24 24",children:(0,o.jsx)("line",{x1:"5",y1:"12",x2:"19",y2:"12"})})})]},t))}),x.options.length<30&&(0,o.jsx)("button",{onClick:function(){f(e=>e.options.length>=30?e:{...e,options:[...e.options,""]})},className:"text-brand-orange dark:text-brand-saffron text-sm font-bold mb-3",children:"+ Add option"}),(0,o.jsxs)("label",{className:"block text-xs font-semibold text-gray-500 dark:text-white/55 mb-1 mt-1",children:["Close date (optional) ",(0,o.jsx)("span",{className:"text-gray-400 dark:text-white/40 font-normal",children:"\xb7 Eastern (ET)"})]}),(0,o.jsx)("input",{type:"datetime-local",className:`${A} mb-3`,min:(0,d.S4)(),value:x.closesAt,onChange:e=>f({...x,closesAt:e.target.value})}),(0,o.jsx)("button",{onClick:T,disabled:N,className:"w-full bg-linear-to-r from-brand-orange to-brand-saffron text-white text-sm font-bold rounded-xl px-6 py-2.5 disabled:opacity-50",children:N?"Creating…":"Create poll"})]}),(0,o.jsx)("p",{className:"text-[11px] font-bold text-gray-400 dark:text-white/45 uppercase tracking-widest mb-2",children:"Polls"}),null===g?(0,o.jsx)("div",{className:"space-y-2",children:[0,1,2].map(e=>(0,o.jsx)("div",{className:"h-28 rounded-2xl bg-white border border-orange-100 app-shine"},e))}):0===g.length?(0,o.jsx)("p",{className:"text-gray-400 dark:text-white/45 text-sm",children:"No polls yet."}):(0,o.jsxs)("div",{className:"space-y-2",children:[(0,o.jsx)("input",{value:y,onChange:e=>w(e.target.value),placeholder:"Search polls…",className:"w-full border border-orange-100 rounded-xl px-4 py-2.5 text-sm mb-3"}),g.filter(e=>`${e.question||""} ${(e.options||[]).map(e=>e.label).join(" ")}`.toLowerCase().includes(y.trim().toLowerCase())).map(e=>(0,o.jsxs)("div",{className:"bg-white border border-orange-100 rounded-2xl p-4 shadow-xs",children:[(0,o.jsxs)("div",{className:"flex items-start justify-between gap-2",children:[(0,o.jsx)("p",{className:"font-bold text-brand-navy dark:text-white",children:e.question}),(0,o.jsx)("span",{className:`shrink-0 text-[10px] font-bold uppercase tracking-wide rounded-full px-2 py-0.5 ${"open"===e.status?"text-brand-green-dark dark:text-brand-green-light bg-green-50":"text-gray-400 bg-gray-100"}`,children:e.status})]}),(0,o.jsx)("div",{className:"mt-3 space-y-2",children:(e.options||[]).map(t=>{let r=e.totalVotes>0?Math.round(t.votes/e.totalVotes*100):0;return(0,o.jsxs)("div",{children:[(0,o.jsxs)("div",{className:"flex items-center justify-between text-sm mb-1",children:[(0,o.jsx)("span",{className:"text-gray-600 dark:text-white/70",children:t.label}),(0,o.jsxs)("span",{className:"text-gray-400 dark:text-white/45 text-xs",children:[r,"% \xb7 ",t.votes]})]}),(0,o.jsx)("div",{className:"h-2.5 rounded-full bg-orange-50 overflow-hidden",children:(0,o.jsx)("div",{className:"h-full rounded-full bg-linear-to-r from-brand-orange to-brand-saffron",style:{width:`${r}%`}})})]},t.id)})}),(0,o.jsx)("p",{className:"text-gray-400 dark:text-white/45 text-xs mt-2",children:[`${e.totalVoters} voter${1===e.totalVoters?"":"s"}`,"multi"===e.kind?"multi":"single",e.closes_at?`closes ${c(e.closes_at)}`:null,c(e.created_at)].filter(Boolean).join(" \xb7 ")}),(0,o.jsxs)("div",{className:"flex flex-wrap gap-2 mt-2.5",children:[(0,o.jsx)("button",{onClick:()=>$(e),className:"border border-orange-100 text-brand-navy dark:text-white text-xs font-bold rounded-lg px-3 py-1.5",children:"open"===e.status?"Close":"Reopen"}),(0,o.jsx)("button",{onClick:()=>_(e),className:"border border-red-200 text-red-600 text-xs font-bold rounded-lg px-3 py-1.5",children:"Delete"})]})]},e.id))]})]})}}},e=>{e.O(0,[8230,900,6475,2422,636,6593,8792],()=>e(e.s=67684)),_N_E=e.O()}]);

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.