PageSourceSearch

https://app.backstagebaton.com/app/assets/AudienceCounterPage-TJ26zWnh.js

js backstagebaton.com collected 2026-10-07 08:51:36 UTC 10,637 bytes, 1 lines download raw bytes

1import{m as q,c as F,r as s,z as V,o as C,E,j as e}from"./index-_aijvlUq.js";function R(){navigator.vibrate&&navigator.vibrate(50)}function H(){const{token:r}=q(),{showError:c,showSuccess:h}=F(),[l,d]=s.useState(null),[m,u]=s.useState(!0),[t,o]=s.useState(!1),[p,j]=s.useState(!1),[y,f]=s.useState({}),[M,b]=s.useState(0),[D,I]=s.useState(null),[S,T]=s.useState(0),v=s.useRef([]),A=s.useRef(null),g=s.useRef(0);s.useEffect(()=>(B(),A.current=setInterval(z,15e3),()=>clearInterval(A.current)),[r]);const w=s.useRef(null),N=s.useCallback(async()=>{if(!(typeof navigator>"u"||!("wakeLock"in navigator))&&!w.current)try{const n=await navigator.wakeLock.request("screen");n.addEventListener("release",()=>{w.current=null}),w.current=n}catch{}},[]);s.useEffect(()=>{function n(){document.visibilityState==="visible"&&N()}return document.addEventListener("visibilitychange",n),()=>{document.removeEventListener("visibilitychange",n),w.current&&(w.current.release().catch(V("wake lock release on unmount")),w.current=null)}},[N]);async function z(){if(!(g.current>0))try{const n=await C.getAudienceByToken(r);if(g.current>0)return;f(n.counts||{}),b(n.grandTotal||0),I(new Date)}catch{}}async function B(){u(!0);try{const n=await C.getAudienceByToken(r);d(n),f(n.counts||{}),b(n.grandTotal||0)}
1catch(n){n.response?.status===410?o(!0):j(!0)}finally{u(!1)}}const k=s.useCallback(async(n,x)=>{R(),N();const i=x?`${n}::${x}`:n;f(a=>({...a,[i]:(a[i]||0)+1})),b(a=>a+1),v.current.push({category:n,county:x||null}),v.current.length>20&&v.current.shift(),T(v.current.length),g.current+=1;try{const a=await C.incrementAudience(r,{category:n,county:x||null});f(L=>({...L,[i]:a.count})),b(a.grandTotal)}catch{f(a=>({...a,[i]:Math.max((a[i]||1)-1,0)})),b(a=>Math.max(a-1,0)),c(E)}finally{g.current=Math.max(0,g.current-1)}},[r,N]),$=s.useCallback(async(n,x)=>{const i=x?`${n}::${x}`:n;if(!((y[i]||0)<=0)){R(),f(a=>({...a,[i]:Math.max((a[i]||0)-1,0)})),b(a=>Math.max(a-1,0)),g.current+=1;try{const a=await C.decrementAudience(r,{category:n,county:x||null});f(L=>({...L,[i]:a.count})),b(a.grandTotal)}catch{f(a=>({...a,[i]:(a[i]||0)+1})),b(a=>a+1),c(E)}finally{g.current=Math.max(0,g.current-1)}}},[r,y]),U=s.useCallback(()=>{const n=v.current.pop();T(v.current.length),n&&$(n.category,n.county)},[$]);return m?e.jsx("div",{className:"flex justify-center items-center h-dvh bg-gray-50",children:e.jsxs("svg",{className:"animate-spin motion-reduce:!animate-spin h-8 w-8 text-band-500",viewBox:"0 0 24 24",fill:"none",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"})]})}):t?e.jsx("div",{className:"flex items-center justify-center h-dvh bg-gray-50",children:e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-8 text-center max-w-sm",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 mb-2",children:"Link Expired"}),e.jsx("p",{className:"text-sm text-gray-500",children:"This attendance link has expired."})]})}):p||!l?e.jsx("div",{className:"flex items-center justify-center h-dvh bg-gray-50",children:e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 p-8 text-center max-w-sm",children:[e.jsx("h2",{className:"text-lg font-semibold text-gray-800 mb-2",children:"Not Available"}),e.jsx("p",{className:"text-sm text-gray-500",children:"Audience counter is not available for this performance."})]})}):e.jsxs("div",{className:"h-dvh bg-gray-50 flex flex-col overflow-hidden",onClick:N,children:[e.jsx("div",{className:"bg-white border-b border-gray-200 px-4 py-3 shrink-0",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-base font-bold text-gray-900 truncate leading-tight",children:l.performance.title}),D&&e.jsxs("p",{className:"text-xs text-green-600 flex items-center gap-1.5 mt-0.5",children:[e.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse motion-reduce:animate-none"}),"Live — syncing with other counters"]})]}),e.jsxs("div",{className:"shrink-0 text-right",children:[e.jsx("p",{className:"text-4xl font-bold text-band-600 leading-none tabular-nums",children:M}),e.jsx("p",{className:"text-xs font-medium text-gray-600 mt-1",children:"total in"})]}),e.jsx("button",{type:"button",onClick:async()=>{R();const n={title:`${l?.performance?.title||"Audience counter"} — counter`,text:"Help count audience members at the door",url:window.location.href};try{if(navigator.share){await navigator.share(n);return}await navigator.clipboard.writeText(window.location.href),h("Link copied — paste it to share with another volunteer.")}catch(x){if(x?.name==="AbortError")return;try{await navigator.clipboard.writeText(window.location.href),h("Link copied — paste it to share with another volunteer.")}catch{c("Could not share link.")}}},className:"shrink-0 p-3 rounded-lg text-gray-500 hover:text-gray-700 hover:bg-gray-100 active:bg-gray-200",title:"Share counter link","aria-label":"Share counter link",children:e.jsx("svg",{className:"h-6 w-6",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",strokeWidth:2,children:e.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M8.684 13.342C8.886 12.938 9 12.482 9 12c0-.482-.114-.938-.316-1.342m0 2.684a3 3 0 110-2.684m0 2.684l6.632 3.316m-6.632-6l6.632-3.3
116m0 0a3 3 0 105.367-2.684 3 3 0 00-5.367 2.684zm0 9.316a3 3 0 105.368 2.684 3 3 0 00-5.368-2.684z"})})})]})}),e.jsxs("div",{className:"flex-1 flex flex-col p-3 min-h-0 gap-3",children:[e.jsxs("div",{className:"flex-1 flex flex-col min-h-0",children:[l.mode==="simple"&&e.jsx(W,{count:y.total||0,onIncrement:()=>k("total")}),l.mode==="age_group"&&e.jsx(_,{counts:y,onIncrement:k}),l.mode==="county"&&e.jsx(G,{counties:l.counties,counts:y,onIncrement:k}),l.mode==="county_age"&&e.jsx(O,{counties:l.counties,counts:y,onIncrement:k})]}),e.jsxs("button",{type:"button",onClick:U,disabled:S===0,className:"shrink-0 w-full py-4 rounded-xl bg-gray-200 text-gray-700 text-lg font-semibold disabled:opacity-30 disabled:cursor-not-allowed active:bg-gray-300 transition-colors","aria-label":"Undo last tap",children:["↩ Undo last tap",S>0?` (${S})`:""]})]})]})}function W({count:r,onIncrement:c}){return e.jsx("div",{className:"flex-1 flex flex-col items-center justify-center min-h-0",children:e.jsxs("button",{type:"button",onClick:c,className:"flex-1 w-full max-w-md rounded-2xl bg-band-600 hover:bg-band-700 active:bg-band-800 transition-colors duration-75 text-white flex flex-col items-center justify-center select-none",children:[e.jsx("span",{className:"text-8xl font-bold tabular-nums",children:r}),e.jsx("span",{className:"text-lg font-medium opacity-75 mt-2",children:"Tap to count"})]})})}function _({counts:r,onIncrement:c}){const h=r.adult||0,l=r.child||0,d=s.useRef({});function m(u){const t=Date.now();t-(d.current[u]||0)<300||(d.current[u]=t,c(u))}return e.jsxs("div",{className:"flex-1 flex gap-3 min-h-0",children:[e.jsxs("button",{type:"button",onClick:()=>m("adult"),className:"flex-1 rounded-2xl bg-band-600 hover:bg-band-700 active:bg-band-800 transition-colors duration-75 text-white flex flex-col items-center justify-center select-none min-h-0",children:[e.jsx("span",{className:"text-6xl font-bold tabular-nums",children:h}),e.jsx("span",{className:"text-base font-medium opacity-75 mt-1",children:"Adult"})]}),e.jsxs("button",{type:"button",onClick:()=>m("child"),className:"flex-1 rounded-2xl bg-accent-500 hover:bg-accent-600 active:bg-accent-700 transition-colors duration-75 text-white flex flex-col items-center justify-center select-none min-h-0",children:[e.jsx("span",{className:"text-6xl font-bold tabular-nums",children:l}),e.jsx("span",{className:"text-base font-medium opacity-75 mt-1",children:"Child"})]})]})}function G({counties:r,counts:c,onIncrement:h}){const l=r.length>6?"grid-cols-3":"grid-cols-2",d=s.useRef({});function m(t){const o=Date.now();o-(d.current[t]||0)<300||(d.current[t]=o,h("total",t))}const u=t=>t?.toLowerCase?.()==="other";return e.jsx("div",{className:`grid ${l} gap-2 flex-1 min-h-0`,children:r.map(t=>{const o=c[`total::${t}`]||0;return e.jsxs("button",{type:"button",onClick:()=>m(t),className:"rounded-xl bg-white border-2 border-gray-200 hover:border-band-400 active:bg-band-100 active:border-band-500 transition-colors duration-75 flex flex-col items-center justify-center select-none min-h-0 px-2",children:[e.jsx("span",{className:"text-4xl font-bold text-gray-900 leading-none tabular-nums",children:o}),e.jsx("span",{className:`text-lg mt-1 truncate max-w-full ${u(t)?"italic text-gray-500 font-medium":"font-semibold text-gray-700"}`,children:t})]},t)})})}function O({counties:r,counts:c,onIncrement:h}){const l=r.length>6?"grid-cols-3":"grid-cols-2",d=s.useRef({});function m(t,o){const p=`${t}::${o}`,j=Date.now();j-(d.current[p]||0)<300||(d.current[p]=j,h(t,o))}const u=t=>t?.toLowerCase?.()==="other";return e.jsx("div",{className:`grid ${l} gap-2 flex-1 min-h-0 auto-rows-fr`,children:r.map(t=>{const o=c[`adult::${t}`]||0,p=c[`child::${t}`]||0,j=o+p;return e.jsxs("div",{className:"bg-white rounded-xl border border-gray-200 flex flex-col min-h-0 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 shrink-0",children:[e.jsx("span",{className:`text-base truncate ${u(t)?"italic text-gray-500 font-medium":"font-bold text-gray-800"}`,children:t}),e.jsx("span",{className:"text-base font-bold text-band-600 tabular-nums",children:j})]}),e.jsxs("div",{className:"flex gap-1.5 px-1.5 flex-1 min-h-0 pb-2",children:[e.jsxs("button",{type:"button",onClick:()=>m("adult",t),className:"flex-1 rounded-lg bg-band-50 border border-band-200 hover:bg-band-100 active:bg-band-300 transition-colors duration-75 flex flex-col items-center justify-center select-none min-h-0",children:[e.jsx("span",{className:"text-4xl font-bold text-band-700 leading-none tabular-nums",children:o}),e.jsx("span",{className:"text-sm font-semibold text-band-600 mt-1",children:"Adult"})]}),e.jsxs("button",{type:"button",onClick:()=>m("child",t),className:"flex-1 rounded-lg bg-accent-50 border border-accent-200 hover:bg-accent-100 active:bg-accent-300 transition-colors duration-75 flex flex-col items-center justify-center select-none min-h-0",children:[e.jsx("span",{className:"text-4xl font-bold text-accent-700 leading-none tabular-nums",children:p}),e.jsx("span",{className:"text-sm font-semibold text-accent-600 mt-1",children:"Child"})]})]})]},t)})})}export{H as AudienceCounterPage};

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.