PIMS/public/build/assets/Show-DeHiSsqs.js

2 lines
6.3 KiB
JavaScript

import{d as A,n as B,c as I,r,e as E,p as G,a as o,f as w,u as z,h as D,w as M,b as e,i as u,o as l,t as i,q as N,v as O,s as X,F as g,g as j,l as k,T as Y}from"./app-BXYcVHqk.js";import{_ as Z}from"./AppLayout.vue_vue_type_script_setup_true_lang-86gE95Fg.js";import{_ as H}from"./_plugin-vue_export-helper-DlAUqK2U.js";import"./AppLogoIcon.vue_vue_type_script_setup_true_lang-BzXwPo6R.js";import"./useForwardExpose-Djbxsgaa.js";import"./VisuallyHidden-BvthYHr5.js";import"./RovingFocusGroup-dmigQ6Dy.js";import"./useArrowNavigation-C6Y-ieo6.js";import"./index-C4J_hXM0.js";import"./createLucideIcon-BlA39rtn.js";const W={class:"flex h-full flex-1 flex-col gap-4 overflow-x-auto rounded-xl p-4"},J={key:0,class:"flex items-center gap-3"},K={class:"flex items-center gap-3"},Q={class:"min-w-0 flex-1"},ee={class:"truncate text-lg font-semibold"},te={class:"flex items-center gap-2"},se={key:1,class:"rounded-md border border-red-300 bg-red-50 p-3 text-red-800 dark:border-red-800 dark:bg-red-950 dark:text-red-200"},ae=["aria-busy"],oe=["href"],le={class:"h-20 w-14 shrink-0 overflow-hidden rounded bg-muted"},re=["src","alt"],ne={class:"flex min-w-0 flex-1 flex-col"},ue={class:"flex items-center justify-between gap-2"},ie={class:"truncate font-medium"},de={class:"text-xs text-muted-foreground"},ce={class:"mt-1 text-xs text-muted-foreground"},ve={key:0,class:"mr-2 rounded border px-1 py-0.5"},fe={key:1},pe={class:"mt-2 text-sm text-foreground/90"},me={key:0,class:"fixed bottom-4 left-1/2 z-50 -translate-x-1/2 rounded bg-foreground px-3 py-2 text-sm text-background shadow-lg"},ge=A({__name:"Show",setup(he){const C=B(),T=I(()=>C.props.entityId),d=r(""),c=r("title_asc"),v=r([]),L=r(0),P=r(1),h=r(1),n=r(!1),_=r(null),b=r(!1),S=r(""),p=r(null);let $=null;const q=I(()=>h.value<P.value&&!n.value);function U(a,t=50){if(!a)return"";const s=a.split(/\s+/);return s.length<=t?a:s.slice(0,t).join(" ")+"…"}async function x(a=!1){if(!n.value){n.value=!0,_.value=null;try{const t=new URLSearchParams;d.value&&t.set("q",d.value),c.value&&t.set("sort",c.value),t.set("per_page","20"),t.set("page",String(h.value));const s=await fetch(`/api/genres/${T.value}?${t.toString()}`,{headers:{Accept:"application/json","X-Requested-With":"XMLHttpRequest"},credentials:"same-origin"});if(!s.ok)throw new Error(`Fetch failed: ${s.status}`);const f=await s.json();p.value=f.entity,L.value=f.movies.total,P.value=f.movies.last_page,a?v.value=f.movies.data:v.value=v.value.concat(f.movies.data)}catch(t){_.value=t?.message??"Unexpected error",S.value=_.value,b.value=!0,setTimeout(()=>b.value=!1,2500)}finally{n.value=!1}}}function V(){clearTimeout($),$=setTimeout(()=>{h.value=1,x(!0)},300)}function F(){const a=new URL(window.location.href);d.value?a.searchParams.set("q",d.value):a.searchParams.delete("q"),c.value?a.searchParams.set("sort",c.value):a.searchParams.delete("sort"),window.history.replaceState({},"",a.toString()),h.value=1,x(!0)}async function R(){q.value&&(h.value+=1,await x(!1))}const y=r(null);let m=null;return E(()=>{const a=new URL(window.location.href);d.value=a.searchParams.get("q")??"",c.value=a.searchParams.get("sort")??"title_asc",x(!0),m=new IntersectionObserver(t=>{for(const s of t)s.isIntersecting&&R()},{root:null,rootMargin:"200px",threshold:0}),y.value&&m.observe(y.value)}),G(y,(a,t)=>{t&&m&&m.unobserve(t),a&&m&&m.observe(a)}),(a,t)=>(l(),o(g,null,[w(z(D),{title:p.value?.name?`${p.value.name} · Genre`:"Genre"},null,8,["title"]),w(Z,{breadcrumbs:[{title:"Genres",href:"/genres"},{title:p.value?.name??"…",href:`/genres/${T.value}`}]},{default:M(()=>[e("div",W,[!p.value&&n.value?(l(),o("div",J,[...t[2]||(t[2]=[e("div",{class:"h-12 w-12 shrink-0 rounded bg-muted animate-pulse"},null,-1),e("div",{class:"h-4 w-40 rounded bg-muted animate-pulse"},null,-1)])])):u("",!0),e("div",K,[t[3]||(t[3]=e("div",{class:"h-12 w-12 shrink-0 rounded bg-muted"},null,-1)),e("div",Q,[e("h1",ee,i(p.value?.name??"…"),1)])]),e("div",te,[N(e("input",{class:"w-full rounded-md border border-gray-300 bg-background px-3 py-2 text-sm outline-none focus:ring-2 focus:ring-primary",type:"text",placeholder:"Filter movies by title…","aria-label":"Filter movies by title","onUpdate:modelValue":t[0]||(t[0]=s=>d.value=s),onInput:V},null,544),[[O,d.value]]),N(e("select",{"onUpdate:modelValue":t[1]||(t[1]=s=>c.value=s),onChange:F,class:"w-44 shrink-0 rounded-md border px-3 py-2 text-sm","aria-label":"Sort movies"},[...t[4]||(t[4]=[e("option",{value:"title_asc"},"Title A → Z",-1),e("option",{value:"title_desc"},"Title Z → A",-1),e("option",{value:"newest"},"Newest",-1),e("option",{value:"oldest"},"Oldest",-1),e("option",{value:"year_asc"},"Year ↑",-1),e("option",{value:"year_desc"},"Year ↓",-1)])],544),[[X,c.value]])]),_.value?(l(),o("div",se,i(_.value),1)):u("",!0),e("ul",{class:"divide-y divide-muted-foreground/20","aria-busy":n.value?"true":"false"},[(l(!0),o(g,null,j(v.value,s=>(l(),o("li",{key:s.id,class:"py-1"},[e("a",{href:`/movies/${s.id}`,class:"flex gap-3 rounded px-2 py-2 hover:bg-muted/40 focus:bg-muted/40 focus:outline-none"},[e("div",le,[s.poster_url?(l(),o("img",{key:0,src:s.poster_url,alt:`Poster for ${s.title}`,loading:"lazy",class:"h-full w-full object-cover"},null,8,re)):u("",!0)]),e("div",ne,[e("div",ue,[e("div",ie,i(s.title),1),e("div",de,i(s.year??""),1)]),e("div",ce,[s.rating?(l(),o("span",ve,i(s.rating),1)):u("",!0),s.genres?.length?(l(),o("span",fe,i(s.genres.map(f=>f.name).join(", ")),1)):u("",!0)]),e("div",pe,i(U(s.description)),1)])],8,oe)]))),128)),n.value&&v.value.length===0?(l(),o(g,{key:0},j(5,s=>e("li",{key:`s-${s}`,class:"py-1"},[...t[5]||(t[5]=[e("div",{class:"flex gap-3 rounded px-2 py-2"},[e("div",{class:"h-20 w-14 shrink-0 overflow-hidden rounded bg-muted animate-pulse"}),e("div",{class:"flex min-w-0 flex-1 flex-col gap-2"},[e("div",{class:"h-4 w-1/3 rounded bg-muted animate-pulse"}),e("div",{class:"h-3 w-1/2 rounded bg-muted animate-pulse"}),e("div",{class:"h-3 w-2/3 rounded bg-muted animate-pulse"})])],-1)])])),64)):u("",!0)],8,ae),e("div",{ref_key:"sentinel",ref:y,class:"py-6 text-center text-sm text-muted-foreground"},[n.value?(l(),o(g,{key:0},[k("Loading…")],64)):!q.value&&v.value.length>0?(l(),o(g,{key:1},[k("End of results")],64)):!v.value.length&&!n.value?(l(),o(g,{key:2},[k("No results")],64)):u("",!0)],512),w(Y,{name:"fade"},{default:M(()=>[b.value?(l(),o("div",me,i(S.value),1)):u("",!0)]),_:1})])]),_:1},8,["breadcrumbs"])],64))}}),qe=H(ge,[["__scopeId","data-v-2ee2f925"]]);export{qe as default};