PageSourceSearch

https://thespinoff.co.nz/_next/static/chunks/3885-f7cd7ff881da8f4e.js

js thespinoff.co.nz collected 2026-10-01 08:49:47 UTC 15,481 bytes, 1 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[3885],{43369:function(e,t,n){n.d(t,{a:function(){return a}});var r=n(85893),a=function(){return(0,r.jsx)("div",{id:"animatedLoaderLogo",className:"animatedLogo"})}},83885:function(e,t,n){n.d(t,{Z:function(){return E}});var r=n(47568),a=n(14924),i=n(82670),o=n(26042),l=n(69396),s=n(29815),c=n(70655),u=n(85893),d=n(43369),p=n(86234),v=n(57321),f=n(67294);var h=n(73935),_=n(94971),m=n(67772),g=function(e,t){return"spinoff_poll_voted_".concat(t,"_").concat(e)},b="spinoff_anon_id",w=function(e,t){return"spinoff_poll_voted_anon_".concat(t,"_").concat(e)},j=function(e){return"spinoff_poll_results_".concat(e)};function x(){try{var e=localStorage.getItem(b);if(e)return e;var t="anon_".concat(Math.random().toString(36).slice(2),"_").concat(Date.now().toString(36));return localStorage.setItem(b,t),t}catch(n){return"anon_".concat(Math.random().toString(36).slice(2))}}var y=["January","February","March","April","May","June","July","August","September","October","November","December"];function N(e,t){var n=function(e){var t=e.getDate(),n=y[e.getMonth()],r=e.getFullYear(),a="".concat(t," ").concat(n," ").concat(r),i=e.getHours(),o=e.getMinutes(),l=i>=12?"pm":"am";return 0===(i%=12)&&(i=12),{datePart:a,time:"".concat(i,":").concat(String(o).padStart(2,"0")).concat(l)}}(e),r=n.datePart,a=n.time;return t?"Voting closed on ".concat(r," ").concat(a):"Voting ends on ".concat(r," at ").concat(a)}function S(e){if(null==e||""===e)return null;var t=new Date(e);return Number.isFinite(t.getTime())?t:null}function E(e){var t=function(e){var t=(0,f.useState)(null),n=t[0],a=t[1],o=(0,f.useState)(null),l=o[0],s=o[1],u=(0,f.useState)(!1),d=u[0],p=u[1];(0,f.useEffect)((function(){if(!e)return a(null),void s("missing-slug");var t=!1,n=function(){var n=(0,r.Z)((function(){var n,r,o,l;return(0,c.__generator)(this,(function(c){switch(c.label){case 0:return c.trys.push([0,3,4,5]),p(!0),s(null),[4,fetch("/api/public/polls/by-slug/".concat(encodeURIComponent(e)))];case 1:if(!(n=c.sent()).ok){if(404===n.status)throw new Error("not-found");throw new Error("fetch-failed")}return[4,n.json()];case 2:return r=c.sent(),t||a(r),[3,5];case 3:return o=c.sent(),t||(l=(0,i.Z)(o,Error)?o.message:"fetch-failed",s(l),a(null)),[3,5];case 4:return t||p(!1),[7];case 5:return[2]}}
1))}));return function(){return n.apply(this,arguments)}}();return n(),function(){t=!0}}),[e]);var v,h,_=(0,f.useMemo)((function(){if(!(null===n||void 0===n?void 0:n.poll))return"unavailable";var e=n.poll,t=e.status,r=e.startsAt,a=e.endsAt,i=new Date,o=r?new Date(r):null,l=a?new Date(a):null;return"draft"===t?"unavailable":"closed"===t||"archived"===t||l&&i>l?"closed":o&&i<o||"scheduled"===t?"scheduled":"live"}),[n]);return{data:n,poll:null!==(v=null===n||void 0===n?void 0:n.poll)&&void 0!==v?v:null,questions:null!==(h=null===n||void 0===n?void 0:n.questions)&&void 0!==h?h:[],loading:d,error:l,state:_}}(e.pollSlug),n=t.poll,b=t.questions,y=t.loading,E=t.error,I=t.state,T=(0,v.K)(),O=T.authenticating,P=T.user,Z=T.member,q=T.getToken,k=(0,f.useState)({}),A=k[0],C=k[1],L=(0,f.useState)({}),D=L[0],M=L[1],R=(0,f.useState)(!1),V=R[0],F=R[1],U=(0,f.useState)(null),W=U[0],J=U[1],B=(0,f.useState)(!1),z=B[0],G=B[1],H=(0,f.useState)(!1),K=H[0],Y=H[1],Q=(0,f.useState)(!1),X=Q[0],$=Q[1],ee=(0,f.useState)(null),te=ee[0],ne=ee[1],re=(0,f.useState)(null),ae=re[0],ie=re[1],oe=(0,f.useState)(!1),le=oe[0],se=oe[1],ce=(0,f.useState)(!1),ue=ce[0],de=ce[1],pe=(0,f.useState)(null),ve=pe[0],fe=pe[1],he=!0===(null===n||void 0===n?void 0:n.allowAnonymousVoting),_e=(0,f.useMemo)((function(){return(0,s.Z)(b).sort((function(e,t){return(e.sortOrder||0)-(t.sortOrder||0)}))}),[b]),me="closed"===I||z||le;if((0,f.useEffect)((function(){if($(!0),he){var e=x();fe(e)}}),[he]),(0,f.useEffect)((function(){if(!n||!me)return ne(null),void ie(null);if("closed"===I){var e,t=null===(e=m.tO.local)||void 0===e?void 0:e.get(j(n.id));if(t)return void ne(t)}var a=!1,o=function(){var e=(0,r.Z)((function(){var e,t,r,o,l,s,u,d,p,v;return(0,c.__generator)(this,(function(c){switch(c.label){case 0:return c.trys.push([0,8,,9]),ie(null),P?[4,q()]:[3,2];case 1:return t=c.sent(),[3,3];case 2:t=null,c.label=3;case 3:return r={},(e=t)&&(r.Authorization="Bearer ".concat(e)),[4,fetch("/api/polls/".concat(encodeURIComponent(n.id),"/results"),{method:"GET",cache:"no-store",headers:r})];case 4:return(o=c.sent()).ok?[3,6]:[4,o.json().catch((function(){return{}}))];case 5:if(l=c.sent(),403===o.status&&"RESULTS_NOT_VISIBLE"===l.code)throw new Error(l.error||"Results are not available yet. They may appear after the poll closes.");if(401===o.status)throw new Error(l.error||"Sign in again to load results.");throw new Error(l.error||"Failed to load poll results.");case 6:return[4,o.json()];case 7:return s=c.sent(),a||(d=(null===(u=s.results)||void 0===u?void 0:u.questions)||[],"closed"===I&&(null===(p=m.tO.local)||void 0===p||p.set(j(n.id),d,new Date(Date.now()+2592e6))),ne(d)),[3,9];case 8:return v=c.sent(),a||ie((0,i.Z)(v,Error)?v.message:"Failed to load poll results."),[3,9];case 9:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}();return o(),function(){a=!0}}),[n,me,I,P,q]),(0,f.useEffect)((function(){var e;if(n&&he&&ve){var t=!!(null===(e=m.tO.local)||void 0===e?void 0:e.get(w(n.id,ve)));se(t),de(!1)}}),[n,he,ve]),(0,f.useEffect)((function(){var e;if(n&&!he){if(!P)return se(!1),void de(!1);if(null===(e=m.tO.local)||void 0===e?void 0:e.get(g(n.id,P.uid)))return se(!0),void de(!1);var t=!1;de(!0);var a=function(){var e=(0,r.Z)((function(){var e,r,a,i,o,l;return(0,c.__generator)(this,(function(s){switch(s.label){case 0:return s.trys.push([0,4,,5]),[4,q()];case 1:return(e=s.sent())?[4,fetch("/api/polls/".concat(encodeURIComponent(n.id)),{method:"GET",headers:{Authorization:"Bearer ".concat(e)},cache:"no-store"})]:(t||de(!1),[2]);case 2:return(r=s.sent()).ok?[4,r.json()]:(t||de(!1),[2]);case 3:return a=s.sent(),t||((l=!!(null===(i=a.myVotes)||void 0===i?void 0:i.length))&&(null===(o=m.tO.local)||void 0===o||o.set(g(n.id,P.uid),!0)),se(l),de(!1)),[3,5];case 4:return s.sent(),t||de(!1),[3,5];case 5:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}();return a(),function(){t=!0}}}),[n,he,P,q]),y)return(0,u.jsx)("div",{className:"poll-interactive poll-interactive--loading",children:(0,u.jsx)(d.a,{})});if(E||!n||"unavailable"===I)return(0,u.jsx)("div",{className:"poll-interactive poll-interactive--unavailable",children:(0,u.jsx)("p",{className:"poll-interactive__status",children:"Poll unavailable."})});var ge=new Date,be=S(n.startsAt),we=S(n.endsAt),je=we?N(we,!!(we&&ge>=we)):null,xe=be&&be>ge?"Voting opens ".concat(be.toLocaleString(),"."):"Poll is scheduled.",ye=!!(null===Z||void 0===Z?void 0:Z.id),Ne="live"!==I||V||z,Se=he?"live"!==I||V||z:"live"!==I||V||z||!!P&&!ye,Ee=!(he?"live"===I&&!V&&!z:"live"===I&&!V&&!z&&!!P&&ye),Ie=function(){var e=(0,r.Z)((function(){var e,t,r,a,o,l,s,u,d,p,v,f,h,b,j,y,N,S,E;return(0,c.__generator)(this,(function(I){switch(I.label){case 0:if(!n)return[2];if(J(null),!he)return[3,13];e=null!==ve&&void 0!==ve?ve:x(),ve||fe(e),I.label=1;case 1:I.trys.push([1,10,11,12]),F(!0),r=!0,a=!1,o=void 0,I.label=2;case 2:I.trys.push([2,7,8,9]),l=function(){var t,r,a,i,o,l,s,d,p,v;return(0,c.__generator)(this,(function(c){switch(c.label){case 0:if(t=u.value,!(a=A[t.id]))throw new Error("Please select an option for each question.");if(i=t.options.find((function(e){return e.id===a})),o=(null===i||void 0===i?void 0:i.isWriteIn)?null===(r=D[t.id])||void 0===r?void 0:r.trim():void 0,(null===i||void 0===i?void 0:i.isWriteIn)&&!o)throw new Error("Please add text for the write-in option.");return[4,fetch("/api/polls/".concat(encodeURIComponent(n.id),"/vote"),{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json"},body:JSON.stringify({questionId:t.id,optionId:a,writeInText:o,anonId:e})})];case 1:return(l=c.sent()).ok?[3,3]:[4,l.json().catch((function(){return{}}))];case 2:if(s=c.sent(),429===l.status||"RATE_LIMITED"===s.code)throw d=l.headers.get("Retry-After"),p=d?parseInt(d,10):NaN,v=Number.isFinite(p)&&p>0?" Try again in about ".concat(p," seconds."):" Please wait a few minutes and try again.",new Error("Too many vote attempts.".concat(v));throw new Error(s.error||"Vote failed.");case 3:return[2]}}
1))},s=_e[Symbol.iterator](),I.label=3;case 3:return(r=(u=s.next()).done)?[3,6]:[5,(0,c.__values)(l())];case 4:I.sent(),I.label=5;case 5:return r=!0,[3,3];case 6:return[3,9];case 7:return S=I.sent(),a=!0,o=S,[3,9];case 8:try{r||null==s.return||s.return()}finally{if(a)throw o}return[7];case 9:return G(!0),null===(t=m.tO.local)||void 0===t||t.set(w(n.id,e),!0),[3,12];case 10:return d=I.sent(),J((0,i.Z)(d,Error)?d.message:"Unable to submit vote."),[3,12];case 11:return F(!1),[7];case 12:return[2];case 13:if(!P)return(0,_.authPromptViewEvent)("poll"),Y(!0),[2];I.label=14;case 14:if(I.trys.push([14,24,25,26]),F(!0),!ye)throw new Error("Still loading your member profile. Please try again.");return[4,q()];case 15:if(!(v=I.sent()))throw new Error("Please sign in to vote.");f=!0,h=!1,b=void 0,I.label=16;case 16:I.trys.push([16,21,22,23]),j=function(){var e,t,r,a,i,o,l,s,u,d;return(0,c.__generator)(this,(function(c){switch(c.label){case 0:if(e=N.value,!(r=A[e.id]))throw new Error("Please select an option for each question.");if(a=e.options.find((function(e){return e.id===r})),i=(null===a||void 0===a?void 0:a.isWriteIn)?null===(t=D[e.id])||void 0===t?void 0:t.trim():void 0,(null===a||void 0===a?void 0:a.isWriteIn)&&!i)throw new Error("Please add text for the write-in option.");return[4,fetch("/api/polls/".concat(encodeURIComponent(n.id),"/vote"),{method:"POST",cache:"no-store",headers:{"Content-Type":"application/json",Authorization:"Bearer ".concat(v)},body:JSON.stringify({questionId:e.id,optionId:r,writeInText:i})})];case 1:return(o=c.sent()).ok?[3,3]:[4,o.json().catch((function(){return{}}))];case 2:if(l=c.sent(),429===o.status||"RATE_LIMITED"===l.code)throw s=o.headers.get("Retry-After"),u=s?parseInt(s,10):NaN,d=Number.isFinite(u)&&u>0?" Try again in about ".concat(u," seconds."):" Please wait a few minutes and try again.",new Error("Too many vote attempts from this account.".concat(d));throw new Error(l.error||"Vote failed.");case 3:return[4,o.json().catch((function(){return null}))];case 4:return c.sent(),[2]}}))},y=_e[Symbol.iterator](),I.label=17;case 17:return(f=(N=y.next()).done)?[3,20]:[5,(0,c.__values)(j())];case 18:I.sent(),I.label=19;case 19:return f=!0,[3,17];case 20:return[3,23];case 21:return S=I.sent(),h=!0,b=S,[3,23];case 22:try{f||null==y.return||y.return()}finally{if(h)throw b}return[7];case 23:return G(!0),P&&(null===(p=m.tO.local)||void 0===p||p.set(g(n.id,P.uid),!0)),[3,26];case 24:return E=I.sent(),J((0,i.Z)(E,Error)?E.message:"Unable to submit vote."),[3,26];case 25:return F(!1),[7];case 26:return[2]}}
1))}));return function(){return e.apply(this,arguments)}}();return(0,u.jsxs)("div",{className:"poll-interactive poll-interactive--".concat(I),children:[(0,u.jsxs)("header",{className:"poll-interactive__header",children:[(0,u.jsx)("h2",{className:"poll-interactive__title",children:n.title}),n.description?(0,u.jsx)("p",{className:"poll-interactive__description",children:n.description}):null]}),"scheduled"===I&&(0,u.jsx)("p",{className:"poll-interactive__status",children:xe}),"closed"===I&&!le&&!z&&(0,u.jsxs)("p",{className:"poll-interactive__status",children:["Voting is closed",we?" (closed ".concat(we.toLocaleString(),")"):"","."]}),!he&&P&&!ye&&"live"===I&&(0,u.jsx)("div",{className:"poll-interactive__member-loading",role:"status","aria-live":"polite","aria-label":"Loading your member profile",children:(0,u.jsxs)("span",{className:"poll-interactive__loading-dots","aria-hidden":"true",children:[(0,u.jsx)("span",{className:"poll-interactive__loading-dot"}),(0,u.jsx)("span",{className:"poll-interactive__loading-dot"}),(0,u.jsx)("span",{className:"poll-interactive__loading-dot"})]})}),(z||le)&&(0,u.jsx)("p",{className:"poll-interactive__status poll-interactive__status--success",children:"Thanks, your vote has been recorded."}),W&&(0,u.jsx)("p",{className:"poll-interactive__status poll-interactive__status--error",children:W}),!me&&!he&&(O||ue)&&(0,u.jsx)("div",{className:"poll-interactive__member-loading",role:"status","aria-live":"polite","aria-label":"Loading poll",children:(0,u.jsxs)("span",{className:"poll-interactive__loading-dots","aria-hidden":"true",children:[(0,u.jsx)("span",{className:"poll-interactive__loading-dot"}),(0,u.jsx)("span",{className:"poll-interactive__loading-dot"}),(0,u.jsx)("span",{className:"poll-interactive__loading-dot"})]})}),!me&&(he||!O&&!ue)&&(0,u.jsxs)(u.Fragment,{children:[_e.map((function(e){return(0,u.jsxs)("fieldset",{disabled:Ne,className:"poll-interactive__question",children:[(0,u.jsx)("legend",{className:"poll-interactive__question-title",children:e.question}),e.options.sort((function(e,t){return e.sortOrder-t.sortOrder})).map((function(t){return(0,u.jsxs)("div",{className:"poll-interactive__option",children:[(0,u.jsxs)("label",{className:"poll-interactive__option-label",children:[(0,u.jsx)("input",{type:"radio",name:"poll-q-".concat(e.id),value:t.id,checked:A[e.id]===t.id,onChange:function(){return C((function(n){return(0,l.Z)((0,o.Z)({},n),(0,a.Z)({},e.id,t.id))}))}}),t.label]}),t.isWriteIn&&A[e.id]===t.id&&(0,u.jsx)("div",{className:"poll-interactive__writein-wrap",children:(0,u.jsx)("input",{className:"poll-interactive__writein-input",type:"text",maxLength:200,value:D[e.id]||"",onChange:function(t){return M((function(n){return(0,l.Z)((0,o.Z)({},n),(0,a.Z)({},e.id,t.target.value))}))},placeholder:"Write your answer"})})]},t.id)}))]},e.id)})),(0,u.jsx)("button",{className:"poll-interactive__submit ".concat(Ee?"poll-interactive__submit--disabled":""),type:"button",onClick:Ie,disabled:Se,children:V?"Submitting...":z?"Submitted":"Vote"})]}),!he&&X?(0,h.createPortal)((0,u.jsx)(p.Z,{isVisible:K,onClose:function(){return Y(!1)},skipEnhancedSignup:!0,registrationSource:"onsite_poll",align:"center",loginHeadline:"Sign in or sign up to have your say",loginPrompt:"Creating an account with The Spinoff is free, and lets you react to comments, participate in polls, and more."}),document.body):null,me&&(0,u.jsxs)("section",{className:"poll-interactive__results",children:[(0,u.jsx)("h3",{className:"poll-interactive__results-title",children:"Results"}),ae&&(0,u.jsx)("p",{className:"poll-interactive__status poll-interactive__status--error",children:ae}),!te&&!ae&&(0,u.jsx)("p",{className:"poll-interactive__status",children:"Loading results..."}),null===te||void 0===te?void 0:te.map((function(e){return(0,u.jsxs)("div",{className:"poll-interactive__result-question",children:[(0,u.jsx)("h4",{className:"poll-interactive__result-question-title",children:e.question}),e.options.slice().sort((function(e,t){return t.count-e.count})).map((function(e){return(0,u.jsxs)("div",{className:"poll-interactive__result-row",children:[(0,u.jsxs)("div",{className:"poll-interactive__result-meta",children:[(0,u.jsx)("span",{children:e.label}),(0,u.jsxs)("span",{children:[e.percent,"%"]})]}),(0,u.jsx)("div",{className:"poll-interactive__result-bar-track",children:(0,u.jsx)("div",{className:"poll-interactive__result-bar-fill",style:{width:"".concat(Math.max(0,Math.min(100,e.percent)),"%")}})})]}
1,e.optionId)}))]},e.questionId)}))]}),je?(0,u.jsx)("p",{className:"poll-interactive__ends-at",children:je}):null]})}}}]);

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.