PageSourceSearch

https://unonext.lovable.app/assets/RadioEpisodeClipsAdmin-C7PlDYAN.js

js unonext.lovable.app collected 2026-10-03 03:53:58 UTC 6,343 bytes, 1 lines download raw bytes

1import{p as I,r as i,z as B,s as u,j as e,B as m,L as w,o as E,q as z}from"./index-E8GC089e.js";import{A as R}from"./AdminLayout-BErrNMwU.js";import{I as H}from"./input-DhTpLcTz.js";import{T as Q,a as M,b as D,c as p,d as O,e as x}from"./table-a6DCr02E.js";import{A as U,a as V,b as G,c as J,d as K,e as W,f as X,g as Y}from"./alert-dialog-DFFxSItc.js";import{S as Z}from"./switch-CDZPAkSC.js";import{A as ee}from"./arrow-left-DzJOj3dq.js";import{S as se}from"./search-BvQ8e150.js";import{F as te}from"./film-DOZ1kZBM.js";import{C as re}from"./clock-Ba8TaFVn.js";import{E as ae}from"./eye-B6FS_5kD.js";import{P as ie}from"./pencil-C1nVhhAU.js";import{T as le}from"./trash-2-B20fRP6U.js";import"./useAdminCheck-DFpuRJtu.js";import"./shield-Bfniijzz.js";import"./log-out-Bf4bExwP.js";import"./chevron-right-BMbcmEuR.js";import"./square-play-BEwkEIEP.js";import"./megaphone-BtcBptgP.js";import"./index-B2N46YtK.js";import"./Combination-D6m90wMP.js";function Ae(){var S;const{showId:o,episodeId:d}=I(),[A,f]=i.useState([]),[a,T]=i.useState(null),[_,C]=i.useState(!0),[n,$]=i.useState(""),[c,g]=i.useState(null),[j,N]=i.useState(!1),[k,v]=i.useState(null),{toast:l}=B();i.useEffect(()=>{d&&L()},[d]);const L=async()=>{C(!0);try{const[{data:s,error:t},{data:r,error:h}]=await Promise.all([u.from("radio_episodes").select("id, title, slug, show_id, show:radio_shows(id, title, slug)").eq("id",d).single(),u.from("radio_clips").select("id, title, slug, duration_seconds, status, clip_date, created_at").eq("episode_id",d).order("created_at",{ascending:!1})]);if(t)throw t;if(h)throw h;T(s),f(r||[])}catch(s){console.error("Error fetching data:",s),l({title:"Error",description:"Failed to load data",variant:"destructive"})}finally{C(!1)}},P=async()=>{if(c){N(!0);try{const{error:s}=await u.from("radio_clips").delete().eq("id",c);if(s)throw s;f(t=>t.filter(r=>r.id!==c)),l({title:"Success",description:"Clip deleted successfully"})}catch(s){console.error("Error deleting clip:",s),l({title:"Error",description:"Failed to delete clip",variant:"destructive"})}finally{N(!1),g(null)}}},F=async s=>{v(s.id);const t=s.status==="published"?"draft":"published";try{const{error:r}=await u.from("radio_clips").update({status:t}).eq("id",s.id);if(r)throw r;f(h=>h.map(b=>b.id===s.id?{...b,status:t}:b)),l({title:"Success",description:`Clip ${t==="published"?"published":"unpublished"}`})}catch(r){console.error("Error toggling publish:",r),l({title:"Error",description:"Failed to update clip status",variant:"destructive"})}finally{v(null)}},q=s=>{const t=Math.floor(s/60),r=s%60;return`${t}:${r.toString().padStart(2,"0")}`},y=A.filter(s=>{if(!n)return!0;const t=n.toLowerCase();return s.title.toLowerCase().includes(t)||s.slug.toLowerCase().includes(t)});return e.jsxs(R,{title:a?`Clips: ${a.title}`:"Episode Clips",breadcrumbs:[{label:"Radio"},{label:"Shows",href:"/admin/radio/shows"},{label:((S=a==null?void 0:a.show)==null?void 0:S.title)||"Show",href:`/admin/radio/shows/${o}/episodes`},{label:"Episodes",href:`/admin/radio/shows/${o}/episodes`},{label:(a==null?void 0:a.title)||"Episode"},{label:"Clips"}],children:[e.jsx("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:e.jsx(m,{variant:"outline",asChild:!0,className:"w-fit",children:e.jsxs(w,{to:`/admin/radio/shows/${o}/episodes`,children:[e.jsx(ee,{className:"h-4 w-4 mr-2"}),"Back to Episodes"]})})}),e.jsx("div",{className:"flex flex-col sm:flex-row gap-4 mb-6",children:e.jsxs("div",{className:"relative flex-1 max-w-sm",children:[e.jsx(se,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(H,{placeholder:"Search clips...",value:n,onChange:s=>$(s.target.value),className:"pl-10"})]})}),_?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(E,{className:"h-8 w-8 animate-spin text-primary"})}):y.length===0?e.jsxs("div",{className:"text-center py-12 bg-card rounded-xl border border-border/30",children:[e.jsx(te,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("h3",{className:"text-lg font-semibold mb-2",children:"No clips found"}),e.jsx("p",{className:"text-muted-foreground mb-4",children:n?"Try a different search term":"No clips linked to this episode yet"})]}):e.jsx("div",{className:"bg-card rounded-xl border border-border/30 overflow-hidden",children:e.jsxs(Q,{children:[e.jsx(M,{children:e.jsxs(D,{children:[e.jsx(p,{children:"Clip"}),e.jsx(p,{children:"Duration"}),e.jsx(p,{children:"Status"}),e.jsx(p,{className:"text-right",children:"Actions"})]})}),e.jsx(O,{children:y.map(s=>e.jsxs(D,{children:[e.jsx(x,{children:e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:s.title}),e.jsx("p",{className:"text-sm text-muted-foreground",children:s.slug})]})}),e.jsx(x,{children:s.duration_seconds?e.jsxs("span",{className:"flex items-center gap-1 text-sm",children:[e.jsx(re,{className:"h-3 w-3"}),q(s.duration_seconds)]}):e.jsx("span",{className:"text-muted-foreground",children:"—"})}),e.jsx(x,{children:e.jsx(z,{variant:s.status==="published"?"default":"secondary",children:s.status||"draft"})}),e.jsx(x,{className:"text-right",children:e.jsxs("div",{className:"flex items-center justify-end gap-1",children:[e.jsx(m,{variant:"ghost",size:"icon",asChild:!0,title:"View",children:e.jsx(w,{to:`/radio/clips/${s.slug}`,target:"_blank",children:e.jsx(ae,{className:"h-4 w-4"})})}),e.jsx(m,{variant:"ghost",size:"icon",asChild:!0,title:"Edit",children:e.jsx(w,{to:`/admin/radio/shows/${o}/clips/${s.id}/edit`,children:e.jsx(ie,{className:"h-4 w-4"})})}),e.jsx(Z,{checked:s.status==="published",onCheckedChange:()=>F(s),disabled:k===s.id,title:s.status==="published"?"Unpublish":"Publish"}),e.jsx(m,{variant:"ghost",size:"icon",onClick:()=>g(s.id),children:e.jsx(le,{className:"h-4 w-4 text-destructive"})})]})})]},s.id))})]})}),e.jsx(U,{open:!!c,onOpenChange:()=>g(null),children:e.jsxs(V,{children:[e.jsxs(G,{children:[e.jsx(J,{children:"Delete Clip?"}),e.jsx(K,{children:"This will permanently delete this clip. This action cannot be undone."})]}),e.jsxs(W,{children:[e.jsx(X,{disabled:j,children:"Cancel"}),e.jsx(Y,{onClick:P,disabled:j,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:j?e.jsxs(e.Fragment,{children:[e.jsx(E,{className:"h-4 w-4 animate-spin mr-2"}),"Deleting..."]}):"Delete"})]})]})})]})}export{Ae as default};

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.