PageSourceSearch

https://loveacrossborders.com/assets/books.admin-bWazOzi-.js

js loveacrossborders.com collected 2026-10-08 14:16:46 UTC 7,141 bytes, 1 lines download raw bytes

1import{h as v,r as y,s as N,j as e,L as x,o as w,t as h,u as A}from"./index-hs4a0mYW.js";import{u as F}from"./useQuery-C-iGd3mh.js";import{u as S}from"./useMutation-CsVV5qgy.js";import{u as p}from"./useServerFn-DgMZqDJQ.js";import{l as I,d as P,b as T,a as C}from"./books.functions-BjM2fbuH.js";import{e as d,N as t,b as g,C as b,I as D,a as _,G as j,h as $,d as f,k,R as E}from"./brand-BVAz6htY.js";import{A as z}from"./arrow-left-bJxZenjV.js";import{P as B}from"./plus-BzpCviRC.js";import{F as K}from"./feather-G0ov8X3n.js";import{U as L}from"./upload-hM-7dRRF.js";import{T as q}from"./trash-2-Bg71gBw1.js";const R=[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}],["path",{d:"m15 5 4 4",key:"1mk7zo"}]],M=v("pencil",R);function te(){const[n,o]=y.useState(!1),[c,a]=y.useState(!1);return y.useEffect(()=>{let r=!0;N.auth.getUser().then(({data:i})=>{r&&(a(!!i.user),o(!0))});const{data:m}=N.auth.onAuthStateChange((i,l)=>{a(!!l?.user),o(!0)});return()=>{r=!1,m.subscription.unsubscribe()}},[]),n?c?e.jsx(Y,{}):e.jsxs(u,{children:[e.jsx("p",{style:{fontFamily:"'Playfair Display', serif",fontSize:24,color:t},className:"mb-4",children:"Sign in required"}),e.jsx("p",{className:"mb-6",style:{color:`${g}`},children:"The admin area requires an account. Sign in or create one, then come back here."}),e.jsx(x,{to:"/auth",search:{mode:"signin",redirect:"/books/admin"},className:"inline-flex items-center px-6 py-3 text-sm",style:{background:t,color:b,letterSpacing:"0.04em",textTransform:"uppercase"},children:"Sign in or sign up"})]}):e.jsx(u,{children:e.jsx("p",{style:{color:`${d}`},children:"Checking..."})})}function u({children:n}){return e.jsxs("div",{className:"min-h-screen",style:{background:b,color:D,fontFamily:"'Inter', sans-serif"},children:[e.jsx("header",{style:{borderBottom:`1px solid ${_}`},children:e.jsxs("div",{className:"mx-auto max-w-5xl px-8 py-5 flex items-center justify-between",children:[e.jsxs(x,{to:"/books",className:"inline-flex items-center gap-2 text-sm",style:{color:t},children:[e.jsx(z,{className:"h-4 w-4","aria-hidden":!0})," Library"]}),e.jsx("span",{style:{fontFamily:"'Playfair Display', serif",color:t},children:"Talkable Books · Admin"})]})}),e.jsx("main",{className:"mx-auto max-w-5xl px-8 py-16",children:n})]})}function Y(){const n=p(C),o=p(T),c=w(),{data:a,isLoading:r,refetch:m}=F({queryKey:["admin-status"],queryFn:()=>n()}),i=S({mutationFn:()=>o(),onSuccess:()=>{h.success("You are now the admin."),m()},onError:l=>h.error(l.message)});return r||!a?e.jsx(u,{children:e.jsx("p",{style:{color:`${d}`},children:"Loading admin state..."})}):a.isAdmin?e.jsx(Q,{onChange:()=>c.invalidateQueries({queryKey:["books"]})}):e.jsx(u,{children:a.adminExists?e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{fontFamily:"'Playfair Display', serif",fontSize:24,color:t},className:"mb-4",children:"Not authorized"}),e.jsx("p",{style:{color:`${g}`},children:"An administrator already exists. Ask them to grant your account the admin role."}),e.jsxs("p",{className:"mt-4 text-xs",style:{color:`${$}`,fontFamily:"monospace"},children:["Your user id: ",a.userId]})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{style:{fontFamily:"'Playfair Display', serif",fontSize:24,color:t},className:"mb-4",children:"Become the first administrator"}),e.jsx("p",{className:"mb-6 max-w-2xl",style:{color:`${g}`},children:"No admin exists yet. The first signed-in user can claim the admin role. After that, only existing admins can grant the role to others."}),e.jsx("button",{onClick:()=>i.mutate(),disabled:i.isPending,className:"inline-flex items-center gap-2 px-6 py-3 text-sm",style:{background:j,color:t,letterSpacing:"0.04em",textTransform:"uppercase"},children:i.isPending?"Claiming...":"Claim admin role"})]})})}function Q({onChange:n}){const o=p(I),c=p(P),a=A(),{data:r,refetch:m,isFetching:i}=F({queryKey:["books","admin"],queryFn:()=>o()}),l=S({mutationFn:s=>c({data:{id:s}}),onSuccess:()=>{h.success("Book deleted."),m(),n()},onError:s=>h.error(s.message)});return e.jsxs(u,{children:[e.jsxs("div",{className:"flex items-baseline justify-between mb-10",children:[e.jsxs("div",{children:[e.jsx("h1",{style:{fontFamily:"'Playfair Display', serif",color:t,fontSize:36,fontWeight:500},children:"The library"}),e.jsx("p",{className:"mt-2 text-sm",style:{color:`${d}`},children:"Manage editions, ingest manuscripts, and remove volumes."})]}),e.jsxs(x,{to:"/books/admin/new",className:"inline-flex items-center gap-2 px-5 py-3 text-sm",style:{background:t,color:b,letterSpacing:"0.04em",textTransform:"uppercase"},children:[e.jsx(B,{className:"h-4 w-4","aria-hidden":!0})," New book"]})]}),!r||r.length===0?e.jsxs("div",{className:"p-10 text-center",style:{background:"#FBF8F1",border:`1px solid ${f}`},children:[e.jsx(K,{className:"h-7 w-7 mx-auto mb-4",style:{color:j},"aria-hidden":!0}),e.jsx("p",{style:{fontFamily:"'Playfair Display', serif",color:t,fontSize:20},children:"The library is empty"}),e.jsx("p",{className:"mt-2 text-sm",style:{color:`${d}`},children:"Add your first book to begin."})]}):e.jsx("ul",{className:"divide-y",style:{borderTop:`1px solid ${f}`,borderBottom:`1px solid ${f}`},children:r.map(s=>e.jsxs("li",{className:"py-5 flex items-center justify-between gap-6",children:[e.jsxs("div",{className:"flex items-center gap-5 min-w-0",children:[e.jsx("div",{className:"w-12 h-16 flex-shrink-0",style:{background:s.
1cover_url?`center/cover no-repeat url(${s.cover_url})`:"linear-gradient(160deg, #14264a 0%, #0F1E3D 100%)"},"aria-hidden":!0}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"truncate",style:{fontFamily:"'Playfair Display', serif",color:t,fontSize:18},children:s.title}),e.jsxs("p",{className:"truncate text-sm",style:{color:`${d}`},children:[s.author," · ",s.chunk_count," ",s.chunk_count===1?"chunk":"chunks"]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{onClick:()=>a({to:"/books/admin/$bookId/ingest",params:{bookId:s.id}}),className:"inline-flex items-center gap-1.5 px-4 py-2 text-xs",style:{background:j,color:t,letterSpacing:"0.06em",textTransform:"uppercase"},children:[e.jsx(L,{className:"h-3.5 w-3.5","aria-hidden":!0})," Ingest"]}),e.jsxs("button",{onClick:()=>a({to:"/books/admin/$bookId/edit",params:{bookId:s.id}}),className:"inline-flex items-center gap-1.5 px-3 py-2 text-xs",style:{border:`1px solid ${k}`,color:t,letterSpacing:"0.06em",textTransform:"uppercase"},title:"Edit",children:[e.jsx(M,{className:"h-3.5 w-3.5","aria-hidden":!0})," Edit"]}),e.jsx(x,{to:"/books/$bookId",params:{bookId:s.id},className:"px-4 py-2 text-xs",style:{border:`1px solid ${k}`,color:t,letterSpacing:"0.06em",textTransform:"uppercase"},children:"Open"}),e.jsx("button",{onClick:()=>{confirm(`Delete "${s.title}"? This removes all of its chunks.`)&&l.mutate(s.id)},disabled:l.isPending,className:"p-2",style:{color:E},title:"Delete",children:e.jsx(q,{className:"h-4 w-4","aria-hidden":!0})})]})]},s.id))}),i&&e.jsx("p",{className:"mt-4 text-xs",style:{color:`${$}`},children:"Refreshing..."})]})}export{te as component};

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.