PageSourceSearch

https://kursusviser.netlify.app/assets/AdminLessons-DKMRaAUF.js

js kursusviser.netlify.app collected 2026-10-03 10:59:09 UTC 5,269 bytes, 1 lines download raw bytes

1import{n as H,r as l,j as e,B as o,X as S,s as d,q as v}from"./index-CYaLOqHf.js";import{u as N}from"./useQuery-0Ne2QPak.js";import{u as f,P as O,C as k,D as X,a as $,b as J,G as U,c as W,T as Y}from"./dnd.esm-DWn8KUaa.js";import{I as p}from"./input-Cv5Sfuvi.js";import{S as q,a as F,b as _,c as I,d as D}from"./select-Cv9m5I8u.js";import{f as Z}from"./format-DB-hwOoU.js";import"./tiny-invariant-BaFNuDhB.js";import"./Combination-D6rwZS1a.js";function L(i){const t=i.split(":");return t.length===2?parseInt(t[0])*60+parseInt(t[1]):0}function z(i){return Z(i)}function ie(){const i=H(),[t,P]=l.useState(null),[E,C]=l.useState(null),[V,g]=l.useState(null),[c,j]=l.useState({name:"",duration:""}),[A,b]=l.useState(!1),[u,w]=l.useState({name:"",duration:""}),{data:K=[]}=N({queryKey:["admin-all-courses"],queryFn:async()=>{const{data:s,error:a}=await d.from("courses").select("id, name").order("name");if(a)throw a;return s}}),{data:M=[]}=N({queryKey:["admin-modules-for-course",t],queryFn:async()=>{if(!t)return[];const{data:s,error:a}=await d.from("modules").select("id, name, course_id").eq("course_id",t).order("sort_order");if(a)throw a;return s},enabled:!!t}),n=E||null,{data:m=[]}=N({queryKey:["admin-lessons",n],queryFn:async()=>{if(!n)return[];const{data:s,error:a}=await d.from("lessons").select("*").eq("module_id",n).order("sort_order");if(a)throw a;return s},enabled:!!n}),h=()=>{i.invalidateQueries({queryKey:["admin-lessons"]}),i.invalidateQueries({queryKey:["lessons"]})},Q=f({mutationFn:async s=>{for(let a=0;a<s.length;a++)await d.from("lessons").update({sort_order:a+1}).eq("id",s[a].id)},onSuccess:h}),T=f({mutationFn:async s=>{const a=m.length>0?Math.max(...m.map(x=>x.sort_order)):0,{error:r}=await d.from("lessons").insert({name:s.name,duration_seconds:L(s.duration),module_id:n,sort_order:a+1});if(r)throw r},onSuccess:()=>{h(),b(!1),w({name:"",duration:""}),v.success("Lektion oprettet")}}),R=f({mutationFn:async({id:s,...a})=>{const{error:r}=await d.from("lessons").update({name:a.name,duration_seconds:L(a.duration)}).eq("id",s);if(r)throw r},onSuccess:()=>{h(),g(null),v.success("Lektion opdateret")}}),B=f({mutationFn:async s=>{const{error:a}=await d.from("lessons").delete().eq("id",s);if(a)throw a},onSuccess:()=>{h(),v.success("Lektion slettet")}}),G=s=>{if(!s.destination)return;const a=Array.from(m),[r]=a.splice(s.source.index,1);a.splice(s.destination.index,0,r),Q.mutate(a)};return e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-4",children:[e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Lektioner"}),e.jsxs(o,{size:"sm",onClick:()=>b(!0),disabled:!n,children:[e.jsx(O,{className:"h-4 w-4 mr-1"})," Tilføj"]})]}),e.jsxs("div",{className:"flex items-center gap-3 mb-6",children:[e.jsxs(q,{value:t??"",onValueChange:s=>{P(s),C(null)},children:[e.jsx(F,{className:"w-64",children:e.jsx(_,{placeholder:"Vælg kursus"})}),e.jsx(I,{children:K.map(s=>e.jsx(D,{value:s.id,children:s.name},s.id))})]}),e.jsxs(q,{value:n??"",onValueChange:C,disabled:!t,children:[e.jsx(F,{className:"w-64",children:e.jsx(_,{placeholder:"Vælg modul"})}),e.jsx(I,{children:M.map(s=>e.jsx(D,{value:s.id,children:s.name},s.id))})]})]}),A&&e.jsxs("div",{className:"flex items-center gap-2 mb-4 p-3 border border-border rounded-lg bg-card",children:[e.jsx(p,{placeholder:"Lektionsnavn",value:u.name,onChange:s=>w({...u,name:s.target.value}),className:"flex-1"}),e.jsx(p,{placeholder:"mm:ss",value:u.duration,onChange:s=>w({...u,duration:s.target.value}),className:"w-24"}),e.jsx(o,{size:"sm",onClick:()=>T.mutate(u),children:e.jsx(k,{className:"h-4 w-4"})}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>b(!1),children:e.jsx(S,{className:"h-4 w-4"})})]}),e.jsx(X,{onDragEnd:G,children:e.jsx($,{droppableId:"lessons",children:s=>e.jsxs("div",{ref:s.innerRef,...s.droppableProps,className:"space-y-1",children:[m.map((a,r)=>e.jsx(J,{draggableId:a.id,index:r,children:x=>e.jsxs("div",{ref:x.innerRef,...x.draggableProps,className:"flex items-center gap-2 p-3 border border-border rounded-lg bg-card",children:[e.jsx("div",{...x.dragHandleProps,children:e.jsx(U,{className:"h-4 w-4 text-muted-foreground"})}),V===a.id?e.jsxs(e.Fragment,{children:[e.jsx(p,{value:c.name,onChange:y=>j({...c,name:y.target.value}),className:"flex-1"}),e.jsx(p,{value:c.duration,onChange:y=>j({...c,duration:y.target.value}),className:"w-24"}),e.jsx(o,{size:"sm",onClick:()=>R.mutate({id:a.id,...c}),children:e.jsx(k,{className:"h-4 w-4"})}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>g(null),children:e.jsx(S,{className:"h-4 w-4"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1 text-sm font-medium text-foreground",children:a.name}),e.jsx("span",{className:"text-xs text-muted-foreground tabular-nums",children:z(a.duration_seconds)}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>{g(a.id),j({name:a.name,duration:z(a.duration_seconds)})},children:e.jsx(W,{className:"h-3.5 w-3.5"})}),e.jsx(o,{size:"sm",variant:"ghost",onClick:()=>B.mutate(a.id),children:e.jsx(Y,{className:"h-3.5 w-3.5 text-destructive"})})]})]})},a.id)),s.placeholder]})})}),m.length===0&&n&&e.jsx("p",{className:"text-center text-sm text-muted-foreground py-8",children:"Ingen lektioner i dette modul."})]})}
1export{ie 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.