PageSourceSearch

https://tabiracademy.com/assets/AdminSharedSections-BDmWJW1e.js

js tabiracademy.com collected 2026-10-09 22:04:47 UTC 8,356 bytes, 1 lines download raw bytes

1import{u as ne,Y as le,t as i,j as e,B as r,A as ce,m as de}from"./index-DGkCV18M.js";import{r as a,w as oe,Z as B,ao as me,v as p,ay as he,X as ue,q as xe,bb as U,ae as pe,bc as ge,J as je,bd as ve}from"./icons-B5hbgZbc.js";import{I as g}from"./input-Djs9V4hI.js";import{C as P,d as F}from"./card-CccqfwSN.js";import{B as fe}from"./badge-DqPzbhq4.js";import{T as Ne}from"./textarea-D_PtYdnP.js";import{g as Se,c as we,d as Ce,u as q,a as j,l as ye,b as ke}from"./sharedSectionsApi-BO_DgOHt.js";import{D as O,b as V,c as H,d as J,f as be}from"./dialog-DK2wDU8s.js";import{S as De,a as Le,b as Ee,c as Te,d as ze}from"./select-xLVyleAn.js";import"./index-pMG5Nshn.js";import"./index-CmvZa3SB.js";const Je=()=>{const R=ne(),[v,X]=a.useState([]),[f,Y]=a.useState([]),[Z,N]=a.useState(!0),[$,d]=a.useState(!1),[o,S]=a.useState(""),[w,C]=a.useState(""),[y,k]=a.useState(!1),[b,u]=a.useState(null),[D,L]=a.useState(""),[E,T]=a.useState(""),[l,z]=a.useState(null),[m,x]=a.useState([]),[h,_]=a.useState(""),[G,I]=a.useState(!1);a.useEffect(()=>{c()},[]);const c=async()=>{N(!0);try{const[s,t]=await Promise.all([Se(),le()]);X(s),Y(t)}catch(s){i({title:"Error",description:s.message,variant:"destructive"})}finally{N(!1)}},K=async()=>{if(o.trim()){k(!0);try{await we(o.trim(),w.trim()||void 0),d(!1),S(""),C(""),await c(),i({title:"Created",description:"Shared section created successfully"})}catch(s){i({title:"Error",description:s.message,variant:"destructive"})}finally{k(!1)}}},M=async s=>{if(confirm("Delete this shared section? It will be unlinked from all courses."))try{await Ce(s),await c(),i({title:"Deleted"})}catch(t){i({title:"Error",description:t.message,variant:"destructive"})}},Q=async s=>{const t=s.status==="active"?"draft":"active";try{await q(s.id,{status:t}),await c(),i({title:t==="active"?"Activated":"Deactivated"})}catch(n){i({title:"Error",description:n.message,variant:"destructive"})}},W=async s=>{try{await q(s,{title:D.trim(),description:E.trim()||null}),u(null),await c(),i({title:"Saved"})}catch(t){i({title:"Error",description:t.message,variant:"destructive"})}},ee=async s=>{z(s),I(!0);try{const t=await j(s);x(t)}catch(t){i({title:"Error",description:t.message,variant:"destructive"})}finally{I(!1)}},se=async()=>{if(!(!l||!h))try{await ye(l,parseInt(h));const s=await j(l);x(s),_(""),i({title:"Linked"})}catch(s){i({title:"Error",description:s.message,variant:"destructive"})}},te=async s=>{if(l)try{await ke(l,s);const t=await j(l);x(t),i({title:"Unlinked"})}catch(t){i({title:"Error",description:t.message,variant:"destructive"})}},ae=s=>{var t;return((t=f.find(n=>n.course_id===s))==null?void 0:t.course_name)||`Course #${s}`},ie=new Set(m.map(s=>s.course_id)),A=f.filter(s=>!ie.has(s.course_id)),re=s=>{var t,n;return((n=(t=s.section_data)==null?void 0:t.topics)==null?void 0:n.length)||0};return e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("div",{className:"border-b border-border/50 bg-card/80 backdrop-blur-sm sticky top-0 z-20",children:e.jsxs("div",{className:"max-w-6xl mx-auto px-4 py-3 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>R("/admin"),className:"gap-1.5",children:[e.jsx(oe,{className:"w-4 h-4"}),"Admin"]}),e.jsx("div",{className:"h-5 w-px bg-border"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(B,{className:"w-5 h-5 text-primary"}),e.jsx("h1",{className:"text-lg font-bold text-foreground",children:"Shared Sections"})]})]}),e.jsxs(r,{onClick:()=>d(!0),size:"sm",className:"gap-1.5",children:[e.jsx(me,{className:"w-4 h-4"}),"New Section"]})]})}),e.jsx("div",{className:"max-w-6xl mx-auto px-4 py-6 space-y-4",children:Z?e.jsx("div",{className:"flex justify-center py-16",children:e.jsx(p,{className:"w-8 h-8 animate-spin text-muted-foreground"})}):v.length===0?e.jsx(P,{children:e.jsxs(F,{className:"py-16 text-center",children:[e.jsx(B,{className:"w-12 h-12 mx-auto text-muted-foreground/30 mb-4"}),e.jsx("p",{className:"text-muted-foreground",children:"No shared sections yet. Create one to get started."})]})}):e.jsx(ce,{children:v.map((s,t)=>e.jsx(de.div,{initial:{opacity:0,y:10}
1,animate:{opacity:1,y:0},transition:{delay:t*.05},children:e.jsx(P,{className:"transition-all hover:shadow-md",children:e.jsx(F,{className:"p-4",children:e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("div",{className:"flex-1 min-w-0",children:b===s.id?e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{value:D,onChange:n=>L(n.target.value),placeholder:"Section title"}),e.jsx(g,{value:E,onChange:n=>T(n.target.value),placeholder:"Description (optional)"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(r,{size:"sm",onClick:()=>W(s.id),className:"gap-1",children:[e.jsx(he,{className:"w-3.5 h-3.5"}),"Save"]}),e.jsx(r,{size:"sm",variant:"ghost",onClick:()=>u(null),children:e.jsx(ue,{className:"w-3.5 h-3.5"})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx("h3",{className:"font-semibold text-foreground truncate",children:s.title}),e.jsx(fe,{variant:s.status==="active"?"default":"secondary",children:s.status})]}),s.description&&e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:s.description}),e.jsxs("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"flex items-center gap-1",children:[e.jsx(xe,{className:"w-3 h-3"}),re(s)," topics"]}),e.jsxs("span",{children:["Updated ",new Date(s.updated_at).toLocaleDateString()]})]})]})}),b!==s.id&&e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>ee(s.id),className:"gap-1",children:[e.jsx(U,{className:"w-3.5 h-3.5"}),"Link"]}),e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>Q(s),className:"gap-1",children:[e.jsx(pe,{className:"w-3.5 h-3.5"}),s.status==="active"?"Deactivate":"Activate"]}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>{u(s.id),L(s.title),T(s.description||"")},children:e.jsx(ge,{className:"w-3.5 h-3.5"})}),e.jsx(r,{variant:"ghost",size:"sm",onClick:()=>M(s.id),className:"text-destructive hover:text-destructive",children:e.jsx(je,{className:"w-3.5 h-3.5"})})]})]})})})},s.id))})}),e.jsx(O,{open:$,onOpenChange:d,children:e.jsxs(V,{children:[e.jsx(H,{children:e.jsx(J,{children:"Create Shared Section"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(g,{placeholder:"Section title (e.g., Current Affairs 2025)",value:o,onChange:s=>S(s.target.value)}),e.jsx(Ne,{placeholder:"Description (optional)",value:w,onChange:s=>C(s.target.value),rows:3})]}),e.jsxs(be,{children:[e.jsx(r,{variant:"outline",onClick:()=>d(!1),children:"Cancel"}),e.jsxs(r,{onClick:K,disabled:!o.trim()||y,children:[y&&e.jsx(p,{className:"w-4 h-4 animate-spin mr-1.5"}),"Create"]})]})]})}),e.jsx(O,{open:!!l,onOpenChange:s=>!s&&z(null),children:e.jsxs(V,{className:"max-w-lg",children:[e.jsx(H,{children:e.jsx(J,{children:"Link to Courses"})}),G?e.jsx("div",{className:"flex justify-center py-8",children:e.jsx(p,{className:"w-6 h-6 animate-spin text-muted-foreground"})}):e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsxs("p",{className:"text-sm font-medium text-foreground mb-2",children:["Linked Courses (",m.length,")"]}),m.length===0?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Not linked to any courses yet."}):e.jsx("div",{className:"space-y-2",children:m.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2 rounded-lg bg-muted/50 border border-border/50",children:[e.jsx("span",{className:"text-sm font-medium truncate",children:ae(s.course_id)}),e.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>te(s.course_id),className:"text-destructive hover:text-destructive gap-1",children:[e.jsx(ve,{className:"w-3.5 h-3.5"}),"Unlink"]})]},s.id))})]}),A.length>0&&e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(De,{value:h,onValueChange:_,children:[e.jsx(Le,{className:"flex-1",children:e.jsx(Ee,{placeholder:"Select a course..."})}),e.jsx(Te,{children:A.map(s=>e.jsx(ze,{value:String(s.course_id),children:s.course_name},s.course_id))})]}),e.jsxs(r,{onClick:se,disabled:!h,size:"sm",className:"gap-1",children:[e.jsx(U,{className:"w-3.5 h-3.5"}),"Link"]})]})]})]})})]})};export{Je 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.