PageSourceSearch

https://www.towerphs.com/_next/static/chunks/pages/admin/layout-979db9600ddc8ff0.js

js towerphs.com collected 2026-10-02 19:08:22 UTC 16,999 bytes, 1 lines download raw bytes

1(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[258],{4935:function(e,t,a){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/layout",function(){return a(8630)}])},1523:function(e,t,a){"use strict";a.d(t,{A:function(){return m},Z:function(){return x}});var s=a(5893),n=a(9008),i=a.n(n),l=a(1664),r=a.n(l),d=a(1163),o=a(7294),c=a(7368),u=a(8997);let h=(0,o.createContext)(null);function m(){let e=(0,o.useContext)(h);if(!e)throw Error("useAdmin must be used inside <AdminShell>");return e}let p=[{href:"/admin",label:"Dashboard"},{href:"/admin/blurbs",label:"Blurbs"},{href:"/admin/letters",label:"Letters"},{href:"/admin/layout",label:"App layout"},{href:"/admin/schedule",label:"Schedule"},{href:"/admin/forms",label:"Forms"},{href:"/admin/live",label:"Live"},{href:"/admin/crossword",label:"Crosswords"},{href:"/admin/vanguard",label:"Vanguard"},{href:"/admin/push",label:"Push"}];function x(e){let{title:t,wide:a,children:n}=e,l=(0,c.o_)(),[r,d]=(0,o.useState)({kind:"loading"});return(0,o.useEffect)(()=>{let e=!1,t=async t=>{var a;if(e)return;if(!(null==t?void 0:null===(a=t.user)||void 0===a?void 0:a.email)){d({kind:"signedout"});return}let s=t.user.email,{data:n,error:i}=await l.from("editor").select("email, role").eq("email",s).maybeSingle();if(!e){if(i||!n){d({kind:"noteditor",email:s});return}d({kind:"editor",session:t,email:s,role:"admin"===n.role?"admin":"editor"})}};l.auth.getSession().then(e=>{let{data:a}=e;return t(a.session)});let{data:a}=l.auth.onAuthStateChange((e,a)=>{t(a)});return()=>{e=!0,a.subscription.unsubscribe()}},[l]),(0,s.jsxs)("div",{className:"ta-root",children:[(0,s.jsxs)(i(),{children:[(0,s.jsx)("title",{children:"".concat(t," | Tower Console")}),(0,s.jsx)("meta",{name:"robots",content:"noindex, nofollow"})]}),"loading"===r.kind&&(0,s.jsx)(b,{children:(0,s.jsx)("p",{className:"ta-gate-body ta-muted",children:"Loading…"})}),"signedout"===r.kind&&(0,s.jsx)(g,{supabase:l}),"noteditor"===r.kind&&(0,s.jsx)(j,{supabase:l,email:r.email}),"editor"===r.kind&&(0,s.jsx)(h.Provider,{value:{supabase:l,session:r.session,email:r.email,role:r.role},children:(0,s.jsx)(f,{title:t,email:r.email,supabase:l,wide:a,children:n})})]})}function b(e){let{children:t}=e;return(0,s.jsx)("div",{className:"ta-gate",children:(0,s.jsxs)("div",{className:"ta-gate-inner",children:[(0,s.jsx)("div",{className:"ta-gate-wordmark",children:"The Tower"}),(0,s.jsx)("div",{className:"ta-gate-rules",children:"Editorial Console"}),t]})})}function g(e){let{supabase:t}=e,[a,n]=(0,o.useState)(""),[i,l]=(0,o.useState)(""),[r,d]=(0,o.useState)(!1),[c,u]=(0,o.useState)(null),h=async e=>{e.preventDefault(),d(!0),u(null);let{error:s}=await t.auth.signInWithPassword({email:a.trim(),password:i});s&&u(s.message),d(!1)};return(0,s.jsxs)(b,{children:[(0,s.jsxs)("form",{className:"ta-gate-form",onSubmit:h,children:[(0,s.jsxs)("label",{children:["Email",(0,s.jsx)("input",{type:"email",value:a,onChange:e=>n(e.target.value),autoComplete:"username",required:!0,autoFocus:!0})]}),(0,s.jsxs)("label",{children:["Password",(0,s.jsx)("input",{type:"password",value:i,onChange:e=>l(e.target.value),autoComplete:"current-password",required:!0})]}),c&&(0,s.jsx)("p",{className:"ta-error",children:c}),(0,s.jsx)("button",{className:"ta-btn ta-btn-primary",type:"submit",disabled:r,children:r?"Signing in…":"Sign in"})]}),(0,s.jsx)("p",{className:"ta-gate-note",children:"Accounts are issued by invitation. Ask a console admin if you need access."})]})}function j(e){let{supabase:t,email:a}=e;return(0,s.jsxs)(b,{children:[(0,s.jsxs)("p",{className:"ta-gate-body",children:["You are signed in as ",(0,s.jsx)("b",{children:a}),", but that account is not on the editor list, so the console is closed to it."]}),(0,s.jsx)("p",{className:"ta-gate-body ta-muted ta-small",children:"If you should have access, ask a console admin to add your email to the editor list."}),(0,s.jsx)("button",{className:"ta-btn",onClick:()=>t.auth.signOut(),children:"Sign out"})]})}function f(e){let{title:t,email:a,supabase:n,wide:i,children:l}=e,c=(0,d.useRouter)(),[h,m]=(0,o.useState)(!1);return(0,o.useEffect)(()=>{m(!1)},[c.asPath]),(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("header",{className:"ta-masthead",children:[(0,s.jsxs)(r(),{href:"/admin",className:"ta-masthead-logo",children:[(0,s.jsx)("img",{src:"/assets/tower-short.png",alt:"",draggable:"false"}),(0,s.jsx)("h1",{children:"The Tower"})]}),(0,s.jsx)("span",{className:"ta-masthead-tag",children:"Console"}),(0,s.jsxs)("div",{className:"ta-masthead-sides",children:[(0,s.jsx)("p",{className:"ta-masthead-date",suppressHydrationWarning:!0,children:(0,u.Bt)().toUpperCase()}),(0,s.jsxs)("div",{className:"ta-masthead-user",children:[(0,s.jsx)("span",{className:"ta-masthead-email",children:a}),(0,s.jsx)("button",{className:"ta-btn ta-btn-small",onClick:()=>n.auth.signOut(),children:"Sign out"})]})]})]}),(0,s.jsxs)("nav",{className:"ta-nav","data-open":h?"true":"false",children:[(0,s.jsx)("button",{className:"ta-nav-toggle","aria-expanded":h,onClick:()=>m(!h),children:h?"✕ Close":"☰ Sections"}),(0,s.jsx)("div",{className:"ta-nav-links",children:p.map(e=>{let t="/admin"===e.href?"/admin"===c.pathname:c.pathname.startsWith(e.href);return(0,s.jsx)(r(),{href:e.href,className:t?"active":"",children:e.label},e.href)})})]}),(0,s.jsxs)("main",{className:"ta-content".concat(i?" wide":""),children:[(0,s.jsx)("h1",{className:"ta-page-title",children:t}),l]})]})}},7368:function(e,t,a){"use strict";let s;a.d(t,{q2:function(){return r},o_:function(){return l},oz:function(){return d}});var n=a(2629);a(1864),a(2474);let i="https://yusjougmsdnhcsksadaw.supabase.co";function l(){return s||(s=(0,n.eI)(i,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Inl1c2pvdWdtc2RuaGNza3NhZGF3Iiwicm9sZSI6ImFub24iLCJpYXQiOjE2NDU1NzI4NzQsImV4cCI6MTk2MTE0ODg3NH0.DHLgiswzK6Y_z5_mXAkRn1xy60zvhdb_iQH5gAyJorg",{auth:{persistSession:!0,autoRefreshToken:!0,detectSessionInUrl:!1,storageKey:"tower-console-auth"}})),s}let r="".concat(i,"/functions/v1/send-push");function d(e){return["","January","February","March","April","May","June","July","August","September","October","November","December"][e]||"".concat(e)}},8630:function(e,t,a){"use strict";a.r(t),a.d(t,{default:function(){return m}});
1var s=a(5893),n=a(7294),i=a(1523),l=a(7368);let r=0,d=()=>"b".concat(++r);function o(e){let t=[];for(let a of e.split("\n")){let e;let s=a.trim();if(s){if(e=s.match(/^LargeArticle\(\s*(\d+)\s*\)$/i))t.push({key:d(),kind:"large",ids:[Number(e[1])]});else if(e=s.match(/^Sidescroll\(\s*([\d\s,]*?)\s*\)$/i)){let a=e[1].split(",").map(e=>e.trim()).filter(Boolean).map(Number);t.push({key:d(),kind:"side",ids:a})}else/^Divider$/i.test(s)?t.push({key:d(),kind:"divider"}):(e=s.match(/^Text\(\s*"(.*)"\s*\)$/i))?t.push({key:d(),kind:"text",text:e[1]}):t.push({key:d(),kind:"raw",line:s})}}return t}function c(e){let{onPick:t,placeholder:a}=e,{supabase:r}=(0,i.A)(),[d,o]=(0,n.useState)(""),[c,u]=(0,n.useState)([]),[h,m]=(0,n.useState)(!1),p=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let e=e=>{p.current&&!p.current.contains(e.target)&&m(!1)};return document.addEventListener("mousedown",e),()=>document.removeEventListener("mousedown",e)},[]),(0,n.useEffect)(()=>{let e=setTimeout(async()=>{let e=d.trim();if(!e){u([]);return}let t=r.from("article").select("id, title, month, year, published").order("id",{ascending:!1}).limit(12);t=/^\d+$/.test(e)?t.eq("id",Number(e)):t.ilike("title","%".concat(e,"%"));let{data:a}=await t;u(null!=a?a:[]),m(!0)},220);return()=>clearTimeout(e)},[r,d]),(0,s.jsxs)("div",{className:"ta-picker",ref:p,children:[(0,s.jsx)("input",{type:"search",value:d,placeholder:null!=a?a:"Add article by title or id…",onChange:e=>o(e.target.value),onFocus:()=>c.length&&m(!0)}),h&&c.length>0&&(0,s.jsx)("div",{className:"ta-picker-results",children:c.map(e=>(0,s.jsxs)("button",{type:"button",onClick:()=>{t(e),o(""),m(!1)},children:[(0,s.jsxs)("b",{children:["#",e.id]})," ",e.title," ",(0,s.jsxs)("span",{className:"ta-muted",children:[(0,l.oz)(e.month)," ",e.year,e.published?"":" \xb7 UNPUBLISHED"]})]},e.id))})]})}function u(e){let{block:t,index:a,total:n,titles:i,duplicates:l,onChange:r,onMove:d,onDelete:o}=e,u=("large"===t.kind||"side"===t.kind)&&(0===t.ids.length||t.ids.some(e=>null===i.get(e)||l.has(e))),h=(e,t)=>{let a=i.get(e),n=null===a,r=l.has(e);return(0,s.jsxs)("span",{className:"ta-article-chip".concat(n||r?" missing":""),title:r?"Used more than once in this layout":void 0,children:[(0,s.jsxs)("b",{children:["#",e]})," ",n?"⚠ not found":a?a.title.slice(0,48):"…",r&&(0,s.jsx)("span",{className:"ta-error",children:"dup"}),(0,s.jsx)("button",{type:"button",onClick:t,"aria-label":"Remove",children:"\xd7"})]},e)};return(0,s.jsxs)("div",{className:"ta-layout-block".concat(u?" invalid":""),children:[(0,s.jsxs)("div",{className:"ta-layout-move",children:[(0,s.jsx)("button",{disabled:0===a,onClick:()=>d(a,-1),"aria-label":"Move up",children:"▲"}),(0,s.jsx)("button",{disabled:a===n-1,onClick:()=>d(a,1),"aria-label":"Move down",children:"▼"})]}),(0,s.jsxs)("div",{className:"ta-layout-body",children:["large"===t.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"ta-layout-kind",children:"Hero card"}),(0,s.jsxs)("div",{children:[t.ids.map(e=>h(e,()=>r({...t,ids:[]}))),0===t.ids.length&&(0,s.jsx)(c,{placeholder:"Pick the hero article…",onPick:e=>r({...t,ids:[e.id]})})]})]}),"side"===t.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"ta-layout-kind",children:"Sidescroll row"}),(0,s.jsx)("div",{children:t.ids.map(e=>h(e,()=>r({...t,ids:t.ids.filter(t=>t!==e)})))}),(0,s.jsx)(c,{onPick:e=>!t.ids.includes(e.id)&&r({...t,ids:[...t.ids,e.id]})})]}),"divider"===t.kind&&(0,s.jsx)("span",{className:"ta-layout-kind",children:"Divider"}),"text"===t.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"ta-layout-kind",children:"Section header"}),(0,s.jsx)("input",{type:"text",value:t.text,placeholder:"This Week at PHS",onChange:e=>r({...t,text:e.target.value}),style:{fontWeight:700,color:"#031025"}})]}),"raw"===t.kind&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"ta-layout-kind",children:t.line.startsWith("#")?"Comment":"⚠ Unrecognized line"}),(0,s.jsx)("input",{type:"text",value:t.line,onChange:e=>r({...t,line:e.target.value}),style:{fontFamily:"monospace"}})]})]}),(0,s.jsx)("button",{className:"ta-btn ta-btn-small ta-btn-ghost-danger",onClick:o,children:"Delete"})]})}function h(){let{supabase:e}
1=(0,i.A)(),[t,a]=(0,n.useState)([]),[r,c]=(0,n.useState)(null),[h,m]=(0,n.useState)([]),[p,x]=(0,n.useState)({month:new Date().getMonth()+1,year:new Date().getFullYear(),published:!1}),[b,g]=(0,n.useState)(new Map),[j,f]=(0,n.useState)("visual"),[y,v]=(0,n.useState)(""),[k,N]=(0,n.useState)(!1),[w,S]=(0,n.useState)({}),C=(0,n.useCallback)(async()=>{let{data:t,error:s}=await e.from("app_layout").select("id, layout, month, year, published").order("year",{ascending:!1}).order("month",{ascending:!1}).order("id",{ascending:!1});if(s)return S({err:s.message}),[];let n=null!=t?t:[];return a(n),n},[e]);(0,n.useEffect)(()=>{C().then(e=>{e.length&&null===r&&E(e[0])})},[C]);let I=(0,n.useMemo)(()=>{let e=t.filter(e=>e.published);return e.length?e[0].id:null},[t]),E=e=>{c(e.id),m(o(e.layout)),v(e.layout),x({month:e.month,year:e.year,published:e.published}),S({})},A=()=>{let e=new Date;c("new"),m([]),v(""),x({month:e.getMonth()+1,year:e.getFullYear(),published:!1}),S({})},_=(0,n.useMemo)(()=>h.flatMap(e=>"large"===e.kind||"side"===e.kind?e.ids:[]),[h]);(0,n.useEffect)(()=>{let t=_.filter(e=>!b.has(e));if(0===t.length)return;let a=!1;return(async()=>{let{data:s}=await e.from("article").select("id, title, month, year, published").in("id",t);a||g(e=>{let a=new Map(e);for(let e of t)a.set(e,null);for(let e of null!=s?s:[])a.set(e.id,e);return a})})(),()=>{a=!0}},[e,_,b]);let F=(0,n.useMemo)(()=>{let e=new Set,t=new Set;for(let a of _)(e.has(a)?t:e).add(a);return t},[_]),M=_.filter(e=>null===b.get(e)),P=(0,n.useMemo)(()=>h.map(e=>{switch(e.kind){case"large":var t;return"LargeArticle(".concat(null!==(t=e.ids[0])&&void 0!==t?t:"",")");case"side":return"Sidescroll(".concat(e.ids.join(", "),")");case"divider":return"Divider";case"text":return'Text("'.concat(e.text.replace(/"/g,"'"),'")');case"raw":return e.line}}).join("\n")+"\n",[h]),z=F.size>0||M.length>0||h.some(e=>("large"===e.kind||"side"===e.kind)&&0===e.ids.length),D=e=>{e!==j&&("raw"===e?v(P):m(o(y)),f(e))},T=async()=>{N(!0),S({});let t="raw"===j?y:P;try{if("new"===r){let{data:a,error:s}=await e.from("app_layout").insert({layout:t,month:p.month,year:p.year,published:p.published}).select("id, layout, month, year, published").single();if(s)throw s;await C(),E(a)}else if("number"==typeof r){let{error:a,data:s}=await e.from("app_layout").update({layout:t,month:p.month,year:p.year,published:p.published}).eq("id",r).select("id");if(a)throw a;if(!(null==s?void 0:s.length))throw Error("Save was blocked (no rows updated). Are you signed in as an editor?");await C()}S({ok:"Saved."})}catch(e){S({err:e instanceof Error?e.message:String(e)})}N(!1)},L=e=>{let t={key:d()},a="large"===e?{...t,kind:"large",ids:[]}:"side"===e?{...t,kind:"side",ids:[]}:"text"===e?{...t,kind:"text",text:""}:"raw"===e?{...t,kind:"raw",line:"# comment"}:{...t,kind:"divider"};m(e=>[...e,a])};return(0,s.jsxs)("div",{className:"ta-stack",children:[(0,s.jsxs)("div",{className:"ta-toolbar",children:[(0,s.jsxs)("select",{value:null===r?"":r,onChange:e=>{if("new"===e.target.value)A();else{let a=t.find(t=>t.id===Number(e.target.value));a&&E(a)}},style:{maxWidth:320},children:[(0,s.jsx)("option",{value:"",disabled:!0,children:"Pick a layout…"}),t.map(e=>(0,s.jsxs)("option",{value:e.id,children:[(0,l.oz)(e.month)," ",e.year," \xb7 #",e.id,e.published?" \xb7 published":"",e.id===I?" \xb7 LIVE IN APP":""]},e.id)),(0,s.jsx)("option",{value:"new",children:"+ New layout…"})]}),"number"==typeof r&&r===I&&(0,s.jsx)("span",{className:"ta-badge red",children:"LIVE IN APP"})]}),null!==r&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"ta-card ta-row",children:[(0,s.jsxs)("label",{style:{margin:0},children:["Month",(0,s.jsx)("select",{value:p.month,onChange:e=>x({...p,month:Number(e.target.value)}),children:Array.from({length:12},(e,t)=>t+1).map(e=>(0,s.jsx)("option",{value:e,children:(0,l.oz)(e)},e))})]}),(0,s.jsxs)("label",{style:{margin:0,maxWidth:110},children:["Year",(0,s.jsx)("input",{type:"number",value:p.year,onChange:e=>x({...p,year:Number(e.target.value)})})]}),(0,s.jsxs)("label",{style:{margin:0,display:"flex",alignItems:"center",gap:6},children:[(0,s.jsx)("input",{type:"checkbox",checked:p.published,onChange:e=>x({...p,published:e.target.checked}),style:{width:"auto"}}),"Published (the app shows the latest published layout)"]})]}),(0,s.jsxs)("div",{className:"ta-tabs",children:[(0,s.jsx)("button",{className:"visual"===j?"active":"",onClick:()=>D("visual"),children:"Visual editor"}),(0,s.jsx)("button",{className:"raw"===j?"active":"",onClick:()=>D("raw"),children:"Raw script"})]}
1),"visual"===j?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"ta-stack",children:[h.map((e,t)=>(0,s.jsx)(u,{block:e,index:t,total:h.length,titles:b,duplicates:F,onChange:t=>m(a=>a.map(a=>a.key===e.key?t:a)),onMove:(e,t)=>m(a=>{let s=[...a],[n]=s.splice(e,1);return s.splice(e+t,0,n),s}),onDelete:()=>m(t=>t.filter(t=>t.key!==e.key))},e.key)),0===h.length&&(0,s.jsx)("p",{className:"ta-muted",children:"Empty layout. Add blocks below."})]}),(0,s.jsxs)("div",{className:"ta-row",children:[(0,s.jsx)("button",{className:"ta-btn",onClick:()=>L("large"),children:"+ Hero card"}),(0,s.jsx)("button",{className:"ta-btn",onClick:()=>L("side"),children:"+ Sidescroll"}),(0,s.jsx)("button",{className:"ta-btn",onClick:()=>L("text"),children:"+ Section header"}),(0,s.jsx)("button",{className:"ta-btn",onClick:()=>L("divider"),children:"+ Divider"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("h3",{style:{fontSize:14,marginBottom:6},children:"Script preview"}),(0,s.jsx)("pre",{className:"ta-code",children:P||"(empty)"})]})]}):(0,s.jsx)("textarea",{rows:14,value:y,onChange:e=>v(e.target.value),style:{fontFamily:"monospace"}}),M.length>0&&(0,s.jsxs)("p",{className:"ta-error",children:["Unknown article ids: ",M.join(", "),". They don’t exist in the article table."]}),F.size>0&&(0,s.jsxs)("p",{className:"ta-error",children:["Duplicate article ids: ",Array.from(F).join(", "),". Each article may appear once."]}),(0,s.jsxs)("div",{className:"ta-row",children:[(0,s.jsx)("button",{className:"ta-btn ta-btn-primary",disabled:k||"visual"===j&&z,onClick:T,children:k?"Saving…":"new"===r?"Create layout":"Save layout"}),w.ok&&(0,s.jsx)("span",{className:"ta-ok",children:w.ok}),w.err&&(0,s.jsx)("span",{className:"ta-error",children:w.err})]})]})]})}function m(){return(0,s.jsx)(i.Z,{title:"App front-page layout",children:(0,s.jsx)(h,{})})}}},function(e){e.O(0,[3714,8764,8886,2888,9774,179],function(){return e(e.s=4935)}),_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.