coursekit-lms 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/README.md +127 -26
  3. package/dist/cli/index.js +7139 -1633
  4. package/dist/cli/index.js.map +1 -1
  5. package/dist/server/index.js +7128 -1655
  6. package/dist/server/index.js.map +1 -1
  7. package/dist/types/server/config.d.ts +4 -0
  8. package/dist/types/server/db/migrations/002_email.d.ts +8 -0
  9. package/dist/types/server/db/migrations/003_groups_cohorts.d.ts +7 -0
  10. package/dist/types/server/db/migrations/004_completion_badges.d.ts +8 -0
  11. package/dist/types/server/db/migrations/005_question_bank.d.ts +11 -0
  12. package/dist/types/server/db/migrations/006_grade_categories.d.ts +11 -0
  13. package/dist/types/server/db/schema-completion.d.ts +79 -0
  14. package/dist/types/server/db/schema.d.ts +165 -5
  15. package/dist/types/server/index.d.ts +7 -0
  16. package/dist/types/server/lib/events.d.ts +105 -0
  17. package/dist/types/server/routes/badges.d.ts +4 -0
  18. package/dist/types/server/routes/certificates.d.ts +3 -0
  19. package/dist/types/server/routes/cohorts.d.ts +6 -0
  20. package/dist/types/server/routes/completion.d.ts +4 -0
  21. package/dist/types/server/routes/email.d.ts +13 -0
  22. package/dist/types/server/routes/grade-categories.d.ts +4 -0
  23. package/dist/types/server/routes/groups.d.ts +4 -0
  24. package/dist/types/server/routes/question-bank.d.ts +4 -0
  25. package/dist/types/server/seed/demo-completion.d.ts +2 -0
  26. package/dist/types/server/seed/demo-email.d.ts +2 -0
  27. package/dist/types/server/seed/demo-grade-categories.d.ts +6 -0
  28. package/dist/types/server/seed/demo-groups.d.ts +6 -0
  29. package/dist/types/server/seed/demo-question-bank.d.ts +20 -0
  30. package/dist/types/server/services/badges.d.ts +39 -0
  31. package/dist/types/server/services/certificates.d.ts +42 -0
  32. package/dist/types/server/services/cohorts.d.ts +64 -0
  33. package/dist/types/server/services/completion.d.ts +63 -0
  34. package/dist/types/server/services/course-total.d.ts +107 -0
  35. package/dist/types/server/services/email/config.d.ts +55 -0
  36. package/dist/types/server/services/email/digests.d.ts +57 -0
  37. package/dist/types/server/services/email/outbox.d.ts +61 -0
  38. package/dist/types/server/services/email/preferences.d.ts +25 -0
  39. package/dist/types/server/services/email/service.d.ts +116 -0
  40. package/dist/types/server/services/email/templates.d.ts +74 -0
  41. package/dist/types/server/services/email/tokens.d.ts +11 -0
  42. package/dist/types/server/services/email/transport.d.ts +29 -0
  43. package/dist/types/server/services/enrolments.d.ts +32 -0
  44. package/dist/types/server/services/grade-categories.d.ts +31 -0
  45. package/dist/types/server/services/gradebook.d.ts +18 -0
  46. package/dist/types/server/services/groups.d.ts +90 -0
  47. package/dist/types/server/services/notify.d.ts +4 -1
  48. package/dist/types/server/services/question-bank.d.ts +53 -0
  49. package/dist/types/server/services/question-types.d.ts +146 -0
  50. package/dist/types/server/services/quiz-slots.d.ts +33 -0
  51. package/dist/types/server/services/quiz.d.ts +45 -14
  52. package/dist/types/shared/completion.d.ts +214 -0
  53. package/dist/types/shared/email.d.ts +117 -0
  54. package/dist/types/shared/grades.d.ts +18 -0
  55. package/dist/types/shared/groups.d.ts +17 -0
  56. package/dist/types/shared/permissions.d.ts +1 -1
  57. package/dist/types/shared/types.d.ts +268 -2
  58. package/dist/web/assets/{ActivityEditor-BVSZUV8l.js → ActivityEditor-BNG3aTQa.js} +2 -2
  59. package/dist/web/assets/ActivityPage-i0XHYD2Q.js +1 -0
  60. package/dist/web/assets/AdminBadgesPage-DvpxIg1P.js +1 -0
  61. package/dist/web/assets/AdminCohortsPage-B5PWBkjp.js +3 -0
  62. package/dist/web/assets/AdminCoursesPage-Dm1ECbS-.js +1 -0
  63. package/dist/web/assets/AdminEmailPage-D3E_Db1_.js +1 -0
  64. package/dist/web/assets/AdminLayout-BVeduyCQ.js +1 -0
  65. package/dist/web/assets/{AdminOverviewPage-DnTrdGbr.js → AdminOverviewPage-BaCKvhgr.js} +1 -1
  66. package/dist/web/assets/{AdminSettingsPage-B82cX8xU.js → AdminSettingsPage-B5Ag5K15.js} +1 -1
  67. package/dist/web/assets/AdminUsersPage-BVCG65EK.js +1 -0
  68. package/dist/web/assets/{AnnouncementsPage-BKW30k0Z.js → AnnouncementsPage-C0OAzyvW.js} +1 -1
  69. package/dist/web/assets/BadgePage-B3Ecudas.js +1 -0
  70. package/dist/web/assets/CalendarPage-CEks5F4m.js +1 -0
  71. package/dist/web/assets/{CatalogPage-BiMgSSBR.js → CatalogPage-e7lVtwUN.js} +1 -1
  72. package/dist/web/assets/CertificatePage-_eSGt8R-.js +9 -0
  73. package/dist/web/assets/CompletionPage-Dxp-ulA_.js +1 -0
  74. package/dist/web/assets/CourseBadgesPage-Vi3P1Lnc.js +1 -0
  75. package/dist/web/assets/CourseContentPage-IFlhVsO5.js +1 -0
  76. package/dist/web/assets/CourseLayout-BqwXol8L.js +1 -0
  77. package/dist/web/assets/CourseSettingsPage-BIagLirb.js +1 -0
  78. package/dist/web/assets/CreateCoursePage-BBcdiTtz.js +1 -0
  79. package/dist/web/assets/{DiscussionPage-CWwVpFQV.js → DiscussionPage-C23QoCSw.js} +1 -1
  80. package/dist/web/assets/GradebookSetupPage-a5GH4xIk.js +1 -0
  81. package/dist/web/assets/GradesPage-CY6MtJxs.js +1 -0
  82. package/dist/web/assets/GroupsPage-DS3HFeC4.js +1 -0
  83. package/dist/web/assets/{MyCoursesPage-Dd-Oaygv.js → MyCoursesPage-Ckj-1SCA.js} +1 -1
  84. package/dist/web/assets/{NotFoundPage-BRquC7-l.js → NotFoundPage-BmwVsGAy.js} +1 -1
  85. package/dist/web/assets/NotificationsPage-DBRM37F1.js +1 -0
  86. package/dist/web/assets/ParticipantsPage-DV4Mjfxo.js +1 -0
  87. package/dist/web/assets/ProfilePage-BqG55_02.js +1 -0
  88. package/dist/web/assets/QuestionAnswer-CJIoWSz2.js +1 -0
  89. package/dist/web/assets/QuestionBankPage-BkI44c4K.js +1 -0
  90. package/dist/web/assets/QuizAttemptPage-DQVfbLKI.js +1 -0
  91. package/dist/web/assets/QuizEditorPage-muk-KVG1.js +1 -0
  92. package/dist/web/assets/SubmissionsPage-Dx97JOzE.js +1 -0
  93. package/dist/web/assets/UnsubscribePage-BPLiTiaG.js +1 -0
  94. package/dist/web/assets/VerifyCertificatePage-Cw9iXN3C.js +1 -0
  95. package/dist/web/assets/achievements-DaIfUTKU.js +1 -0
  96. package/dist/web/assets/{arrow-up-LHDup5m4.js → arrow-up-lI30bvj5.js} +1 -1
  97. package/dist/web/assets/badge-art-QPo-pYql.js +1 -0
  98. package/dist/web/assets/badge-card-ByT0wR6q.js +1 -0
  99. package/dist/web/assets/badge-dialog-p2zTk4h0.js +1 -0
  100. package/dist/web/assets/{ban-D3Vsxg_g.js → ban-DEiI8npI.js} +1 -1
  101. package/dist/web/assets/bank-S3XEFPfe.js +3 -0
  102. package/dist/web/assets/bell-off-Bo2RE0kn.js +1 -0
  103. package/dist/web/assets/calendar-range-Cfg-P4Md.js +1 -0
  104. package/dist/web/assets/certificate-sheet-DzW0lfzR.js +2 -0
  105. package/dist/web/assets/chevron-left-Bu6IJANV.js +1 -0
  106. package/dist/web/assets/circle-dashed-D34ZjnSx.js +1 -0
  107. package/dist/web/assets/clock-DPBmdKAi.js +1 -0
  108. package/dist/web/assets/cohorts-DL0Dsxva.js +1 -0
  109. package/dist/web/assets/completion-2z7I-ypT.js +1 -0
  110. package/dist/web/assets/contact-NCWQa7wc.js +1 -0
  111. package/dist/web/assets/{context-BLVW7NB7.js → context-D8W_QqNi.js} +1 -1
  112. package/dist/web/assets/{copy-Bxxjq6zo.js → copy-B5IKRMFo.js} +1 -1
  113. package/dist/web/assets/download-BrtK5sVk.js +1 -0
  114. package/dist/web/assets/{ellipsis-c2POIN-Y.js → ellipsis-BDmYLoyn.js} +1 -1
  115. package/dist/web/assets/email-BZ3kGs-R.js +1 -0
  116. package/dist/web/assets/flag-DOzXVys0.js +1 -0
  117. package/dist/web/assets/folder-input-M2p_UJZX.js +1 -0
  118. package/dist/web/assets/{library-3WG9oLCb.js → folder-tree-B-DoLXMB.js} +1 -1
  119. package/dist/web/assets/frame-DZh5g5b3.js +1 -0
  120. package/dist/web/assets/globe-DDTr53UY.js +1 -0
  121. package/dist/web/assets/grades-ogaD0MDO.js +1 -0
  122. package/dist/web/assets/groups-CrYV_AFp.js +1 -0
  123. package/dist/web/assets/{hooks-BBARn-DA.js → hooks-EFhyJ5yU.js} +1 -1
  124. package/dist/web/assets/hourglass-BKca6Cje.js +1 -0
  125. package/dist/web/assets/inbox-x1U4YU-c.js +1 -0
  126. package/dist/web/assets/index-BdPmMS6n.css +2 -0
  127. package/dist/web/assets/index-CEZdqKdi.js +50 -0
  128. package/dist/web/assets/{key-round-B_KI-brR.js → key-round-fzvV-etw.js} +1 -1
  129. package/dist/web/assets/library-Bcm33ouq.js +1 -0
  130. package/dist/web/assets/lightbulb-CjSpJ1_v.js +1 -0
  131. package/dist/web/assets/{lock-BjbqwA_0.js → lock-C2edVDOc.js} +1 -1
  132. package/dist/web/assets/mail-CQ9yiBph.js +1 -0
  133. package/dist/web/assets/mail-x-B6oBqlcw.js +1 -0
  134. package/dist/web/assets/{markdown-ykrkPMbn.js → markdown-HNlXovsL.js} +3 -3
  135. package/dist/web/assets/message-square-text-wvO9_guT.js +1 -0
  136. package/dist/web/assets/{misc-DvgDEI3I.js → misc-CyGhN6HT.js} +1 -1
  137. package/dist/web/assets/{pencil-p0GQmIMo.js → pencil-DFUpj3YP.js} +1 -1
  138. package/dist/web/assets/{pin-DlYC3uec.js → pin-DNUQ6-WX.js} +1 -1
  139. package/dist/web/assets/revoke-dialog-DjBKaFTV.js +1 -0
  140. package/dist/web/assets/rotate-ccw-yBj9Ri49.js +1 -0
  141. package/dist/web/assets/scroll-text-RmPlZi3F.js +1 -0
  142. package/dist/web/assets/{send-mxSHcdcD.js → send-BnVkFV8w.js} +1 -1
  143. package/dist/web/assets/{settings-DRKWzSHN.js → settings-BxdCrDf8.js} +1 -1
  144. package/dist/web/assets/shield-x-RpNHS0o8.js +1 -0
  145. package/dist/web/assets/shuffle-C1aB_4dp.js +1 -0
  146. package/dist/web/assets/target-G9Q_WQLB.js +1 -0
  147. package/dist/web/assets/trophy-BFFngFEh.js +1 -0
  148. package/dist/web/assets/user-minus-CkOPT3ak.js +1 -0
  149. package/dist/web/assets/users-round-CNhv0Whm.js +1 -0
  150. package/dist/web/index.html +4 -4
  151. package/package.json +6 -1
  152. package/dist/web/assets/ActivityPage-DPmSV_mU.js +0 -1
  153. package/dist/web/assets/AdminCoursesPage-uaSHNtzf.js +0 -1
  154. package/dist/web/assets/AdminLayout-DqoShZGn.js +0 -1
  155. package/dist/web/assets/AdminUsersPage-3d2F9AEl.js +0 -1
  156. package/dist/web/assets/CalendarPage-CLRWyTNT.js +0 -1
  157. package/dist/web/assets/CourseContentPage-BIDH0UbG.js +0 -1
  158. package/dist/web/assets/CourseLayout-ql01LEmj.js +0 -1
  159. package/dist/web/assets/CourseSettingsPage-CReoPqOa.js +0 -1
  160. package/dist/web/assets/CreateCoursePage-DFCHlq5M.js +0 -1
  161. package/dist/web/assets/GradesPage-Bu5vphcG.js +0 -1
  162. package/dist/web/assets/NotificationsPage-LJvqb6Dj.js +0 -1
  163. package/dist/web/assets/ParticipantsPage-wFxiphna.js +0 -1
  164. package/dist/web/assets/ProfilePage-CzfhacAX.js +0 -1
  165. package/dist/web/assets/QuizAttemptPage-CEAV6wAL.js +0 -1
  166. package/dist/web/assets/QuizEditorPage-DS_czQVM.js +0 -3
  167. package/dist/web/assets/SubmissionsPage-CQjcx09G.js +0 -1
  168. package/dist/web/assets/chevron-left-D6IMQD6N.js +0 -1
  169. package/dist/web/assets/frame-CGabirLa.js +0 -1
  170. package/dist/web/assets/index-B29bTBiJ.js +0 -50
  171. package/dist/web/assets/index-WxCvsbJq.css +0 -2
  172. package/dist/web/assets/message-square-text-fe24gbEU.js +0 -1
  173. package/dist/web/assets/trophy-Cch2iF1m.js +0 -1
@@ -1 +1 @@
1
- import{D as e,H as t,U as n,_ as r,d as i,dt as a,ft as o,m as s,mt as c,r as l,w as u}from"./hooks-BBARn-DA.js";import{At as d,Et as f,F as p,S as m,ct as h,et as g,j as _,mt as v,n as y,nt as b,o as x,t as S}from"./index-B29bTBiJ.js";import{c as C,n as w}from"./misc-DvgDEI3I.js";var T={name:`database`,size:24,node:[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]};T.node;var E=t(T),D=c(o(),1),O=a();function k(e){if(e<=4)return Math.max(1,e);let t=10**Math.floor(Math.log10(e)),n=[1,2,2.5,5,10].find(n=>n*t>=e/2)*t;return Math.ceil(e/n)*n}function A({data:e}){let[t,n]=(0,D.useState)(null),i=k(Math.max(0,...e.map(e=>e.count))),a=i<=4?Array.from({length:i+1},(e,t)=>t):[0,i/2,i],o=e.reduce((e,t)=>e+t.count,0),s=e=>u(`${e.date}T12:00:00Z`,{month:`short`,day:`numeric`});return(0,O.jsxs)(S,{children:[(0,O.jsx)(y,{title:`New sign-ups`,description:`Last 30 days · ${o} total`}),(0,O.jsxs)(`div`,{className:`px-5 pb-5`,children:[(0,O.jsxs)(`div`,{className:`relative flex h-48 gap-3`,children:[(0,O.jsx)(`div`,{className:`flex flex-col-reverse justify-between pb-6 text-right text-[11px] text-muted-foreground tabular-nums`,"aria-hidden":!0,children:a.map(e=>(0,O.jsx)(`span`,{className:`-translate-y-1/2 leading-none first:translate-y-1/2`,children:e},e))}),(0,O.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,O.jsx)(`div`,{className:`absolute inset-x-0 top-0 bottom-6 flex flex-col-reverse justify-between`,"aria-hidden":!0,children:a.map(e=>(0,O.jsx)(`div`,{className:`h-px bg-border`},e))}),(0,O.jsx)(`div`,{className:`absolute inset-x-0 top-0 bottom-6 flex items-end gap-[2px]`,role:`img`,"aria-label":`Sign-ups per day for the last 30 days, ${o} in total`,children:e.map((e,a)=>(0,O.jsxs)(`button`,{type:`button`,className:`group relative flex h-full flex-1 items-end justify-center outline-none`,onPointerEnter:()=>n(a),onPointerLeave:()=>n(null),onFocus:()=>n(a),onBlur:()=>n(null),"aria-label":`${s(e)}: ${e.count} sign-up${e.count===1?``:`s`}`,children:[e.count>0&&(0,O.jsx)(`span`,{className:r(`w-[70%] max-w-6 rounded-t-[4px] bg-primary transition-[filter]`,t===a&&`brightness-110`),style:{height:`${e.count/i*100}%`}}),t===a&&(0,O.jsxs)(`span`,{className:`pointer-events-none absolute bottom-full z-10 mb-1.5 rounded-lg border bg-popover px-2.5 py-1.5 text-left whitespace-nowrap shadow-lg`,children:[(0,O.jsxs)(`span`,{className:`block text-sm font-semibold`,children:[e.count,` sign-up`,e.count===1?``:`s`]}),(0,O.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(e)})]})]},e.date))}),(0,O.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 flex justify-between text-[11px] text-muted-foreground`,"aria-hidden":!0,children:[(0,O.jsx)(`span`,{children:s(e[0])}),(0,O.jsx)(`span`,{children:s(e[Math.floor(e.length/2)])}),(0,O.jsx)(`span`,{children:s(e[e.length-1])})]})]})]}),(0,O.jsxs)(`table`,{className:`sr-only`,children:[(0,O.jsx)(`caption`,{children:`Sign-ups per day`}),(0,O.jsx)(`thead`,{children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{children:`Date`}),(0,O.jsx)(`th`,{children:`Sign-ups`})]})}),(0,O.jsx)(`tbody`,{children:e.map(e=>(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`td`,{children:s(e)}),(0,O.jsx)(`td`,{children:e.count})]},e.date))})]})]})]})}function j(){l(`Administration`);let{data:t,isLoading:r,error:a,refetch:o}=n({queryKey:[`admin`,`overview`],queryFn:()=>s.get(`/admin/overview`)});if(a)return(0,O.jsx)(w,{error:a,onRetry:()=>o()});if(r||!t)return(0,O.jsxs)(`div`,{className:`space-y-6`,children:[(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[0,1,2,3].map(e=>(0,O.jsx)(C,{className:`h-[104px]`},e))}),(0,O.jsx)(C,{className:`h-72`})]});let c=Math.max(1,...t.topCourses.map(e=>e.students));return(0,O.jsxs)(`div`,{className:`space-y-6`,children:[(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,O.jsx)(x,{icon:g,label:`People`,value:t.counts.users.toLocaleString(),tone:`primary`}),(0,O.jsx)(x,{icon:f,label:`Courses`,value:t.counts.courses.toLocaleString(),tone:`sky`}),(0,O.jsx)(x,{icon:v,label:`Enrolments`,value:t.counts.enrolments.toLocaleString(),tone:`violet`}),(0,O.jsx)(x,{icon:b,label:`Submissions`,value:t.counts.submissions.toLocaleString(),hint:`${t.counts.posts.toLocaleString()} forum posts`,tone:`emerald`})]}),(0,O.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:[(0,O.jsx)(A,{data:t.signups}),(0,O.jsxs)(S,{children:[(0,O.jsx)(y,{title:`Most popular courses`,description:`Active student enrolments`}),(0,O.jsxs)(`div`,{className:`space-y-3.5 px-5 pb-5`,children:[t.topCourses.length===0&&(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No courses yet.`}),t.topCourses.map(e=>(0,O.jsxs)(d,{to:`/courses/${e.slug}`,className:`group block`,children:[(0,O.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 text-sm`,children:[(0,O.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-[3px]`,style:p(e.coverColor)}),(0,O.jsx)(`span`,{className:`truncate font-medium group-hover:text-primary`,children:e.title}),(0,O.jsx)(`span`,{className:`ml-auto text-muted-foreground tabular-nums`,children:e.students})]}),(0,O.jsx)(`div`,{className:`h-2 rounded-r-[4px] bg-transparent`,children:(0,O.jsx)(`div`,{className:`h-2 rounded-r-[4px] bg-primary`,style:{width:`${Math.max(2,e.students/c*100)}%`}})})]},e.id))]})]})]}),(0,O.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:[(0,O.jsxs)(S,{children:[(0,O.jsx)(y,{title:`Newest people`,action:(0,O.jsx)(d,{to:`/admin/users`,className:`text-xs font-medium text-primary hover:underline`,children:`Manage users`})}),(0,O.jsx)(`div`,{className:`divide-y border-t`,children:t.recentUsers.map(t=>(0,O.jsxs)(`div`,{className:`flex items-center gap-3 px-5 py-3`,children:[(0,O.jsx)(_,{user:t,size:`sm`}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`truncate text-sm font-medium`,children:t.name}),(0,O.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:t.email})]}),(0,O.jsx)(m,{variant:t.role===`admin`?`violet`:t.role===`instructor`?`info`:`neutral`,children:i[t.role]}),(0,O.jsx)(`span`,{className:`hidden w-24 text-right text-xs text-muted-foreground sm:block`,children:e(t.createdAt)})]},t.id))})]}),(0,O.jsxs)(S,{children:[(0,O.jsx)(y,{title:`System`,icon:(0,O.jsx)(E,{className:`size-4.5`})}),(0,O.jsxs)(`dl`,{className:`space-y-3 px-5 pb-5 text-sm`,children:[[[`Version`,`Coursekit ${t.version}`],[`Database`,t.database],[`Activities`,t.counts.activities.toLocaleString()],[`Forum posts`,t.counts.posts.toLocaleString()]].map(([e,t])=>(0,O.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,O.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,O.jsx)(`dd`,{className:`font-medium`,children:t})]},e)),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-muted/60 px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,O.jsx)(h,{className:`size-3.5`}),` Coursekit is open source. Contributions welcome!`]})]})]})]})]})}export{j as default};
1
+ import{D as e,H as t,U as n,_ as r,d as i,dt as a,ft as o,m as s,mt as c,r as l,w as u}from"./hooks-EFhyJ5yU.js";import{C as d,I as f,It as p,M as m,Mt as h,bt as g,n as _,o as v,pt as y,rt as b,t as x,tt as S}from"./index-CEZdqKdi.js";import{c as C,n as w}from"./misc-CyGhN6HT.js";var T={name:`database`,size:24,node:[[`ellipse`,{cx:`12`,cy:`5`,rx:`9`,ry:`3`,key:`msslwz`}],[`path`,{d:`M3 5V19A9 3 0 0 0 21 19V5`,key:`1wlel7`}],[`path`,{d:`M3 12A9 3 0 0 0 21 12`,key:`mv7ke4`}]]};T.node;var E=t(T),D=c(o(),1),O=a();function k(e){if(e<=4)return Math.max(1,e);let t=10**Math.floor(Math.log10(e)),n=[1,2,2.5,5,10].find(n=>n*t>=e/2)*t;return Math.ceil(e/n)*n}function A({data:e}){let[t,n]=(0,D.useState)(null),i=k(Math.max(0,...e.map(e=>e.count))),a=i<=4?Array.from({length:i+1},(e,t)=>t):[0,i/2,i],o=e.reduce((e,t)=>e+t.count,0),s=e=>u(`${e.date}T12:00:00Z`,{month:`short`,day:`numeric`});return(0,O.jsxs)(x,{children:[(0,O.jsx)(_,{title:`New sign-ups`,description:`Last 30 days · ${o} total`}),(0,O.jsxs)(`div`,{className:`px-5 pb-5`,children:[(0,O.jsxs)(`div`,{className:`relative flex h-48 gap-3`,children:[(0,O.jsx)(`div`,{className:`flex flex-col-reverse justify-between pb-6 text-right text-[11px] text-muted-foreground tabular-nums`,"aria-hidden":!0,children:a.map(e=>(0,O.jsx)(`span`,{className:`-translate-y-1/2 leading-none first:translate-y-1/2`,children:e},e))}),(0,O.jsxs)(`div`,{className:`relative min-w-0 flex-1`,children:[(0,O.jsx)(`div`,{className:`absolute inset-x-0 top-0 bottom-6 flex flex-col-reverse justify-between`,"aria-hidden":!0,children:a.map(e=>(0,O.jsx)(`div`,{className:`h-px bg-border`},e))}),(0,O.jsx)(`div`,{className:`absolute inset-x-0 top-0 bottom-6 flex items-end gap-[2px]`,role:`img`,"aria-label":`Sign-ups per day for the last 30 days, ${o} in total`,children:e.map((e,a)=>(0,O.jsxs)(`button`,{type:`button`,className:`group relative flex h-full flex-1 items-end justify-center outline-none`,onPointerEnter:()=>n(a),onPointerLeave:()=>n(null),onFocus:()=>n(a),onBlur:()=>n(null),"aria-label":`${s(e)}: ${e.count} sign-up${e.count===1?``:`s`}`,children:[e.count>0&&(0,O.jsx)(`span`,{className:r(`w-[70%] max-w-6 rounded-t-[4px] bg-primary transition-[filter]`,t===a&&`brightness-110`),style:{height:`${e.count/i*100}%`}}),t===a&&(0,O.jsxs)(`span`,{className:`pointer-events-none absolute bottom-full z-10 mb-1.5 rounded-lg border bg-popover px-2.5 py-1.5 text-left whitespace-nowrap shadow-lg`,children:[(0,O.jsxs)(`span`,{className:`block text-sm font-semibold`,children:[e.count,` sign-up`,e.count===1?``:`s`]}),(0,O.jsx)(`span`,{className:`block text-[11px] text-muted-foreground`,children:s(e)})]})]},e.date))}),(0,O.jsxs)(`div`,{className:`absolute inset-x-0 bottom-0 flex justify-between text-[11px] text-muted-foreground`,"aria-hidden":!0,children:[(0,O.jsx)(`span`,{children:s(e[0])}),(0,O.jsx)(`span`,{children:s(e[Math.floor(e.length/2)])}),(0,O.jsx)(`span`,{children:s(e[e.length-1])})]})]})]}),(0,O.jsxs)(`table`,{className:`sr-only`,children:[(0,O.jsx)(`caption`,{children:`Sign-ups per day`}),(0,O.jsx)(`thead`,{children:(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`th`,{children:`Date`}),(0,O.jsx)(`th`,{children:`Sign-ups`})]})}),(0,O.jsx)(`tbody`,{children:e.map(e=>(0,O.jsxs)(`tr`,{children:[(0,O.jsx)(`td`,{children:s(e)}),(0,O.jsx)(`td`,{children:e.count})]},e.date))})]})]})]})}function j(){l(`Administration`);let{data:t,isLoading:r,error:a,refetch:o}=n({queryKey:[`admin`,`overview`],queryFn:()=>s.get(`/admin/overview`)});if(a)return(0,O.jsx)(w,{error:a,onRetry:()=>o()});if(r||!t)return(0,O.jsxs)(`div`,{className:`space-y-6`,children:[(0,O.jsx)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[0,1,2,3].map(e=>(0,O.jsx)(C,{className:`h-[104px]`},e))}),(0,O.jsx)(C,{className:`h-72`})]});let c=Math.max(1,...t.topCourses.map(e=>e.students));return(0,O.jsxs)(`div`,{className:`space-y-6`,children:[(0,O.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 lg:grid-cols-4`,children:[(0,O.jsx)(v,{icon:S,label:`People`,value:t.counts.users.toLocaleString(),tone:`primary`}),(0,O.jsx)(v,{icon:h,label:`Courses`,value:t.counts.courses.toLocaleString(),tone:`sky`}),(0,O.jsx)(v,{icon:g,label:`Enrolments`,value:t.counts.enrolments.toLocaleString(),tone:`violet`}),(0,O.jsx)(v,{icon:b,label:`Submissions`,value:t.counts.submissions.toLocaleString(),hint:`${t.counts.posts.toLocaleString()} forum posts`,tone:`emerald`})]}),(0,O.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:[(0,O.jsx)(A,{data:t.signups}),(0,O.jsxs)(x,{children:[(0,O.jsx)(_,{title:`Most popular courses`,description:`Active student enrolments`}),(0,O.jsxs)(`div`,{className:`space-y-3.5 px-5 pb-5`,children:[t.topCourses.length===0&&(0,O.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`No courses yet.`}),t.topCourses.map(e=>(0,O.jsxs)(p,{to:`/courses/${e.slug}`,className:`group block`,children:[(0,O.jsxs)(`div`,{className:`mb-1.5 flex items-center gap-2 text-sm`,children:[(0,O.jsx)(`span`,{className:`size-2.5 shrink-0 rounded-[3px]`,style:f(e.coverColor)}),(0,O.jsx)(`span`,{className:`truncate font-medium group-hover:text-primary`,children:e.title}),(0,O.jsx)(`span`,{className:`ml-auto text-muted-foreground tabular-nums`,children:e.students})]}),(0,O.jsx)(`div`,{className:`h-2 rounded-r-[4px] bg-transparent`,children:(0,O.jsx)(`div`,{className:`h-2 rounded-r-[4px] bg-primary`,style:{width:`${Math.max(2,e.students/c*100)}%`}})})]},e.id))]})]})]}),(0,O.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1.4fr)_minmax(0,1fr)]`,children:[(0,O.jsxs)(x,{children:[(0,O.jsx)(_,{title:`Newest people`,action:(0,O.jsx)(p,{to:`/admin/users`,className:`text-xs font-medium text-primary hover:underline`,children:`Manage users`})}),(0,O.jsx)(`div`,{className:`divide-y border-t`,children:t.recentUsers.map(t=>(0,O.jsxs)(`div`,{className:`flex items-center gap-3 px-5 py-3`,children:[(0,O.jsx)(m,{user:t,size:`sm`}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`truncate text-sm font-medium`,children:t.name}),(0,O.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:t.email})]}),(0,O.jsx)(d,{variant:t.role===`admin`?`violet`:t.role===`instructor`?`info`:`neutral`,children:i[t.role]}),(0,O.jsx)(`span`,{className:`hidden w-24 text-right text-xs text-muted-foreground sm:block`,children:e(t.createdAt)})]},t.id))})]}),(0,O.jsxs)(x,{children:[(0,O.jsx)(_,{title:`System`,icon:(0,O.jsx)(E,{className:`size-4.5`})}),(0,O.jsxs)(`dl`,{className:`space-y-3 px-5 pb-5 text-sm`,children:[[[`Version`,`Coursekit ${t.version}`],[`Database`,t.database],[`Activities`,t.counts.activities.toLocaleString()],[`Forum posts`,t.counts.posts.toLocaleString()]].map(([e,t])=>(0,O.jsxs)(`div`,{className:`flex justify-between gap-4`,children:[(0,O.jsx)(`dt`,{className:`text-muted-foreground`,children:e}),(0,O.jsx)(`dd`,{className:`font-medium`,children:t})]},e)),(0,O.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg bg-muted/60 px-3 py-2.5 text-xs text-muted-foreground`,children:[(0,O.jsx)(y,{className:`size-3.5`}),` Coursekit is open source. Contributions welcome!`]})]})]})]})]})}export{j as default};
@@ -1 +1 @@
1
- import{Ct as e,Rt as t,l as n,m as r,mt as i,n as a,p as o,t as s,u as c}from"./index-B29bTBiJ.js";import{U as l,_ as u,b as d,dt as f,ft as p,g as m,h,m as g,mt as _,r as v,ut as y,y as b}from"./hooks-BBARn-DA.js";import{T as x,c as S}from"./misc-DvgDEI3I.js";var C=_(p(),1),w=f(),T=[`#4f46e5`,`#2563eb`,`#0891b2`,`#059669`,`#16a34a`,`#d97706`,`#ea580c`,`#dc2626`,`#db2777`,`#9333ea`,`#0f172a`];function E(){v(`Site settings`);let f=y(),{data:p}=l({queryKey:[`admin`,`settings`],queryFn:()=>g.get(`/admin/settings`)}),[_,E]=(0,C.useState)(null);(0,C.useEffect)(()=>{p&&!_&&E(p)},[p,_]);let D=t({mutationFn:()=>g.put(`/admin/settings`,_),onSuccess:async e=>{E(e),x.success(`Site settings saved`),await f.invalidateQueries({queryKey:[`session`]}),await f.invalidateQueries({queryKey:[`admin`,`settings`]})},onError:e=>x.error(h(e))});if(!_)return(0,w.jsx)(S,{className:`h-96`});let O=JSON.stringify(_)!==JSON.stringify(p),k=/^#[0-9a-fA-F]{6}$/.test(_.brandColor);return(0,w.jsxs)(`form`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_340px]`,onSubmit:e=>{e.preventDefault(),D.mutate()},children:[(0,w.jsxs)(`div`,{className:`space-y-6`,children:[(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Identity`,description:`Your site's name and messaging.`}),(0,w.jsxs)(`div`,{className:`space-y-4 px-5 pb-5`,children:[(0,w.jsx)(n,{label:`Site name`,children:e=>(0,w.jsx)(c,{...e,required:!0,value:_.name,onChange:e=>E({..._,name:e.target.value})})}),(0,w.jsx)(n,{label:`Tagline`,hint:`Shown on the sign-in page.`,children:e=>(0,w.jsx)(c,{...e,value:_.tagline,onChange:e=>E({..._,tagline:e.target.value})})}),(0,w.jsx)(n,{label:`Dashboard welcome message`,children:e=>(0,w.jsx)(r,{...e,rows:2,value:_.welcomeMessage,onChange:e=>E({..._,welcomeMessage:e.target.value})})})]})]}),(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Brand colour`,description:`Used for buttons, links and highlights across the site.`}),(0,w.jsxs)(`div`,{className:`space-y-4 px-5 pb-5`,children:[(0,w.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.map(t=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>E({..._,brandColor:t}),className:u(`grid size-9 place-items-center rounded-full ring-offset-2 ring-offset-card transition-transform hover:scale-110`,_.brandColor.toLowerCase()===t&&`ring-2 ring-foreground`),style:{background:t},"aria-label":`Use ${t}`,children:_.brandColor.toLowerCase()===t&&(0,w.jsx)(e,{className:`size-4`,style:{color:d(t)},strokeWidth:3})},t))}),(0,w.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,w.jsx)(`input`,{type:`color`,value:k?_.brandColor:`#4f46e5`,onChange:e=>E({..._,brandColor:e.target.value}),className:`size-9 cursor-pointer rounded-lg border bg-card p-1`,"aria-label":`Custom colour`}),(0,w.jsx)(c,{value:_.brandColor,onChange:e=>E({..._,brandColor:e.target.value}),className:`w-32 font-mono`,"aria-label":`Hex colour`}),!k&&(0,w.jsx)(`span`,{className:`text-xs text-destructive`,children:`Use a 6-digit hex colour`})]}),k&&b(_.brandColor,`#ffffff`)<4.5&&(0,w.jsxs)(`p`,{className:`rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-300`,children:[`This colour is light for text on white (`,b(_.brandColor,`#ffffff`).toFixed(1),`:1). Links and labels may be hard to read; a darker shade is more accessible.`]})]})]}),(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Access`}),(0,w.jsx)(`div`,{className:`px-5 pb-5`,children:(0,w.jsx)(o,{label:`Allow self-registration`,description:`Anyone can create a student account from the sign-in page. Turn off to add people yourself.`,checked:_.allowSignup,onCheckedChange:e=>E({..._,allowSignup:e})})})]})]}),(0,w.jsxs)(`div`,{className:`space-y-4 lg:sticky lg:top-20`,children:[(0,w.jsxs)(s,{className:`overflow-hidden`,children:[(0,w.jsx)(`p`,{className:`border-b px-5 py-3 text-xs font-medium text-muted-foreground`,children:`Preview`}),(0,w.jsxs)(`div`,{className:`space-y-4 p-5`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,w.jsx)(`span`,{className:`grid size-8 place-items-center rounded-[10px] text-white`,style:{background:k?_.brandColor:void 0,color:k?d(_.brandColor):void 0},children:(0,w.jsx)(i,{className:`size-[18px]`})}),(0,w.jsx)(`span`,{className:`font-semibold`,children:_.name||`Your site`})]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_.tagline}),(0,w.jsxs)(`div`,{className:`flex gap-2`,children:[(0,w.jsx)(`span`,{className:`rounded-lg px-4 py-2 text-sm font-medium`,style:{background:k?_.brandColor:void 0,color:k?d(_.brandColor):void 0},children:`Primary button`}),(0,w.jsx)(`span`,{className:`rounded-lg px-4 py-2 text-sm font-medium`,style:{color:k?_.brandColor:void 0,background:k?`${_.brandColor}1a`:void 0},children:`Soft`})]})]})]}),(0,w.jsx)(m,{type:`submit`,className:`w-full`,loading:D.isPending,disabled:!O||!k,children:`Save settings`})]})]})}export{E as default};
1
+ import{Gt as e,bt as t,kt as n,l as r,m as i,n as a,p as o,t as s,u as c}from"./index-CEZdqKdi.js";import{U as l,_ as u,b as d,dt as f,ft as p,g as m,h,m as g,mt as _,r as v,ut as y,y as b}from"./hooks-EFhyJ5yU.js";import{E as x,c as S}from"./misc-CyGhN6HT.js";var C=_(p(),1),w=f(),T=[`#4f46e5`,`#2563eb`,`#0891b2`,`#059669`,`#16a34a`,`#d97706`,`#ea580c`,`#dc2626`,`#db2777`,`#9333ea`,`#0f172a`];function E(){v(`Site settings`);let f=y(),{data:p}=l({queryKey:[`admin`,`settings`],queryFn:()=>g.get(`/admin/settings`)}),[_,E]=(0,C.useState)(null);(0,C.useEffect)(()=>{p&&!_&&E(p)},[p,_]);let D=e({mutationFn:()=>g.put(`/admin/settings`,_),onSuccess:async e=>{E(e),x.success(`Site settings saved`),await f.invalidateQueries({queryKey:[`session`]}),await f.invalidateQueries({queryKey:[`admin`,`settings`]})},onError:e=>x.error(h(e))});if(!_)return(0,w.jsx)(S,{className:`h-96`});let O=JSON.stringify(_)!==JSON.stringify(p),k=/^#[0-9a-fA-F]{6}$/.test(_.brandColor);return(0,w.jsxs)(`form`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_340px]`,onSubmit:e=>{e.preventDefault(),D.mutate()},children:[(0,w.jsxs)(`div`,{className:`space-y-6`,children:[(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Identity`,description:`Your site's name and messaging.`}),(0,w.jsxs)(`div`,{className:`space-y-4 px-5 pb-5`,children:[(0,w.jsx)(r,{label:`Site name`,children:e=>(0,w.jsx)(c,{...e,required:!0,value:_.name,onChange:e=>E({..._,name:e.target.value})})}),(0,w.jsx)(r,{label:`Tagline`,hint:`Shown on the sign-in page.`,children:e=>(0,w.jsx)(c,{...e,value:_.tagline,onChange:e=>E({..._,tagline:e.target.value})})}),(0,w.jsx)(r,{label:`Dashboard welcome message`,children:e=>(0,w.jsx)(i,{...e,rows:2,value:_.welcomeMessage,onChange:e=>E({..._,welcomeMessage:e.target.value})})})]})]}),(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Brand colour`,description:`Used for buttons, links and highlights across the site.`}),(0,w.jsxs)(`div`,{className:`space-y-4 px-5 pb-5`,children:[(0,w.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:T.map(e=>(0,w.jsx)(`button`,{type:`button`,onClick:()=>E({..._,brandColor:e}),className:u(`grid size-9 place-items-center rounded-full ring-offset-2 ring-offset-card transition-transform hover:scale-110`,_.brandColor.toLowerCase()===e&&`ring-2 ring-foreground`),style:{background:e},"aria-label":`Use ${e}`,children:_.brandColor.toLowerCase()===e&&(0,w.jsx)(n,{className:`size-4`,style:{color:d(e)},strokeWidth:3})},e))}),(0,w.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,w.jsx)(`input`,{type:`color`,value:k?_.brandColor:`#4f46e5`,onChange:e=>E({..._,brandColor:e.target.value}),className:`size-9 cursor-pointer rounded-lg border bg-card p-1`,"aria-label":`Custom colour`}),(0,w.jsx)(c,{value:_.brandColor,onChange:e=>E({..._,brandColor:e.target.value}),className:`w-32 font-mono`,"aria-label":`Hex colour`}),!k&&(0,w.jsx)(`span`,{className:`text-xs text-destructive`,children:`Use a 6-digit hex colour`})]}),k&&b(_.brandColor,`#ffffff`)<4.5&&(0,w.jsxs)(`p`,{className:`rounded-lg bg-amber-500/10 px-3 py-2 text-xs text-amber-800 dark:text-amber-300`,children:[`This colour is light for text on white (`,b(_.brandColor,`#ffffff`).toFixed(1),`:1). Links and labels may be hard to read; a darker shade is more accessible.`]})]})]}),(0,w.jsxs)(s,{children:[(0,w.jsx)(a,{title:`Access`}),(0,w.jsx)(`div`,{className:`px-5 pb-5`,children:(0,w.jsx)(o,{label:`Allow self-registration`,description:`Anyone can create a student account from the sign-in page. Turn off to add people yourself.`,checked:_.allowSignup,onCheckedChange:e=>E({..._,allowSignup:e})})})]})]}),(0,w.jsxs)(`div`,{className:`space-y-4 lg:sticky lg:top-20`,children:[(0,w.jsxs)(s,{className:`overflow-hidden`,children:[(0,w.jsx)(`p`,{className:`border-b px-5 py-3 text-xs font-medium text-muted-foreground`,children:`Preview`}),(0,w.jsxs)(`div`,{className:`space-y-4 p-5`,children:[(0,w.jsxs)(`div`,{className:`flex items-center gap-2.5`,children:[(0,w.jsx)(`span`,{className:`grid size-8 place-items-center rounded-[10px] text-white`,style:{background:k?_.brandColor:void 0,color:k?d(_.brandColor):void 0},children:(0,w.jsx)(t,{className:`size-[18px]`})}),(0,w.jsx)(`span`,{className:`font-semibold`,children:_.name||`Your site`})]}),(0,w.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:_.tagline}),(0,w.jsxs)(`div`,{className:`flex gap-2`,children:[(0,w.jsx)(`span`,{className:`rounded-lg px-4 py-2 text-sm font-medium`,style:{background:k?_.brandColor:void 0,color:k?d(_.brandColor):void 0},children:`Primary button`}),(0,w.jsx)(`span`,{className:`rounded-lg px-4 py-2 text-sm font-medium`,style:{color:k?_.brandColor:void 0,background:k?`${_.brandColor}1a`:void 0},children:`Soft`})]})]})]}),(0,w.jsx)(m,{type:`submit`,className:`w-full`,loading:D.isPending,disabled:!O||!k,children:`Save settings`})]})]})}export{E as default};
@@ -0,0 +1 @@
1
+ import{D as e,H as t,Q as n,U as r,d as i,dt as a,ft as o,g as s,h as c,m as l,mt as u,r as ee,s as te,t as ne,ut as re}from"./hooks-EFhyJ5yU.js";import{$ as ie,A as d,B as f,C as p,D as m,E as h,Gt as g,H as _,Ht as v,J as y,M as b,O as x,Ot as S,Rt as ae,U as oe,V as se,W as C,at as ce,f as w,k as T,kt as E,l as D,lt as le,nt as O,t as k,tt as A,u as j,z as M}from"./index-CEZdqKdi.js";import{t as N}from"./ban-DEiI8npI.js";import{t as P}from"./chevron-left-Bu6IJANV.js";import{t as F}from"./copy-B5IKRMFo.js";import{t as I}from"./ellipsis-BDmYLoyn.js";import{E as L,c as R,n as z,s as B,t as V}from"./misc-CyGhN6HT.js";var H={name:`log-in`,size:24,node:[[`path`,{d:`m10 17 5-5-5-5`,key:`1bsop3`}],[`path`,{d:`M15 12H3`,key:`6jk70r`}],[`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`,key:`u53s6r`}]]};H.node;var U=t(H),W=u(o(),1),G=a(),ue={admin:`violet`,instructor:`info`,student:`neutral`},K=20;function de({open:e,onOpenChange:t,onDone:n}){let[r,i]=(0,W.useState)({name:``,email:``,role:`student`,password:``}),[a,o]=(0,W.useState)(null),u=g({mutationFn:()=>l.post(`/admin/users`,{...r,password:r.password||void 0}),onSuccess:e=>{n(),e.temporaryPassword?o(e.temporaryPassword):(L.success(`Created ${e.user.name}`),t(!1)),i({name:``,email:``,role:`student`,password:``})},onError:e=>L.error(c(e))});return(0,G.jsx)(h,{open:e,onOpenChange:e=>{t(e),e||o(null)},children:(0,G.jsx)(x,{children:a?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(d,{icon:(0,G.jsx)(E,{className:`size-5`}),title:`Account created`,description:`Share this temporary password securely. It won't be shown again.`}),(0,G.jsx)(m,{children:(0,G.jsxs)(`div`,{className:`flex items-center gap-2 rounded-lg border bg-muted/50 p-3 font-mono text-sm`,children:[(0,G.jsx)(`span`,{className:`flex-1 break-all`,children:a}),(0,G.jsx)(s,{variant:`ghost`,size:`icon-sm`,"aria-label":`Copy password`,onClick:()=>{navigator.clipboard.writeText(a),L.success(`Copied`)},children:(0,G.jsx)(F,{})})]})}),(0,G.jsx)(T,{children:(0,G.jsx)(s,{onClick:()=>t(!1),children:`Done`})})]}):(0,G.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),u.mutate()},children:[(0,G.jsx)(d,{icon:(0,G.jsx)(O,{className:`size-5`}),title:`Add a person`}),(0,G.jsxs)(m,{className:`space-y-4`,children:[(0,G.jsx)(D,{label:`Full name`,children:e=>(0,G.jsx)(j,{...e,autoFocus:!0,required:!0,value:r.name,onChange:e=>i({...r,name:e.target.value})})}),(0,G.jsx)(D,{label:`Email`,children:e=>(0,G.jsx)(j,{...e,type:`email`,required:!0,value:r.email,onChange:e=>i({...r,email:e.target.value})})}),(0,G.jsx)(D,{label:`Site role`,hint:`Instructors can create courses. Administrators manage the whole site.`,children:e=>(0,G.jsxs)(w,{...e,value:r.role,onChange:e=>i({...r,role:e.target.value}),children:[(0,G.jsx)(`option`,{value:`student`,children:`Student`}),(0,G.jsx)(`option`,{value:`instructor`,children:`Instructor`}),(0,G.jsx)(`option`,{value:`admin`,children:`Administrator`})]})}),(0,G.jsx)(D,{label:`Password`,optional:!0,hint:`Leave empty to generate a temporary password.`,children:e=>(0,G.jsx)(j,{...e,type:`password`,autoComplete:`new-password`,value:r.password,onChange:e=>i({...r,password:e.target.value})})})]}),(0,G.jsxs)(T,{children:[(0,G.jsx)(s,{type:`button`,variant:`outline`,onClick:()=>t(!1),children:`Cancel`}),(0,G.jsx)(s,{type:`submit`,loading:u.isPending,children:`Create account`})]})]})})})}function q(){ee(`Users`);let t=te(),a=re(),o=v(),u=ie(),[d]=ae(),[m,h]=(0,W.useState)(d.get(`q`)??``),[x,w]=(0,W.useState)(``),[T,D]=(0,W.useState)(1),[F,H]=(0,W.useState)(!1),q=ne(m.trim(),300),{data:J,isLoading:fe,error:Y,refetch:X}=r({queryKey:[`admin`,`users`,q,x,T],queryFn:()=>l.get(`/admin/users?${new URLSearchParams({...q?{q}:{},...x?{role:x}:{},page:String(T),pageSize:String(K)})}`),placeholderData:n}),Z=()=>a.invalidateQueries({queryKey:[`admin`]}),Q=g({mutationFn:({id:e,body:t})=>l.patch(`/admin/users/${e}`,t),onSuccess:async()=>{await Z(),L.success(`User updated`)},onError:e=>L.error(c(e))}),pe=g({mutationFn:e=>l.delete(`/admin/users/${e}`),onSuccess:async()=>{await Z(),L.success(`User deleted`)},onError:e=>L.error(c(e))}),me=g({mutationFn:e=>l.post(`/admin/users/${e}/impersonate`),onSuccess:async()=>{a.clear(),o(`/`)},onError:e=>L.error(c(e))}),$=J?Math.max(1,Math.ceil(J.total/K)):1;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`mb-5 flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,G.jsxs)(`div`,{className:`relative sm:w-80`,children:[(0,G.jsx)(le,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,G.jsx)(j,{value:m,onChange:e=>{h(e.target.value),D(1)},placeholder:`Search by name or email`,className:`pl-9`,"aria-label":`Search users`})]}),(0,G.jsx)(B,{value:x,onChange:e=>{w(e),D(1)},options:[{value:``,label:`Everyone`},{value:`student`,label:`Students`},{value:`instructor`,label:`Instructors`},{value:`admin`,label:`Admins`}]}),(0,G.jsxs)(s,{className:`sm:ml-auto`,onClick:()=>H(!0),children:[(0,G.jsx)(O,{}),` Add person`]})]}),Y?(0,G.jsx)(z,{error:Y,onRetry:()=>X()}):fe||!J?(0,G.jsx)(R,{className:`h-96`}):J.items.length===0?(0,G.jsx)(V,{icon:A,title:`No people found`}):(0,G.jsxs)(k,{className:`overflow-hidden`,children:[(0,G.jsx)(`div`,{className:`overflow-x-auto`,children:(0,G.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,G.jsx)(`thead`,{className:`border-b bg-muted/40 text-left text-xs text-muted-foreground`,children:(0,G.jsxs)(`tr`,{children:[(0,G.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Person`}),(0,G.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Role`}),(0,G.jsx)(`th`,{className:`hidden px-3 py-3 font-medium md:table-cell`,children:`Courses`}),(0,G.jsx)(`th`,{className:`hidden px-3 py-3 font-medium lg:table-cell`,children:`Last sign-in`}),(0,G.jsx)(`th`,{className:`w-12 px-3 py-3`})]})}),(0,G.jsx)(`tbody`,{className:`divide-y`,children:J.items.map(n=>(0,G.jsxs)(`tr`,{className:`hover:bg-accent/30`,children:[(0,G.jsx)(`td`,{className:`px-5 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,G.jsx)(b,{user:n,size:`sm`}),(0,G.jsxs)(`div`,{className:`min-w-0`,children:[(0,G.jsxs)(`p`,{className:`truncate font-medium`,children:[n.name,n.id===t?.id&&(0,G.jsx)(`span`,{className:`ml-1.5 text-xs font-normal text-muted-foreground`,children:`(you)`})]}),(0,G.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.email})]})]})}),(0,G.jsx)(`td`,{className:`px-3 py-3`,children:(0,G.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,G.jsx)(p,{variant:ue[n.role],children:i[n.role]}),n.status===`suspended`&&(0,G.jsx)(p,{variant:`danger`,children:`Suspended`})]})}),(0,G.jsx)(`td`,{className:`hidden px-3 py-3 text-muted-foreground tabular-nums md:table-cell`,children:n.courseCount}),(0,G.jsx)(`td`,{className:`hidden px-3 py-3 text-muted-foreground lg:table-cell`,children:n.lastLoginAt?e(n.lastLoginAt):`Never`}),(0,G.jsx)(`td`,{className:`px-3 py-3 text-right`,children:n.id!==t?.id&&(0,G.jsxs)(M,{children:[(0,G.jsx)(y,{asChild:!0,children:(0,G.jsx)(s,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${n.name}`,children:(0,G.jsx)(I,{})})}),(0,G.jsxs)(se,{className:`w-56`,children:[n.role!==`admin`&&n.status===`active`&&(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(_,{onSelect:()=>me.mutate(n.id),children:[(0,G.jsx)(U,{}),` Log in as `,n.name.split(` `)[0]]}),(0,G.jsx)(C,{})]}),(0,G.jsx)(oe,{children:`Site role`}),[`student`,`instructor`,`admin`].map(e=>(0,G.jsx)(f,{checked:n.role===e,onSelect:()=>Q.mutate({id:n.id,body:{role:e}}),children:i[e]},e)),(0,G.jsx)(C,{}),(0,G.jsxs)(_,{onSelect:()=>Q.mutate({id:n.id,body:{status:n.status===`active`?`suspended`:`active`}}),children:[n.status===`active`?(0,G.jsx)(N,{}):(0,G.jsx)(E,{}),n.status===`active`?`Suspend account`:`Reactivate account`]}),(0,G.jsxs)(_,{destructive:!0,onSelect:async()=>{await u({title:`Delete ${n.name}?`,description:`Their account, enrolments, submissions, grades and posts are permanently deleted.`,confirmLabel:`Delete account`,destructive:!0})&&pe.mutate(n.id)},children:[(0,G.jsx)(ce,{}),` Delete account`]})]})]})})]},n.id))})]})}),(0,G.jsxs)(`div`,{className:`flex items-center justify-between border-t px-5 py-3 text-sm text-muted-foreground`,children:[(0,G.jsxs)(`span`,{children:[J.total,` `,J.total===1?`person`:`people`]}),$>1&&(0,G.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,G.jsx)(s,{variant:`outline`,size:`icon-sm`,disabled:T<=1,onClick:()=>D(T-1),"aria-label":`Previous page`,children:(0,G.jsx)(P,{})}),(0,G.jsxs)(`span`,{className:`tabular-nums`,children:[T,` / `,$]}),(0,G.jsx)(s,{variant:`outline`,size:`icon-sm`,disabled:T>=$,onClick:()=>D(T+1),"aria-label":`Next page`,children:(0,G.jsx)(S,{})})]})]})]}),(0,G.jsx)(de,{open:F,onOpenChange:H,onDone:Z})]})}export{q as default};
@@ -1 +1 @@
1
- import{Q as e,Rt as t,g as n,j as r,rt as i,t as a,u as o,ut as s}from"./index-B29bTBiJ.js";import{D as c,T as l,U as u,dt as d,ft as f,g as p,h as m,m as h,mt as g,r as _,ut as v}from"./hooks-BBARn-DA.js";import{t as y}from"./send-mxSHcdcD.js";import{T as b,c as x,n as S,t as C}from"./misc-DvgDEI3I.js";import{n as w,r as T}from"./markdown-ykrkPMbn.js";import{r as E}from"./context-BLVW7NB7.js";var D=g(f(),1),O=d();function k(){let{course:d,can:f}=E();_(`Announcements · ${d.title}`);let g=v(),k=e(),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(``),P=[`announcements`,d.id],{data:F,isLoading:I,error:L,refetch:R}=u({queryKey:P,queryFn:()=>h.get(`/courses/${d.id}/announcements`)}),z=t({mutationFn:()=>h.post(`/courses/${d.id}/announcements`,{title:A,body:M}),onSuccess:async()=>{j(``),N(``),b.success(`Announcement posted. Everyone in the course has been notified.`),await g.invalidateQueries({queryKey:P})},onError:e=>b.error(m(e))}),B=t({mutationFn:e=>h.delete(`/courses/${d.id}/announcements/${e}`),onSuccess:()=>g.invalidateQueries({queryKey:P})});return(0,O.jsxs)(n,{size:`narrow`,children:[f(`announcement:post`)&&(0,O.jsx)(a,{className:`mb-8 p-5`,children:(0,O.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),z.mutate()},children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,O.jsx)(s,{className:`size-4 text-primary`}),` New announcement`]}),(0,O.jsx)(o,{value:A,onChange:e=>j(e.target.value),placeholder:`Title`,required:!0,"aria-label":`Announcement title`}),(0,O.jsx)(T,{value:M,onChange:N,rows:4,placeholder:`Write your message to the class…`}),(0,O.jsx)(`div`,{className:`flex justify-end`,children:(0,O.jsxs)(p,{type:`submit`,loading:z.isPending,disabled:!A.trim()||!M.trim(),children:[(0,O.jsx)(y,{}),` Post announcement`]})})]})}),L?(0,O.jsx)(S,{error:L,onRetry:()=>R()}):I?(0,O.jsxs)(`div`,{className:`space-y-4`,children:[(0,O.jsx)(x,{className:`h-36`}),(0,O.jsx)(x,{className:`h-36`})]}):F.length===0?(0,O.jsx)(C,{icon:s,title:`No announcements yet`,description:`Course news from your teachers will show up here.`}):(0,O.jsx)(`ol`,{className:`relative space-y-6 border-l pl-6`,children:F.map(e=>(0,O.jsxs)(`li`,{className:`relative`,children:[(0,O.jsx)(`span`,{className:`absolute top-5 -left-[31px] size-2.5 rounded-full bg-primary ring-4 ring-background`}),(0,O.jsxs)(a,{className:`p-5`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(r,{user:e.author,size:`sm`}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium`,children:e.author.name}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,title:l(e.createdAt),children:c(e.createdAt)})]}),f(`announcement:post`)&&(0,O.jsx)(p,{variant:`ghost`,size:`icon-sm`,"aria-label":`Delete announcement`,onClick:async()=>{await k({title:`Delete this announcement?`,confirmLabel:`Delete`,destructive:!0})&&B.mutate(e.id)},children:(0,O.jsx)(i,{})})]}),(0,O.jsx)(`h2`,{className:`mt-4 text-lg font-semibold tracking-tight`,children:e.title}),(0,O.jsx)(w,{source:e.body,className:`mt-2 prose-sm`})]})]},e.id))})]})}export{k as default};
1
+ import{$ as e,Gt as t,M as n,_ as r,at as i,ht as a,t as o,u as s}from"./index-CEZdqKdi.js";import{D as c,T as l,U as u,dt as d,ft as f,g as p,h as m,m as h,mt as g,r as _,ut as v}from"./hooks-EFhyJ5yU.js";import{t as y}from"./send-BnVkFV8w.js";import{E as b,c as x,n as S,t as C}from"./misc-CyGhN6HT.js";import{n as w,r as T}from"./markdown-HNlXovsL.js";import{r as E}from"./context-D8W_QqNi.js";var D=g(f(),1),O=d();function k(){let{course:d,can:f}=E();_(`Announcements · ${d.title}`);let g=v(),k=e(),[A,j]=(0,D.useState)(``),[M,N]=(0,D.useState)(``),P=[`announcements`,d.id],{data:F,isLoading:I,error:L,refetch:R}=u({queryKey:P,queryFn:()=>h.get(`/courses/${d.id}/announcements`)}),z=t({mutationFn:()=>h.post(`/courses/${d.id}/announcements`,{title:A,body:M}),onSuccess:async()=>{j(``),N(``),b.success(`Announcement posted. Everyone in the course has been notified.`),await g.invalidateQueries({queryKey:P})},onError:e=>b.error(m(e))}),B=t({mutationFn:e=>h.delete(`/courses/${d.id}/announcements/${e}`),onSuccess:()=>g.invalidateQueries({queryKey:P})});return(0,O.jsxs)(r,{size:`narrow`,children:[f(`announcement:post`)&&(0,O.jsx)(o,{className:`mb-8 p-5`,children:(0,O.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),z.mutate()},children:[(0,O.jsxs)(`div`,{className:`flex items-center gap-2 text-sm font-semibold`,children:[(0,O.jsx)(a,{className:`size-4 text-primary`}),` New announcement`]}),(0,O.jsx)(s,{value:A,onChange:e=>j(e.target.value),placeholder:`Title`,required:!0,"aria-label":`Announcement title`}),(0,O.jsx)(T,{value:M,onChange:N,rows:4,placeholder:`Write your message to the class…`}),(0,O.jsx)(`div`,{className:`flex justify-end`,children:(0,O.jsxs)(p,{type:`submit`,loading:z.isPending,disabled:!A.trim()||!M.trim(),children:[(0,O.jsx)(y,{}),` Post announcement`]})})]})}),L?(0,O.jsx)(S,{error:L,onRetry:()=>R()}):I?(0,O.jsxs)(`div`,{className:`space-y-4`,children:[(0,O.jsx)(x,{className:`h-36`}),(0,O.jsx)(x,{className:`h-36`})]}):F.length===0?(0,O.jsx)(C,{icon:a,title:`No announcements yet`,description:`Course news from your teachers will show up here.`}):(0,O.jsx)(`ol`,{className:`relative space-y-6 border-l pl-6`,children:F.map(e=>(0,O.jsxs)(`li`,{className:`relative`,children:[(0,O.jsx)(`span`,{className:`absolute top-5 -left-[31px] size-2.5 rounded-full bg-primary ring-4 ring-background`}),(0,O.jsxs)(o,{className:`p-5`,children:[(0,O.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,O.jsx)(n,{user:e.author,size:`sm`}),(0,O.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,O.jsx)(`p`,{className:`text-sm font-medium`,children:e.author.name}),(0,O.jsx)(`p`,{className:`text-xs text-muted-foreground`,title:l(e.createdAt),children:c(e.createdAt)})]}),f(`announcement:post`)&&(0,O.jsx)(p,{variant:`ghost`,size:`icon-sm`,"aria-label":`Delete announcement`,onClick:async()=>{await k({title:`Delete this announcement?`,confirmLabel:`Delete`,destructive:!0})&&B.mutate(e.id)},children:(0,O.jsx)(i,{})})]}),(0,O.jsx)(`h2`,{className:`mt-4 text-lg font-semibold tracking-tight`,children:e.title}),(0,O.jsx)(w,{source:e.body,className:`mt-2 prose-sm`})]})]},e.id))})]})}export{k as default};
@@ -0,0 +1 @@
1
+ import{$ as e,A as t,C as n,D as r,Dt as i,E as a,Ft as o,Gt as s,Ht as c,It as l,M as u,O as d,Wt as f,_ as p,at as m,dt as h,gt as g,k as _,l as v,lt as y,m as b,n as x,s as S,t as C,u as w}from"./index-CEZdqKdi.js";import{H as T,U as E,_ as D,dt as O,ft as k,g as A,h as j,m as M,mt as N,p as ee,r as P,s as F,t as te,u as ne,ut as re,w as I}from"./hooks-EFhyJ5yU.js";import{t as ie}from"./flag-DOzXVys0.js";import{n as L,t as R}from"./badge-dialog-p2zTk4h0.js";import{t as z}from"./library-Bcm33ouq.js";import{t as B}from"./pencil-DFUpj3YP.js";import{t as V}from"./rotate-ccw-yBj9Ri49.js";import{t as H}from"./user-minus-CkOPT3ak.js";import{E as U,c as W,n as G}from"./misc-CyGhN6HT.js";import{r as K,t as q}from"./badge-art-QPo-pYql.js";import{n as J,t as Y}from"./achievements-DaIfUTKU.js";import ae from"./NotFoundPage-BmwVsGAy.js";var X={name:`bot`,size:24,node:[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]};X.node;var oe=T(X),Z=N(k(),1),Q=O();function se(e,t){let n=te(t.trim(),250),r=e.course,i=E({queryKey:[`participants`,r?.id],queryFn:()=>M.get(`/courses/${r.id}/participants`),enabled:!!r}),a=E({queryKey:[`admin`,`users`,`award`,n],queryFn:()=>M.get(`/admin/users?${new URLSearchParams({q:n,status:`active`,pageSize:`30`})}`),enabled:!r});return{candidates:(0,Z.useMemo)(()=>{if(r){let e=t.trim().toLowerCase(),n={student:0,assistant:1,teacher:2};return(i.data??[]).filter(e=>e.status===`active`).filter(t=>!e||t.user.name.toLowerCase().includes(e)||t.user.email?.toLowerCase().includes(e)).sort((e,t)=>n[e.role]-n[t.role]||e.user.name.localeCompare(t.user.name)).map(e=>({id:e.user.id,name:e.user.name,avatarUrl:e.user.avatarUrl,detail:e.user.email??ne[e.role]}))}return(a.data?.items??[]).map(e=>({id:e.id,name:e.name,avatarUrl:e.avatarUrl,detail:e.email}))},[r,i.data,a.data,t]),isLoading:r?i.isLoading:a.isLoading}}function ce({badge:e,open:n,onOpenChange:i,onDone:o}){let[c,l]=(0,Z.useState)(``),[f,p]=(0,Z.useState)([]),[m,h]=(0,Z.useState)(``),{candidates:x,isLoading:C}=se(e,c),T=new Set((e.recipients??[]).filter(e=>!e.revokedAt).map(e=>e.user.id)),E=x.filter(e=>!T.has(e.id)),D=s({mutationFn:()=>M.post(`/badges/${e.id}/awards`,{userIds:f,note:m.trim()||null}),onSuccess:t=>{U.success(t.awarded?`Awarded “${e.name}” to ${t.awarded} ${t.awarded===1?`person`:`people`}`:`They already have this badge`),p([]),h(``),o(),i(!1)},onError:e=>U.error(j(e))});return(0,Q.jsx)(a,{open:n,onOpenChange:i,children:(0,Q.jsx)(d,{children:(0,Q.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),D.mutate()},children:[(0,Q.jsx)(t,{icon:(0,Q.jsx)(g,{className:`size-5`}),title:`Award “${e.name}”`,description:e.course?`Choose participants of the course. They get a notification.`:`Search for people on this site. They get a notification.`}),(0,Q.jsxs)(r,{className:`space-y-4`,children:[(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(y,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(w,{value:c,onChange:e=>l(e.target.value),placeholder:e.course?`Find a participant`:`Search by name or email`,className:`pl-9`,"aria-label":`Find people`,autoFocus:!0})]}),C?(0,Q.jsx)(W,{className:`h-48`}):(0,Q.jsxs)(`fieldset`,{className:`min-w-0`,children:[(0,Q.jsx)(`legend`,{className:`sr-only`,children:`People`}),(0,Q.jsxs)(`ul`,{className:`ck-scrollbar max-h-64 divide-y overflow-y-auto rounded-lg border`,children:[E.map(e=>{let t=`award-${e.id}`,n=f.includes(e.id);return(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-3 py-2`,children:[(0,Q.jsx)(S,{id:t,checked:n,onCheckedChange:t=>p(n=>t?[...n,e.id]:n.filter(t=>t!==e.id))}),(0,Q.jsx)(u,{user:e,size:`sm`}),(0,Q.jsxs)(`label`,{htmlFor:t,className:`min-w-0 flex-1 cursor-pointer`,children:[(0,Q.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.name}),(0,Q.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.detail})]})]},e.id)}),E.length===0&&(0,Q.jsx)(`li`,{className:`px-3 py-6 text-center text-sm text-muted-foreground`,children:c.trim()?`Nobody matches your search.`:`Everyone here already has this badge.`})]})]}),(0,Q.jsx)(v,{label:`Note`,optional:!0,hint:`Shown to the recipients on the badge, for example what they did.`,children:e=>(0,Q.jsx)(b,{...e,rows:2,maxLength:300,value:m,onChange:e=>h(e.target.value),className:`min-h-0`})})]}),(0,Q.jsxs)(_,{children:[(0,Q.jsxs)(`span`,{className:`mr-auto self-center text-sm text-muted-foreground`,children:[f.length,` selected`]}),(0,Q.jsx)(A,{type:`button`,variant:`outline`,onClick:()=>i(!1),children:`Cancel`}),(0,Q.jsx)(A,{type:`submit`,loading:D.isPending,disabled:f.length===0,children:`Award badge`})]})]})})})}function le({recipient:e,canAward:t,onRevoke:r,onRestore:i}){let a=!!e.revokedAt;return(0,Q.jsxs)(`li`,{className:D(`flex flex-col gap-3 px-5 py-3.5 sm:flex-row sm:items-center`,a&&`bg-muted/40`),children:[(0,Q.jsxs)(`div`,{className:`flex min-w-0 flex-1 items-center gap-3`,children:[(0,Q.jsx)(u,{user:e.user,size:`sm`,className:D(a&&`opacity-60`)}),(0,Q.jsxs)(`div`,{className:`min-w-0`,children:[(0,Q.jsxs)(`p`,{className:`flex flex-wrap items-center gap-x-2 truncate text-sm font-medium`,children:[e.user.name,a&&(0,Q.jsx)(n,{variant:`danger`,children:`Revoked`})]}),(0,Q.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[e.user.email&&(0,Q.jsxs)(`span`,{children:[e.user.email,` · `]}),e.awardedBy?`Awarded by ${e.awardedBy.name}`:`Awarded automatically`,` on`,` `,I(e.awardedAt,{year:`numeric`})]}),e.note&&(0,Q.jsxs)(`p`,{className:`mt-1 text-xs text-foreground/80 italic`,children:[`“`,e.note,`”`]})]})]}),t&&(0,Q.jsx)(`div`,{className:`shrink-0 pl-11 sm:pl-0`,children:a?(0,Q.jsxs)(A,{variant:`outline`,size:`sm`,onClick:i,children:[(0,Q.jsx)(V,{}),` Restore`]}):(0,Q.jsxs)(A,{variant:`ghost`,size:`sm`,className:`text-destructive hover:bg-destructive/10`,onClick:r,children:[(0,Q.jsx)(H,{}),` Revoke`]})})]})}function $({badge:t,onChange:n}){let r=e(),[i,a]=(0,Z.useState)(``),[o,c]=(0,Z.useState)(!1),l=t.recipients??[],u=(0,Z.useMemo)(()=>{let e=i.trim().toLowerCase();return l.filter(t=>!e||t.user.name.toLowerCase().includes(e)||t.user.email?.toLowerCase().includes(e))},[l,i]),d=l.filter(e=>!e.revokedAt).length,f=s({mutationFn:e=>M.delete(`/badges/${t.id}/awards/${e}`),onSuccess:async()=>{U.success(`Badge revoked`),await n()},onError:e=>U.error(j(e))}),p=s({mutationFn:e=>M.post(`/badges/${t.id}/awards`,{userIds:[e]}),onSuccess:async()=>{U.success(`Badge restored`),await n()},onError:e=>U.error(j(e))});return(0,Q.jsxs)(C,{className:`mt-6 overflow-hidden`,children:[(0,Q.jsx)(x,{title:`Recipients`,description:`${d} ${d===1?`person has`:`people have`} this badge${l.length>d?`, ${l.length-d} revoked`:``}.`,action:t.canAward&&(0,Q.jsxs)(A,{size:`sm`,onClick:()=>c(!0),children:[(0,Q.jsx)(h,{}),` Award badge`]})}),l.length>6&&(0,Q.jsx)(`div`,{className:`px-5 pb-3`,children:(0,Q.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,Q.jsx)(y,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(w,{value:i,onChange:e=>a(e.target.value),placeholder:`Find a recipient`,className:`pl-9`,"aria-label":`Find a recipient`})]})}),l.length===0?(0,Q.jsxs)(`div`,{className:`border-t px-5 py-10 text-center text-sm text-muted-foreground`,children:[`Nobody has this badge yet.`,t.criteria!==`manual`&&` It is awarded automatically as soon as someone qualifies.`]}):(0,Q.jsxs)(`ul`,{className:`divide-y border-t`,children:[u.map(e=>(0,Q.jsx)(le,{recipient:e,canAward:t.canAward,onRestore:()=>p.mutate(e.user.id),onRevoke:async()=>{await r({title:`Revoke the badge from ${e.user.name}?`,description:t.criteria===`manual`?`It disappears from their profile. You can restore it later.`:`It disappears from their profile and is not awarded to them automatically again. You can restore it later.`,confirmLabel:`Revoke`,destructive:!0})&&f.mutate(e.user.id)}},e.user.id)),u.length===0&&(0,Q.jsx)(`li`,{className:`px-5 py-6 text-center text-sm text-muted-foreground`,children:`Nobody matches your search.`})]}),o&&(0,Q.jsx)(ce,{badge:t,open:o,onOpenChange:c,onDone:()=>void n()})]})}function ue(){let{badgeId:t}=f(),n=F(),r=c(),a=re(),u=e(),[d,h]=(0,Z.useState)(!1),_=Y.badge(t??``),{data:v,isLoading:y,error:b,refetch:x}=E({queryKey:_,queryFn:()=>M.get(`/badges/${t}`),enabled:!!t});P(v?`${v.name} badge`:`Badge`);let S=v?.course?Y.courseBadges(v.course.slug):Y.siteBadges,w=()=>Promise.all([a.invalidateQueries({queryKey:_}),a.invalidateQueries({queryKey:S}),a.invalidateQueries({queryKey:Y.myBadges})]),T=s({mutationFn:()=>M.delete(`/badges/${t}`),onSuccess:async()=>{U.success(`Badge deleted`),await a.invalidateQueries({queryKey:S}),r(v?.course?`/courses/${v.course.slug}/badges`:`/admin/badges`)},onError:e=>U.error(j(e))});if(b instanceof ee&&b.status===404)return(0,Q.jsx)(ae,{});let D=v?.course?{to:`/courses/${v.course.slug}/badges`,label:`${v.course.title} badges`}:n?.role===`admin`?{to:`/admin/badges`,label:`Site badges`}:{to:`/profile`,label:`Your profile`},O=!!v&&(v.canAward||v.canManage),k=v?q[v.color]:null,N=v?.criteria===`completion`?ie:v?.criteria===`courses`?z:L;return(0,Q.jsxs)(p,{size:`narrow`,children:[(0,Q.jsx)(A,{asChild:!0,variant:`ghost`,size:`sm`,className:`-ml-2 mb-4`,children:(0,Q.jsxs)(l,{to:D.to,children:[(0,Q.jsx)(o,{}),` `,D.label]})}),b?(0,Q.jsx)(G,{error:b,onRetry:()=>x()}):y||!v?(0,Q.jsx)(W,{className:`h-64`}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)(C,{className:`overflow-hidden`,children:[(0,Q.jsxs)(`div`,{className:`flex flex-col items-center gap-6 px-6 py-8 text-center sm:flex-row sm:items-center sm:text-left`,style:k?{backgroundImage:`radial-gradient(circle at 12% 50%, ${k.from}33, transparent 45%)`}:void 0,children:[(0,Q.jsx)(K,{icon:v.icon,color:v.color,size:124,locked:!O&&!v.earnedAt,label:`${v.name} badge`}),(0,Q.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:v.course?(0,Q.jsxs)(Q.Fragment,{children:[`Course badge ·`,` `,(0,Q.jsx)(l,{to:`/courses/${v.course.slug}`,className:`hover:text-foreground hover:underline`,children:v.course.title})]}):`Site badge`}),(0,Q.jsx)(`h1`,{className:`mt-1 text-2xl font-semibold tracking-tight text-balance sm:text-[28px]`,children:v.name}),v.description&&(0,Q.jsx)(`p`,{className:`mt-2 text-[15px] text-muted-foreground`,children:v.description}),(0,Q.jsxs)(`p`,{className:`mt-3 inline-flex items-center gap-1.5 text-sm`,children:[(0,Q.jsx)(N,{className:`size-4 text-muted-foreground`}),` `,J(v)]}),v.canManage&&(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-wrap justify-center gap-2 sm:justify-start`,children:[(0,Q.jsxs)(A,{variant:`outline`,size:`sm`,onClick:()=>h(!0),children:[(0,Q.jsx)(B,{}),` Edit`]}),(0,Q.jsxs)(A,{variant:`ghost`,size:`sm`,className:`text-destructive hover:bg-destructive/10`,loading:T.isPending,onClick:async()=>{await u({title:`Delete “${v.name}”?`,description:`Everyone who has it loses it. This cannot be undone.`,confirmLabel:`Delete badge`,destructive:!0})&&T.mutate()},children:[(0,Q.jsx)(m,{}),` Delete`]})]})]})]}),v.earnedAt?(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 border-t bg-success/[0.07] px-6 py-3.5 text-sm`,children:[(0,Q.jsx)(i,{className:`mt-0.5 size-4 shrink-0 text-success`}),(0,Q.jsxs)(`p`,{children:[(0,Q.jsxs)(`span`,{className:`font-medium`,children:[`You earned this badge on `,I(v.earnedAt,{year:`numeric`}),`.`]}),v.earnedNote&&(0,Q.jsxs)(`span`,{className:`text-muted-foreground`,children:[` “`,v.earnedNote,`”`]})]})]}):!O&&(0,Q.jsxs)(`div`,{className:`flex items-start gap-2.5 border-t bg-muted/40 px-6 py-3.5 text-sm text-muted-foreground`,children:[v.criteria===`manual`?(0,Q.jsx)(g,{className:`mt-0.5 size-4 shrink-0`}):(0,Q.jsx)(oe,{className:`mt-0.5 size-4 shrink-0`}),(0,Q.jsx)(`p`,{children:v.criteria===`manual`?`You haven’t earned this badge yet.`:`You haven’t earned this badge yet. It is awarded automatically when you qualify.`})]})]}),v.recipients&&(0,Q.jsx)($,{badge:v,onChange:w}),d&&(0,Q.jsx)(R,{open:d,onOpenChange:h,scope:v.course?{kind:`course`,courseId:v.course.id}:{kind:`site`},badge:v,onSaved:e=>{a.setQueryData(_,e),w()}})]})]})}export{ue as default};
@@ -0,0 +1 @@
1
+ import{A as e,At as t,D as n,E as r,F as i,Gt as a,It as o,O as s,Ot as c,Tt as l,X as u,Y as d,Z as f,_ as p,a as m,at as h,dt as g,f as _,k as v,l as y,m as b,n as x,t as S,u as C}from"./index-CEZdqKdi.js";import{F as w,H as T,O as E,T as D,U as O,_ as k,dt as A,ft as j,g as M,h as N,k as P,m as F,mt as I,r as L,ut as R}from"./hooks-EFhyJ5yU.js";import{t as z}from"./chevron-left-Bu6IJANV.js";import{t as B}from"./flag-DOzXVys0.js";import{E as V,c as H}from"./misc-CyGhN6HT.js";var U={name:`video`,size:24,node:[[`path`,{d:`m16 13 5.223 3.482a.5.5 0 0 0 .777-.416V7.87a.5.5 0 0 0-.752-.432L16 10.5`,key:`ftymec`}],[`rect`,{x:`2`,y:`6`,width:`14`,height:`12`,rx:`2`,key:`158x01`}]]};U.node;var W=T(U),G=I(j(),1),K=A(),q=Array.from({length:7},(e,t)=>new Intl.DateTimeFormat(void 0,{weekday:`short`}).format(new Date(2024,0,1+t)));function J(e){let t=new Date(e.getFullYear(),e.getMonth(),1),n=(t.getDay()+6)%7;return new Date(t.getFullYear(),t.getMonth(),1-n)}var Y=e=>`${e.getFullYear()}-${e.getMonth()}-${e.getDate()}`;function X(e){if(e.kind===`personal`)return{background:`color-mix(in oklab, var(--primary) 14%, transparent)`,color:`var(--primary)`};let t=i(e.course?.coverColor??`slate`);return{background:`color-mix(in oklab, ${t.from} 16%, transparent)`,color:`color-mix(in oklab, ${t.to} 80%, var(--foreground))`}}function Z({kind:e}){return e===`due`?(0,K.jsx)(l,{className:`size-3 shrink-0`}):e===`course-start`||e===`course-end`?(0,K.jsx)(B,{className:`size-3 shrink-0`}):(0,K.jsx)(W,{className:`size-3 shrink-0`})}function Q({event:e,onDeleted:t}){let n=a({mutationFn:()=>F.delete(`/calendar/events/${e.id}`),onSuccess:t,onError:e=>V.error(N(e))});return(0,K.jsxs)(`div`,{className:`space-y-2`,children:[(0,K.jsx)(`p`,{className:`font-semibold leading-snug`,children:e.title}),(0,K.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[D(e.startsAt),e.endsAt&&` – ${E(e.endsAt)}`]}),e.course&&(0,K.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.course.title}),e.description&&(0,K.jsx)(`p`,{className:`text-sm`,children:e.description}),(0,K.jsxs)(`div`,{className:`flex gap-2 pt-1`,children:[e.link&&(0,K.jsx)(M,{asChild:!0,size:`xs`,variant:`outline`,children:(0,K.jsx)(o,{to:e.link,children:`Open`})}),e.canDelete&&(0,K.jsxs)(M,{size:`xs`,variant:`ghost`,className:`text-destructive`,onClick:()=>n.mutate(),loading:n.isPending,children:[(0,K.jsx)(h,{}),` Delete`]})]})]})}function $({open:i,onOpenChange:o,onCreated:c,defaultDate:l}){let{data:u}=O({queryKey:[`courses`,`mine`],queryFn:()=>F.get(`/courses/mine`)}),d=(u??[]).filter(e=>e.myRole===`teacher`),f=new Date(l);f.setHours(17,0,0,0);let[p,m]=(0,G.useState)({title:``,description:``,startsAt:w(f.toISOString()),endsAt:``,courseId:``}),h=a({mutationFn:()=>F.post(`/calendar/events`,{title:p.title,description:p.description||null,startsAt:P(p.startsAt),endsAt:P(p.endsAt),courseId:p.courseId||null}),onSuccess:()=>{V.success(`Event added`),c(),o(!1)},onError:e=>V.error(N(e))});return(0,K.jsx)(r,{open:i,onOpenChange:o,children:(0,K.jsx)(s,{children:(0,K.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),h.mutate()},children:[(0,K.jsx)(e,{icon:(0,K.jsx)(t,{className:`size-5`}),title:`New event`,description:`Personal events are only visible to you. Course events are shown to everyone in the course.`}),(0,K.jsxs)(n,{className:`space-y-4`,children:[(0,K.jsx)(y,{label:`Title`,children:e=>(0,K.jsx)(C,{...e,autoFocus:!0,required:!0,value:p.title,onChange:e=>m({...p,title:e.target.value})})}),(0,K.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,K.jsx)(y,{label:`Starts`,children:e=>(0,K.jsx)(C,{...e,type:`datetime-local`,required:!0,value:p.startsAt,onChange:e=>m({...p,startsAt:e.target.value})})}),(0,K.jsx)(y,{label:`Ends`,optional:!0,children:e=>(0,K.jsx)(C,{...e,type:`datetime-local`,value:p.endsAt,onChange:e=>m({...p,endsAt:e.target.value})})})]}),d.length>0&&(0,K.jsx)(y,{label:`Visible to`,children:e=>(0,K.jsxs)(_,{...e,value:p.courseId,onChange:e=>m({...p,courseId:e.target.value}),children:[(0,K.jsx)(`option`,{value:``,children:`Only me`}),d.map(e=>(0,K.jsxs)(`option`,{value:e.id,children:[`Everyone in `,e.title]},e.id))]})}),(0,K.jsx)(y,{label:`Notes`,optional:!0,children:e=>(0,K.jsx)(b,{...e,rows:3,value:p.description,onChange:e=>m({...p,description:e.target.value})})})]}),(0,K.jsxs)(v,{children:[(0,K.jsx)(M,{type:`button`,variant:`outline`,onClick:()=>o(!1),children:`Cancel`}),(0,K.jsx)(M,{type:`submit`,loading:h.isPending,children:`Add event`})]})]})})})}function ee(){L(`Calendar`);let e=R(),[t,n]=(0,G.useState)(()=>new Date(new Date().getFullYear(),new Date().getMonth(),1)),[r,i]=(0,G.useState)(null),a=J(t),s=new Date(a.getFullYear(),a.getMonth(),a.getDate()+42),l={from:a.toISOString(),to:s.toISOString()},h=[`calendar`,l.from,l.to],{data:_,isLoading:v}=O({queryKey:h,queryFn:()=>F.get(`/calendar?${new URLSearchParams(l)}`)}),y=()=>e.invalidateQueries({queryKey:[`calendar`]}),b=(0,G.useMemo)(()=>{let e=new Map;for(let t of _??[]){let n=Y(new Date(t.startsAt));e.set(n,[...e.get(n)??[],t])}return e},[_]),C=new Date,w=Array.from({length:42},(e,t)=>new Date(a.getFullYear(),a.getMonth(),a.getDate()+t)),T=(_??[]).filter(e=>new Date(e.startsAt)>=new Date(C.getFullYear(),C.getMonth(),C.getDate())).slice(0,8),D=new Intl.DateTimeFormat(void 0,{month:`long`,year:`numeric`}).format(t);return(0,K.jsxs)(p,{size:`wide`,children:[(0,K.jsx)(m,{title:`Calendar`,description:`Due dates, course events and your own reminders in one place.`,actions:(0,K.jsxs)(M,{onClick:()=>i(new Date),children:[(0,K.jsx)(g,{}),` New event`]})}),(0,K.jsxs)(`div`,{className:`grid items-start gap-6 xl:grid-cols-[minmax(0,1fr)_320px]`,children:[(0,K.jsxs)(S,{className:`overflow-hidden`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2 border-b px-5 py-3`,children:[(0,K.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:D}),(0,K.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,K.jsx)(M,{variant:`outline`,size:`sm`,onClick:()=>n(new Date(C.getFullYear(),C.getMonth(),1)),children:`Today`}),(0,K.jsx)(M,{variant:`ghost`,size:`icon-sm`,onClick:()=>n(new Date(t.getFullYear(),t.getMonth()-1,1)),"aria-label":`Previous month`,children:(0,K.jsx)(z,{})}),(0,K.jsx)(M,{variant:`ghost`,size:`icon-sm`,onClick:()=>n(new Date(t.getFullYear(),t.getMonth()+1,1)),"aria-label":`Next month`,children:(0,K.jsx)(c,{})})]})]}),(0,K.jsx)(`div`,{className:`grid grid-cols-7 border-b bg-muted/40 text-center text-xs font-medium text-muted-foreground`,children:q.map(e=>(0,K.jsx)(`div`,{className:`py-2`,children:e},e))}),v?(0,K.jsx)(H,{className:`h-[540px] rounded-none`}):(0,K.jsx)(`div`,{className:`grid grid-cols-7`,children:w.map((e,n)=>{let r=e.getMonth()===t.getMonth(),a=Y(e)===Y(C),o=b.get(Y(e))??[];return(0,K.jsxs)(`div`,{onDoubleClick:()=>i(e),className:k(`group min-h-24 border-r border-b p-1.5 sm:min-h-28`,(n+1)%7==0&&`border-r-0`,!r&&`bg-muted/30`),children:[(0,K.jsx)(`div`,{className:`mb-1 flex items-center justify-between`,children:(0,K.jsx)(`span`,{className:k(`grid size-6 place-items-center rounded-full text-xs tabular-nums`,!r&&`text-muted-foreground/60`,a&&`bg-primary font-semibold text-primary-foreground`),children:e.getDate()})}),(0,K.jsxs)(`div`,{className:`space-y-1`,children:[o.slice(0,3).map(e=>(0,K.jsxs)(d,{children:[(0,K.jsx)(f,{asChild:!0,children:(0,K.jsxs)(`button`,{className:`flex w-full items-center gap-1 truncate rounded-md px-1.5 py-0.5 text-left text-[11px] font-medium transition-opacity hover:opacity-80`,style:X(e),children:[(0,K.jsx)(Z,{kind:e.kind}),(0,K.jsx)(`span`,{className:`truncate`,children:e.title})]})}),(0,K.jsx)(u,{className:`w-64`,children:(0,K.jsx)(Q,{event:e,onDeleted:y})})]},e.id)),o.length>3&&(0,K.jsxs)(`p`,{className:`px-1.5 text-[11px] text-muted-foreground`,children:[`+`,o.length-3,` more`]})]})]},n)})})]}),(0,K.jsxs)(S,{children:[(0,K.jsx)(x,{title:`Coming up`,description:`The next things on your calendar.`}),(0,K.jsxs)(`div`,{className:`space-y-1 px-2 pb-3`,children:[T.length===0&&(0,K.jsx)(`p`,{className:`px-3 pb-3 text-sm text-muted-foreground`,children:`Nothing scheduled in this view.`}),T.map(e=>{let t=new Date(e.startsAt),n=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(`span`,{className:`flex w-11 shrink-0 flex-col items-center rounded-lg border bg-card py-1`,children:[(0,K.jsx)(`span`,{className:`text-[10px] font-semibold text-muted-foreground uppercase`,children:new Intl.DateTimeFormat(void 0,{month:`short`}).format(t)}),(0,K.jsx)(`span`,{className:`text-base leading-tight font-semibold tabular-nums`,children:t.getDate()})]}),(0,K.jsxs)(`span`,{className:`min-w-0`,children:[(0,K.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.title}),(0,K.jsxs)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:[E(e.startsAt),e.course&&` · ${e.course.title}`]})]})]});return e.link?(0,K.jsx)(o,{to:e.link,className:`flex items-center gap-3 rounded-lg px-3 py-2 hover:bg-accent/50`,children:n},e.id):(0,K.jsx)(`div`,{className:`flex items-center gap-3 rounded-lg px-3 py-2`,children:n},e.id)})]})]})]}),r&&(0,K.jsx)($,{open:!!r,onOpenChange:e=>!e&&i(null),onCreated:y,defaultDate:r})]})}export{ee as default};
@@ -1 +1 @@
1
- import{Q as e,U as t,_ as n,dt as r,f as i,ft as a,g as o,m as s,mt as c,r as l,s as u,t as d}from"./hooks-BBARn-DA.js";import{t as f}from"./chevron-left-D6IMQD6N.js";import{At as p,Mt as m,St as h,a as g,at as _,b as v,g as y,ot as b,u as x,vt as S,y as C}from"./index-B29bTBiJ.js";import{n as w,s as T,t as E}from"./misc-DvgDEI3I.js";var D=c(a(),1),O=r(),k=12;function A(){l(`Explore courses`);let r=u(),[a,c]=m(),A=a.get(`category`)??``,j=Number(a.get(`page`)??1),[M,N]=(0,D.useState)(a.get(`q`)??``),P=d(M.trim(),300);(0,D.useEffect)(()=>{c(e=>(P?e.set(`q`,P):e.delete(`q`),e.delete(`page`),e),{replace:!0})},[P,c]);let{data:F}=t({queryKey:[`categories`],queryFn:()=>s.get(`/categories`)}),{data:I,isLoading:L,error:R,refetch:z}=t({queryKey:[`catalog`,P,A,j],queryFn:()=>s.get(`/courses?${new URLSearchParams({...P?{q:P}:{},...A?{category:A}:{},page:String(j),pageSize:String(k)})}`),placeholderData:e}),B=e=>c(t=>(e?t.set(`category`,e):t.delete(`category`),t.delete(`page`),t)),V=e=>c(t=>(t.set(`page`,String(e)),t)),H=I?Math.max(1,Math.ceil(I.total/k)):1;return(0,O.jsxs)(y,{children:[(0,O.jsx)(g,{title:`Explore courses`,description:`Find your next course. Enrol in open courses instantly, or use an enrolment key from your teacher.`,actions:i(r?.role)&&(0,O.jsx)(o,{asChild:!0,children:(0,O.jsxs)(p,{to:`/courses/new`,children:[(0,O.jsx)(b,{}),` New course`]})})}),(0,O.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 lg:flex-row lg:items-center`,children:[(0,O.jsxs)(`div`,{className:`relative lg:w-80`,children:[(0,O.jsx)(_,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(x,{value:M,onChange:e=>N(e.target.value),placeholder:`Search by title or topic`,className:`h-10 pl-9`,"aria-label":`Search courses`})]}),(0,O.jsx)(T,{value:A,onChange:B,className:`lg:ml-auto`,options:[{value:``,label:`All`},...(F??[]).filter(e=>e.courseCount>0).map(e=>({value:e.id,label:e.name,count:e.courseCount}))]})]}),R?(0,O.jsx)(w,{error:R,onRetry:()=>z()}):L||!I?(0,O.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:Array.from({length:8},(e,t)=>(0,O.jsx)(v,{},t))}):I.items.length===0?(0,O.jsx)(E,{icon:S,title:P||A?`No courses match your search`:`No courses yet`,description:P||A?`Try a different keyword or category.`:`Published courses will appear here.`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`div`,{className:n(`grid gap-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:I.items.map(e=>(0,O.jsx)(C,{course:e,showProgress:e.myRole===`student`},e.id))}),H>1&&(0,O.jsxs)(`div`,{className:`mt-8 flex items-center justify-center gap-3`,children:[(0,O.jsxs)(o,{variant:`outline`,size:`sm`,disabled:j<=1,onClick:()=>V(j-1),children:[(0,O.jsx)(f,{}),` Previous`]}),(0,O.jsxs)(`span`,{className:`text-sm text-muted-foreground tabular-nums`,children:[`Page `,j,` of `,H]}),(0,O.jsxs)(o,{variant:`outline`,size:`sm`,disabled:j>=H,onClick:()=>V(j+1),children:[`Next `,(0,O.jsx)(h,{})]})]})]})]})}export{A as default};
1
+ import{Q as e,U as t,_ as n,dt as r,f as i,ft as a,g as o,m as s,mt as c,r as l,s as u,t as d}from"./hooks-EFhyJ5yU.js";import{t as f}from"./chevron-left-Bu6IJANV.js";import{It as p,Ot as m,Rt as h,_ as g,a as _,b as v,dt as y,lt as b,u as x,wt as S,x as C}from"./index-CEZdqKdi.js";import{n as w,s as T,t as E}from"./misc-CyGhN6HT.js";var D=c(a(),1),O=r(),k=12;function A(){l(`Explore courses`);let r=u(),[a,c]=h(),A=a.get(`category`)??``,j=Number(a.get(`page`)??1),[M,N]=(0,D.useState)(a.get(`q`)??``),P=d(M.trim(),300);(0,D.useEffect)(()=>{c(e=>(P?e.set(`q`,P):e.delete(`q`),e.delete(`page`),e),{replace:!0})},[P,c]);let{data:F}=t({queryKey:[`categories`],queryFn:()=>s.get(`/categories`)}),{data:I,isLoading:L,error:R,refetch:z}=t({queryKey:[`catalog`,P,A,j],queryFn:()=>s.get(`/courses?${new URLSearchParams({...P?{q:P}:{},...A?{category:A}:{},page:String(j),pageSize:String(k)})}`),placeholderData:e}),B=e=>c(t=>(e?t.set(`category`,e):t.delete(`category`),t.delete(`page`),t)),V=e=>c(t=>(t.set(`page`,String(e)),t)),H=I?Math.max(1,Math.ceil(I.total/k)):1;return(0,O.jsxs)(g,{children:[(0,O.jsx)(_,{title:`Explore courses`,description:`Find your next course. Enrol in open courses instantly, or use an enrolment key from your teacher.`,actions:i(r?.role)&&(0,O.jsx)(o,{asChild:!0,children:(0,O.jsxs)(p,{to:`/courses/new`,children:[(0,O.jsx)(y,{}),` New course`]})})}),(0,O.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 lg:flex-row lg:items-center`,children:[(0,O.jsxs)(`div`,{className:`relative lg:w-80`,children:[(0,O.jsx)(b,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,O.jsx)(x,{value:M,onChange:e=>N(e.target.value),placeholder:`Search by title or topic`,className:`h-10 pl-9`,"aria-label":`Search courses`})]}),(0,O.jsx)(T,{value:A,onChange:B,className:`lg:ml-auto`,options:[{value:``,label:`All`},...(F??[]).filter(e=>e.courseCount>0).map(e=>({value:e.id,label:e.name,count:e.courseCount}))]})]}),R?(0,O.jsx)(w,{error:R,onRetry:()=>z()}):L||!I?(0,O.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:Array.from({length:8},(e,t)=>(0,O.jsx)(C,{},t))}):I.items.length===0?(0,O.jsx)(E,{icon:S,title:P||A?`No courses match your search`:`No courses yet`,description:P||A?`Try a different keyword or category.`:`Published courses will appear here.`}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)(`div`,{className:n(`grid gap-5 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`),children:I.items.map(e=>(0,O.jsx)(v,{course:e,showProgress:e.myRole===`student`},e.id))}),H>1&&(0,O.jsxs)(`div`,{className:`mt-8 flex items-center justify-center gap-3`,children:[(0,O.jsxs)(o,{variant:`outline`,size:`sm`,disabled:j<=1,onClick:()=>V(j-1),children:[(0,O.jsx)(f,{}),` Previous`]}),(0,O.jsxs)(`span`,{className:`text-sm text-muted-foreground tabular-nums`,children:[`Page `,j,` of `,H]}),(0,O.jsxs)(o,{variant:`outline`,size:`sm`,disabled:j>=H,onClick:()=>V(j+1),children:[`Next `,(0,O.jsx)(m,{})]})]})]})]})}export{A as default};
@@ -0,0 +1,9 @@
1
+ import{Ft as e,Gt as t,It as n,Wt as r,ct as i}from"./index-CEZdqKdi.js";import{H as a,U as o,dt as s,ft as c,g as l,h as u,m as d,mt as f,p,r as m,s as h,ut as g,w as _}from"./hooks-EFhyJ5yU.js";import{t as v}from"./copy-B5IKRMFo.js";import{t as y}from"./rotate-ccw-yBj9Ri49.js";import{t as b}from"./shield-x-RpNHS0o8.js";import{E as x,c as S,n as C,t as w}from"./misc-CyGhN6HT.js";import{r as T,t as E}from"./certificate-sheet-DzW0lfzR.js";import{t as D}from"./revoke-dialog-DjBKaFTV.js";import{t as O}from"./achievements-DaIfUTKU.js";var k={name:`printer`,size:24,node:[[`path`,{d:`M6 18H4a2 2 0 0 1-2-2v-5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2v5a2 2 0 0 1-2 2h-2`,key:`143wyd`}],[`path`,{d:`M6 9V3a1 1 0 0 1 1-1h10a1 1 0 0 1 1 1v6`,key:`1itne7`}],[`rect`,{x:`6`,y:`14`,width:`12`,height:`8`,rx:`1`,key:`1ue0tg`}]]};k.node;var A=a(k),j=f(c(),1),M=s(),N=`
2
+ @page { size: A4 landscape; margin: 0; }
3
+ @media print {
4
+ html, body { background: #fff !important; }
5
+ .ck-print-hide { display: none !important; }
6
+ .ck-certificate-page, .ck-certificate-main { padding: 0 !important; margin: 0 !important; max-width: none !important; background: #fff !important; min-height: 0 !important; }
7
+ .ck-certificate { width: 297mm !important; height: 210mm !important; max-width: none !important; border-radius: 0 !important; box-shadow: none !important; break-inside: avoid; }
8
+ .ck-certificate * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
9
+ }`;function P(){let{certificateId:a}=r(),s=h(),c=g(),[f,k]=(0,j.useState)(!1),P=[`certificate`,a],{data:F,isLoading:I,error:L,refetch:R}=o({queryKey:P,queryFn:()=>d.get(`/certificates/${a}`),enabled:!!a});m(F?`Certificate · ${F.courseTitle}`:`Certificate`);let z=e=>{c.setQueryData(P,e),c.invalidateQueries({queryKey:O.myCertificates}),e.course&&c.invalidateQueries({queryKey:[`course`,e.course.slug]})},B=t({mutationFn:()=>d.post(`/certificates/${a}/restore`),onSuccess:e=>{x.success(`Certificate restored`),z(e)},onError:e=>x.error(u(e))}),V=F&&s?.id===F.recipient.id,H=F?.course&&!V?{to:`/courses/${F.course.slug}/completion`,label:F.course.title}:{to:`/profile`,label:`Your profile`};return(0,M.jsxs)(`div`,{className:`ck-certificate-page min-h-dvh bg-muted/70`,children:[(0,M.jsx)(`style`,{children:N}),(0,M.jsx)(`header`,{className:`ck-print-hide sticky top-0 z-10 border-b bg-background/85 backdrop-blur-lg`,children:(0,M.jsxs)(`div`,{className:`mx-auto flex max-w-[1180px] flex-wrap items-center gap-2 px-4 py-2.5 sm:px-6`,children:[(0,M.jsx)(l,{asChild:!0,variant:`ghost`,size:`sm`,className:`-ml-2 min-w-0`,children:(0,M.jsxs)(n,{to:H.to,children:[(0,M.jsx)(e,{}),` `,(0,M.jsx)(`span`,{className:`truncate`,children:H.label})]})}),F&&(0,M.jsxs)(`div`,{className:`ml-auto flex flex-wrap items-center gap-2`,children:[F.canManage&&(F.revokedAt?(0,M.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>B.mutate(),loading:B.isPending,children:[(0,M.jsx)(y,{}),` Restore`]}):(0,M.jsxs)(l,{variant:`outline`,size:`sm`,onClick:()=>k(!0),children:[(0,M.jsx)(b,{}),` Revoke`]})),!F.revokedAt&&(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)(l,{variant:`outline`,size:`sm`,onClick:async()=>{if(F)try{await navigator.clipboard.writeText(T(F.code)),x.success(`Verification link copied`)}catch{x.error(`Could not copy the link. Select it from the certificate instead.`)}},children:[(0,M.jsx)(v,{}),` `,(0,M.jsx)(`span`,{className:`hidden sm:inline`,children:`Copy verification link`}),(0,M.jsx)(`span`,{className:`sm:hidden`,children:`Copy link`})]}),(0,M.jsxs)(l,{size:`sm`,onClick:()=>window.print(),children:[(0,M.jsx)(A,{}),` Download PDF`]})]})]})]})}),(0,M.jsx)(`main`,{className:`ck-certificate-main mx-auto max-w-[1180px] px-4 py-6 sm:px-6 sm:py-10`,children:L?L instanceof p&&L.status===404?(0,M.jsx)(w,{icon:b,title:`Certificate not found`,description:`It may have been removed, or it belongs to someone else.`,action:(0,M.jsx)(l,{asChild:!0,variant:`outline`,children:(0,M.jsx)(n,{to:`/profile`,children:`Your certificates`})})}):(0,M.jsx)(C,{error:L,onRetry:()=>R()}):I||!F?(0,M.jsx)(S,{className:`aspect-[297/210] w-full`}):(0,M.jsxs)(M.Fragment,{children:[F.revokedAt?(0,M.jsxs)(`div`,{role:`status`,className:`ck-print-hide mb-5 flex items-start gap-3 rounded-xl border border-destructive/30 bg-destructive/[0.06] px-4 py-3 text-sm`,children:[(0,M.jsx)(b,{className:`mt-0.5 size-4.5 shrink-0 text-destructive`}),(0,M.jsxs)(`p`,{children:[(0,M.jsxs)(`span`,{className:`font-semibold`,children:[`This certificate was revoked on `,_(F.revokedAt,{year:`numeric`}),`.`]}),` `,F.revokeReason?`Reason: ${F.revokeReason}`:`It no longer counts as proof of completion.`]})]}):(0,M.jsxs)(`p`,{className:`ck-print-hide mb-5 flex items-center gap-2 text-sm text-muted-foreground`,children:[(0,M.jsx)(i,{className:`size-4 shrink-0 text-success`}),(0,M.jsxs)(`span`,{children:[`Anyone can check this certificate at`,` `,(0,M.jsxs)(n,{to:`/verify/${F.code}`,className:`font-medium text-foreground underline-offset-2 wrap-anywhere hover:underline`,children:[window.location.host,`/verify/`,F.code]})]})]}),(0,M.jsx)(E,{content:F,revoked:!!F.revokedAt}),!F.revokedAt&&(0,M.jsxs)(`p`,{className:`ck-print-hide mt-5 text-center text-xs text-muted-foreground`,children:[`Download PDF opens your browser’s print dialog: choose `,(0,M.jsx)(`span`,{className:`font-medium`,children:`Save as PDF`}),`. The page is set to A4 landscape.`]})]})}),F&&f&&(0,M.jsx)(D,{certificate:F,open:f,onOpenChange:k,onDone:z})]})}export{P as default};
@@ -0,0 +1 @@
1
+ import{C as e,Dt as t,Gt as n,H as r,It as i,J as a,M as o,T as s,V as c,_ as l,_t as u,lt as d,o as f,t as p,tt as m,u as h,y as g,z as _}from"./index-CEZdqKdi.js";import{U as v,_ as y,dt as b,ft as x,g as S,h as C,m as w,mt as T,r as E,ut as D,w as O}from"./hooks-EFhyJ5yU.js";import{t as k}from"./circle-dashed-D34ZjnSx.js";import{t as A}from"./clock-DPBmdKAi.js";import{t as j}from"./flag-DOzXVys0.js";import{t as M}from"./ellipsis-BDmYLoyn.js";import{t as N}from"./rotate-ccw-yBj9Ri49.js";import{t as P}from"./scroll-text-RmPlZi3F.js";import{t as F}from"./settings-BxdCrDf8.js";import{t as I}from"./shield-x-RpNHS0o8.js";import{E as L,a as R,c as z,n as B,s as V,t as H}from"./misc-CyGhN6HT.js";import{t as U}from"./revoke-dialog-DjBKaFTV.js";import{r as W,t as G}from"./achievements-DaIfUTKU.js";import{r as K}from"./context-D8W_QqNi.js";var q=T(x(),1),J=b();function Y(e){return e.completedAt?`completed`:e.activitiesDone>0||e.gradeMet?`progress`:`notStarted`}function X({row:n}){let r=Y(n);return r===`completed`?(0,J.jsxs)(e,{variant:`success`,children:[(0,J.jsx)(t,{}),` Completed `,O(n.completedAt)]}):r===`progress`?(0,J.jsxs)(e,{variant:`info`,children:[(0,J.jsx)(A,{}),` In progress`]}):(0,J.jsxs)(e,{variant:`neutral`,children:[(0,J.jsx)(k,{}),` Not started`]})}function Z({report:e,slug:t,canManage:n}){let[r,a]=(0,q.useState)(!1),o=[{label:`Students must complete`,value:`${e.mode===`all`?`All activities`:`Selected activities`} (${e.activities.length})`},{label:`Minimum course grade`,value:e.minGrade==null?`None`:W(e.minGrade)},{label:`Certificate`,value:e.certificateEnabled?`Issued on completion`:`Off`}];return(0,J.jsxs)(p,{className:`mt-4`,children:[(0,J.jsxs)(`div`,{className:`flex flex-col gap-4 p-5 md:flex-row md:items-start`,children:[(0,J.jsxs)(`div`,{className:`flex min-w-0 flex-1 gap-3`,children:[(0,J.jsx)(u,{className:`mt-0.5 size-4.5 shrink-0 text-muted-foreground`}),(0,J.jsx)(`dl`,{className:`grid min-w-0 flex-1 gap-3 sm:grid-cols-3`,children:o.map(e=>(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`dt`,{className:`text-xs font-medium text-muted-foreground`,children:e.label}),(0,J.jsx)(`dd`,{className:`mt-0.5 text-sm font-medium`,children:e.value})]},e.label))})]}),(0,J.jsxs)(`div`,{className:`flex shrink-0 flex-wrap gap-2 pl-7.5 md:pl-0`,children:[e.activities.length>0&&(0,J.jsx)(S,{variant:`ghost`,size:`sm`,onClick:()=>a(!r),"aria-expanded":r,"aria-controls":`completion-activities`,children:r?`Hide activities`:`Show activities`}),n&&(0,J.jsx)(S,{asChild:!0,variant:`outline`,size:`sm`,children:(0,J.jsxs)(i,{to:`/courses/${t}/settings#completion`,children:[(0,J.jsx)(F,{}),` Edit criteria`]})})]})]}),e.activities.length===0&&(0,J.jsx)(`p`,{className:`border-t px-5 py-3 text-sm text-muted-foreground`,children:`No activity counts towards completion yet: turn on completion tracking for some activities.`}),r&&(0,J.jsx)(`ul`,{id:`completion-activities`,className:`grid gap-1 border-t px-3 py-3 sm:grid-cols-2 lg:grid-cols-3`,children:e.activities.map(e=>(0,J.jsx)(`li`,{className:`min-w-0`,children:(0,J.jsxs)(i,{to:s(t,e.id),className:`flex items-center gap-2.5 rounded-lg px-2 py-1.5 text-sm hover:bg-accent/50 hover:text-primary`,children:[(0,J.jsx)(g,{type:e.type,size:`sm`}),(0,J.jsx)(`span`,{className:`truncate`,children:e.title})]})},e.id))})]})}function Q({report:e,slug:t}){let[n,r]=(0,q.useState)(``),[a,s]=(0,q.useState)(`all`),c=(0,q.useMemo)(()=>{let t=n.trim().toLowerCase();return e.rows.filter(e=>(a===`all`||Y(e)===a)&&(!t||e.user.name.toLowerCase().includes(t)||e.user.email.toLowerCase().includes(t)))},[e.rows,n,a]),l=e.minGrade!=null;return e.rows.length===0?(0,J.jsx)(H,{icon:m,title:`No students yet`,description:`Students appear here once they enrol in the course.`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,J.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,J.jsx)(d,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,J.jsx)(h,{value:n,onChange:e=>r(e.target.value),placeholder:`Find a student`,className:`pl-9`,"aria-label":`Find a student`})]}),(0,J.jsx)(V,{value:a,onChange:s,options:[{value:`all`,label:`All`,count:e.summary.students},{value:`completed`,label:`Completed`,count:e.summary.completed},{value:`progress`,label:`In progress`,count:e.summary.inProgress},{value:`notStarted`,label:`Not started`,count:e.summary.notStarted}]})]}),(0,J.jsx)(p,{className:`overflow-hidden`,children:(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,J.jsx)(`thead`,{className:`border-b bg-muted/40 text-left text-xs text-muted-foreground`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Student`}),(0,J.jsx)(`th`,{className:`hidden px-3 py-3 font-medium md:table-cell`,children:`Activities`}),l&&(0,J.jsx)(`th`,{className:`hidden px-3 py-3 font-medium sm:table-cell`,children:`Grade`}),(0,J.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Status`}),(0,J.jsx)(`th`,{className:`hidden px-3 py-3 font-medium lg:table-cell`,children:`Certificate`})]})}),(0,J.jsxs)(`tbody`,{className:`divide-y`,children:[c.map(e=>(0,J.jsxs)(`tr`,{className:`transition-colors hover:bg-accent/30`,children:[(0,J.jsx)(`td`,{className:`px-5 py-3`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(o,{user:e.user,size:`sm`}),(0,J.jsxs)(`div`,{className:`min-w-0`,children:[(0,J.jsx)(`p`,{className:`truncate font-medium`,children:e.user.name}),(0,J.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:e.user.email})]})]})}),(0,J.jsx)(`td`,{className:`hidden px-3 py-3 md:table-cell`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(R,{value:e.activitiesTotal?e.activitiesDone/e.activitiesTotal*100:0,className:`w-24`,tone:e.activitiesTotal>0&&e.activitiesDone===e.activitiesTotal?`success`:`primary`}),(0,J.jsxs)(`span`,{className:`text-xs whitespace-nowrap text-muted-foreground tabular-nums`,children:[e.activitiesDone,`/`,e.activitiesTotal]})]})}),l&&(0,J.jsx)(`td`,{className:`hidden px-3 py-3 tabular-nums sm:table-cell`,children:(0,J.jsx)(`span`,{className:y(e.gradeMet?`text-success`:e.grade==null?`text-muted-foreground`:`text-foreground`),children:W(e.grade)})}),(0,J.jsx)(`td`,{className:`px-3 py-3`,children:(0,J.jsx)(X,{row:e})}),(0,J.jsx)(`td`,{className:`hidden px-3 py-3 lg:table-cell`,children:e.certificate?(0,J.jsx)(i,{to:`/certificates/${e.certificate.id}`,className:y(`font-mono text-xs hover:text-primary hover:underline`,e.certificate.revoked&&`text-muted-foreground line-through`),children:e.certificate.code}):(0,J.jsx)(`span`,{className:`text-muted-foreground`,children:`–`})})]},e.user.id)),c.length===0&&(0,J.jsx)(`tr`,{children:(0,J.jsx)(`td`,{colSpan:5,className:`px-5 py-8 text-center text-muted-foreground`,children:`Nobody matches these filters.`})})]})]})})}),(0,J.jsxs)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:[(0,J.jsx)(i,{to:`/courses/${t}/participants`,className:`hover:underline`,children:`Manage participants`}),` `,`· Completion is permanent: changing the criteria later never takes it away.`]})]})}function $({slug:t,courseId:s,canManage:l}){let u=D(),[d,f]=(0,q.useState)(null),m=G.certificates(t),{data:h,isLoading:g,error:b,refetch:x}=v({queryKey:m,queryFn:()=>w.get(`/courses/${s}/certificates`)}),T=()=>Promise.all([u.invalidateQueries({queryKey:m}),u.invalidateQueries({queryKey:G.report(t)})]),E=n({mutationFn:e=>w.post(`/certificates/${e}/restore`),onSuccess:async()=>{L.success(`Certificate restored`),await T()},onError:e=>L.error(C(e))});return b?(0,J.jsx)(B,{error:b,onRetry:()=>x()}):g||!h?(0,J.jsx)(z,{className:`h-64`}):h.length===0?(0,J.jsx)(H,{icon:P,title:`No certificates yet`,description:`Certificates are issued automatically when students complete the course.`}):(0,J.jsxs)(p,{className:`overflow-hidden`,children:[(0,J.jsx)(`div`,{className:`overflow-x-auto`,children:(0,J.jsxs)(`table`,{className:`w-full text-sm`,children:[(0,J.jsx)(`thead`,{className:`border-b bg-muted/40 text-left text-xs text-muted-foreground`,children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{className:`px-5 py-3 font-medium`,children:`Recipient`}),(0,J.jsx)(`th`,{className:`px-3 py-3 font-medium`,children:`Code`}),(0,J.jsx)(`th`,{className:`hidden px-3 py-3 font-medium sm:table-cell`,children:`Completed`}),(0,J.jsx)(`th`,{className:`hidden px-3 py-3 font-medium md:table-cell`,children:`Status`}),(0,J.jsx)(`th`,{className:`w-12 px-3 py-3`})]})}),(0,J.jsx)(`tbody`,{className:`divide-y`,children:h.map(t=>(0,J.jsxs)(`tr`,{className:y(`transition-colors hover:bg-accent/30`,t.revokedAt&&`bg-muted/30`),children:[(0,J.jsx)(`td`,{className:`px-5 py-3`,children:(0,J.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,J.jsx)(o,{user:t.recipient,size:`sm`}),(0,J.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:t.recipientName})]})}),(0,J.jsx)(`td`,{className:`px-3 py-3`,children:(0,J.jsx)(i,{to:`/certificates/${t.id}`,className:`font-mono text-xs whitespace-nowrap hover:text-primary hover:underline`,children:t.code})}),(0,J.jsx)(`td`,{className:`hidden px-3 py-3 whitespace-nowrap text-muted-foreground sm:table-cell`,children:O(t.completedAt,{year:`numeric`})}),(0,J.jsx)(`td`,{className:`hidden px-3 py-3 md:table-cell`,children:t.revokedAt?(0,J.jsxs)(e,{variant:`danger`,title:t.revokeReason??void 0,children:[(0,J.jsx)(I,{}),` Revoked`]}):(0,J.jsx)(e,{variant:`success`,children:`Valid`})}),(0,J.jsx)(`td`,{className:`px-3 py-3 text-right`,children:(0,J.jsxs)(_,{children:[(0,J.jsx)(a,{asChild:!0,children:(0,J.jsx)(S,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${t.recipientName}’s certificate`,children:(0,J.jsx)(M,{})})}),(0,J.jsxs)(c,{children:[(0,J.jsx)(r,{asChild:!0,children:(0,J.jsxs)(i,{to:`/certificates/${t.id}`,children:[(0,J.jsx)(P,{}),` View certificate`]})}),l&&(t.revokedAt?(0,J.jsxs)(r,{onSelect:()=>E.mutate(t.id),children:[(0,J.jsx)(N,{}),` Restore`]}):(0,J.jsxs)(r,{destructive:!0,onSelect:()=>f(t),children:[(0,J.jsx)(I,{}),` Revoke…`]}))]})]})})]},t.id))})]})}),d&&(0,J.jsx)(U,{certificate:d,open:!!d,onOpenChange:e=>!e&&f(null),onDone:()=>void T()})]})}function ee(){let{course:e,can:n}=K();E(`Completion · ${e.title}`);let[r,a]=(0,q.useState)(`students`),o=n(`completion:manage`),{data:s,isLoading:c,error:u,refetch:d}=v({queryKey:G.report(e.slug),queryFn:()=>w.get(`/courses/${e.id}/completion/report`)});if(u)return(0,J.jsx)(l,{children:(0,J.jsx)(B,{error:u,onRetry:()=>d()})});if(c||!s)return(0,J.jsxs)(l,{children:[(0,J.jsx)(`div`,{className:`grid grid-cols-2 gap-3 sm:gap-4 lg:grid-cols-4`,children:[0,1,2,3].map(e=>(0,J.jsx)(z,{className:`h-24`},e))}),(0,J.jsx)(z,{className:`mt-6 h-96`})]});if(!s.enabled&&s.summary.completed===0)return(0,J.jsx)(l,{children:(0,J.jsx)(H,{icon:j,title:`Completion tracking is off`,description:`Choose what completes this course, such as finishing every activity or reaching a minimum grade, and optionally issue certificates.`,action:o&&(0,J.jsx)(S,{asChild:!0,children:(0,J.jsxs)(i,{to:`/courses/${e.slug}/settings#completion`,children:[(0,J.jsx)(F,{}),` Set up completion`]})})})});let{summary:p}=s,h=p.students?Math.round(p.completed/p.students*100):0;return(0,J.jsxs)(l,{children:[!s.enabled&&(0,J.jsxs)(`div`,{className:`mb-5 flex flex-wrap items-center gap-3 rounded-xl border border-warning/40 bg-warning/10 px-4 py-3 text-sm`,children:[(0,J.jsx)(j,{className:`size-4 text-warning`}),(0,J.jsx)(`span`,{className:`flex-1`,children:`Completion tracking is off, so no new completions are recorded. Earlier completions are kept.`}),o&&(0,J.jsx)(S,{asChild:!0,variant:`outline`,size:`sm`,children:(0,J.jsx)(i,{to:`/courses/${e.slug}/settings#completion`,children:`Turn it on`})})]}),(0,J.jsxs)(`div`,{className:`grid grid-cols-2 gap-3 sm:gap-4 lg:grid-cols-4`,children:[(0,J.jsx)(f,{icon:m,label:`Students`,value:p.students}),(0,J.jsx)(f,{icon:t,label:`Completed`,value:p.completed,hint:`${h}% of students`,tone:`emerald`}),(0,J.jsx)(f,{icon:A,label:`In progress`,value:p.inProgress,tone:`sky`}),(0,J.jsx)(f,{icon:k,label:`Not started`,value:p.notStarted,tone:`amber`})]}),(0,J.jsx)(Z,{report:s,slug:e.slug,canManage:o}),(0,J.jsxs)(`div`,{className:`mt-6 mb-4 flex flex-wrap items-center justify-between gap-3`,children:[(0,J.jsx)(V,{value:r,onChange:a,options:[{value:`students`,label:`Students`},{value:`certificates`,label:`Certificates`}]}),(0,J.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Checked whenever students finish activities or get grades, and when this page opens.`})]}),r===`students`?(0,J.jsx)(Q,{report:s,slug:e.slug}):(0,J.jsx)($,{slug:e.slug,courseId:e.id,canManage:o})]})}export{ee as default};
@@ -0,0 +1 @@
1
+ import{$ as e,Gt as t,H as n,J as r,V as i,_ as a,at as o,dt as s,gt as c,z as l}from"./index-CEZdqKdi.js";import{U as u,dt as d,ft as f,g as p,h as m,m as h,mt as g,r as _,ut as v}from"./hooks-EFhyJ5yU.js";import{t as y}from"./ellipsis-BDmYLoyn.js";import{t as b}from"./pencil-DFUpj3YP.js";import{E as x,n as S,t as C}from"./misc-CyGhN6HT.js";import{n as w,t as T}from"./badge-card-ByT0wR6q.js";import{t as E}from"./badge-dialog-p2zTk4h0.js";import{t as D}from"./achievements-DaIfUTKU.js";import{r as O}from"./context-D8W_QqNi.js";var k=g(f(),1),A=d();function j(){let{course:d,can:f}=O();_(`Badges · ${d.title}`);let g=v(),j=e(),M=f(`badges:manage`),N=M||f(`badges:award`),[P,F]=(0,k.useState)(null),I=D.courseBadges(d.slug),{data:L,isLoading:R,error:z,refetch:B}=u({queryKey:I,queryFn:()=>h.get(`/courses/${d.id}/badges`)}),V=()=>g.invalidateQueries({queryKey:I}),H=t({mutationFn:e=>h.delete(`/badges/${e}`),onSuccess:async()=>{x.success(`Badge deleted`),await V()},onError:e=>x.error(m(e))}),U=(L??[]).filter(e=>e.earnedAt).length;return(0,A.jsxs)(a,{children:[(0,A.jsxs)(`div`,{className:`mb-6 flex flex-col gap-3 sm:flex-row sm:items-end sm:justify-between`,children:[(0,A.jsxs)(`div`,{children:[(0,A.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:`Course badges`}),(0,A.jsx)(`p`,{className:`mt-0.5 text-sm text-muted-foreground`,children:N?`Recognise great work. Award badges by hand or automatically when students complete the course.`:L?.length?`You have earned ${U} of ${L.length} badges in this course.`:`Badges your teachers award for great work in this course.`})]}),M&&(0,A.jsxs)(p,{onClick:()=>F(`new`),children:[(0,A.jsx)(s,{}),` New badge`]})]}),z?(0,A.jsx)(S,{error:z,onRetry:()=>B()}):R||!L?(0,A.jsx)(w,{}):L.length===0?(0,A.jsx)(C,{icon:c,title:`No badges yet`,description:M?`Create a badge to celebrate milestones, great work or finishing the course.`:`Your teachers haven’t created any badges yet.`,action:M&&(0,A.jsxs)(p,{onClick:()=>F(`new`),children:[(0,A.jsx)(s,{}),` Create a badge`]})}):(0,A.jsx)(`div`,{className:`grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4`,children:L.map(e=>(0,A.jsx)(T,{badge:e,staff:N,actions:M&&(0,A.jsxs)(l,{children:[(0,A.jsx)(r,{asChild:!0,children:(0,A.jsx)(p,{variant:`ghost`,size:`icon-sm`,"aria-label":`Actions for ${e.name}`,children:(0,A.jsx)(y,{})})}),(0,A.jsxs)(i,{children:[(0,A.jsxs)(n,{onSelect:()=>F(e),children:[(0,A.jsx)(b,{}),` Edit`]}),(0,A.jsxs)(n,{destructive:!0,onSelect:async()=>{await j({title:`Delete “${e.name}”?`,description:`It is taken away from ${e.recipientCount??0} ${e.recipientCount===1?`person`:`people`}. This cannot be undone.`,confirmLabel:`Delete badge`,destructive:!0})&&H.mutate(e.id)},children:[(0,A.jsx)(o,{}),` Delete`]})]})]})},e.id))}),P&&(0,A.jsx)(E,{open:!!P,onOpenChange:e=>!e&&F(null),scope:{kind:`course`,courseId:d.id},badge:P===`new`?void 0:P,onSaved:()=>void V()})]})}export{j as default};
@@ -0,0 +1 @@
1
+ import{$ as e,A as t,C as n,Ct as r,D as i,Dt as a,E as o,G as s,Gt as c,H as l,It as u,J as d,K as f,Nt as p,O as m,Q as h,St as g,T as _,U as v,V as y,W as b,_ as x,at as ee,dt as S,ht as C,jt as w,k as T,l as E,m as D,n as O,q as k,t as A,u as j,w as te,y as ne,z as re}from"./index-CEZdqKdi.js";import{D as ie,H as M,M as N,S as ae,U as P,_ as F,dt as oe,ft as se,g as I,h as L,m as R,mt as ce,w as le,x as z}from"./hooks-EFhyJ5yU.js";import{n as B,t as V}from"./arrow-up-lI30bvj5.js";import{n as H,t as ue}from"./ActivityEditor-BNG3aTQa.js";import{t as de}from"./circle-dashed-D34ZjnSx.js";import{t as fe}from"./folder-input-M2p_UJZX.js";import{t as U}from"./ellipsis-BDmYLoyn.js";import{t as W}from"./pencil-DFUpj3YP.js";import{E as G,a as K,t as pe}from"./misc-CyGhN6HT.js";import{t as me}from"./flag-DOzXVys0.js";import{t as q}from"./scroll-text-RmPlZi3F.js";import{r as J,t as he}from"./achievements-DaIfUTKU.js";import{n as ge}from"./markdown-HNlXovsL.js";import{a as Y,r as _e}from"./context-D8W_QqNi.js";var X={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};X.node;var ve=M(X),Z={name:`party-popper`,size:24,node:[[`path`,{d:`M5.8 11.3 2 22l10.7-3.79`,key:`gwxi1d`}],[`path`,{d:`M4 3h.01`,key:`1vcuye`}],[`path`,{d:`M22 8h.01`,key:`1mrtc2`}],[`path`,{d:`M15 2h.01`,key:`1cjtqr`}],[`path`,{d:`M22 20h.01`,key:`1mrys2`}],[`path`,{d:`m22 2-2.24.75a2.9 2.9 0 0 0-1.96 3.12c.1.86-.57 1.63-1.45 1.63h-.38c-.86 0-1.6.6-1.76 1.44L14 10`,key:`hbicv8`}],[`path`,{d:`m22 13-.82-.33c-.86-.34-1.82.2-1.98 1.11c-.11.7-.72 1.22-1.43 1.22H17`,key:`1i94pl`}],[`path`,{d:`m11 2 .33.82c.34.86-.2 1.82-1.11 1.98C9.52 4.9 9 5.52 9 6.23V7`,key:`1cofks`}],[`path`,{d:`M11 13c1.93 1.93 2.83 4.17 2 5-.83.83-3.07-.07-5-2-1.93-1.93-2.83-4.17-2-5 .83-.83 3.07.07 5 2Z`,key:`4kbmks`}]]};Z.node;var ye=M(Z),Q=ce(se(),1),$=oe(),be=5;function xe({criterion:e,courseSlug:t}){let n=e.kind===`grade`?e.met:e.done;return(0,$.jsxs)(`li`,{className:`flex items-start gap-2.5 py-1.5`,children:[(0,$.jsx)(n?a:H,{className:F(`mt-0.5 size-4 shrink-0`,n?`text-success`:`text-muted-foreground/50`),"aria-hidden":!0}),(0,$.jsx)(`span`,{className:`sr-only`,children:n?`Done:`:`To do:`}),e.kind===`grade`?(0,$.jsxs)(`span`,{className:`min-w-0 text-sm`,children:[(0,$.jsxs)(`span`,{className:F(n&&`text-muted-foreground`),children:[`Course grade of at least `,J(e.minGrade)]}),(0,$.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:e.current==null?`Nothing graded yet`:`Your grade so far: ${J(e.current)}`})]}):(0,$.jsx)(u,{to:_(t,e.activityId),className:F(`min-w-0 text-sm hover:text-primary hover:underline`,n&&`text-muted-foreground line-through decoration-muted-foreground/40`),children:e.title})]})}function Se({status:e,courseSlug:t}){return(0,$.jsxs)(`div`,{className:`px-5 pb-5`,children:[(0,$.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl bg-success/[0.08] p-3.5 ring-1 ring-success/20`,children:[(0,$.jsx)(`span`,{className:`grid size-10 shrink-0 place-items-center rounded-full bg-success/15 text-success`,children:(0,$.jsx)(ye,{className:`size-5`})}),(0,$.jsxs)(`div`,{className:`min-w-0`,children:[(0,$.jsx)(`p`,{className:`text-sm font-semibold`,children:`You completed this course`}),(0,$.jsxs)(`p`,{className:`text-xs text-muted-foreground`,children:[`on `,le(e.completedAt,{year:`numeric`})]})]})]}),e.certificate&&(e.certificate.revoked?(0,$.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Your certificate for this course was revoked. Ask your teacher if you have questions.`}):(0,$.jsx)(I,{asChild:!0,variant:`outline`,className:`mt-3 w-full`,children:(0,$.jsxs)(u,{to:`/certificates/${e.certificate.id}`,children:[(0,$.jsx)(q,{}),` View certificate`]})})),(0,$.jsx)(I,{asChild:!0,variant:`ghost`,size:`sm`,className:`mt-1 w-full text-muted-foreground`,children:(0,$.jsxs)(u,{to:`/courses/${t}/badges`,children:[(0,$.jsx)(p,{}),` Course badges`]})})]})}function Ce({course:e}){let[t,n]=(0,Q.useState)(!1),r=e.myRole===`student`,{data:i}=P({queryKey:he.status(e.slug),queryFn:()=>R.get(`/courses/${e.id}/completion`),enabled:r});if(!r||!i||!i.enabled&&!i.completed)return null;let a=i.criteria.filter(e=>e.kind===`grade`?e.met:e.done).length,o=[...i.criteria].sort((e,t)=>Number(e.kind===`grade`?e.met:e.done)-Number(t.kind===`grade`?t.met:t.done)),s=t?o:o.slice(0,be);return(0,$.jsxs)(A,{children:[(0,$.jsx)(O,{title:`Course completion`,icon:(0,$.jsx)(me,{className:`size-4.5`}),action:!i.completed&&i.criteria.length>0&&(0,$.jsxs)(`span`,{className:`text-xs font-semibold tabular-nums`,children:[i.progress,`%`]})}),i.completed?(0,$.jsx)(Se,{status:i,courseSlug:e.slug}):(0,$.jsxs)(`div`,{className:`px-5 pb-5`,children:[i.criteria.length===0?(0,$.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`Your teacher is still setting up what completes this course.`}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(K,{value:i.progress}),(0,$.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[a,` of `,i.criteria.length,` requirements met`]}),(0,$.jsx)(`ul`,{className:`mt-2`,"aria-label":`Requirements`,children:s.map(t=>(0,$.jsx)(xe,{criterion:t,courseSlug:e.slug},t.kind===`grade`?`grade`:t.activityId))}),o.length>be&&(0,$.jsx)(`button`,{type:`button`,onClick:()=>n(!t),className:`mt-1 text-xs font-medium text-primary hover:underline`,"aria-expanded":t,children:t?`Show fewer`:`Show all ${o.length} requirements`})]}),i.certificateEnabled&&(0,$.jsxs)(`p`,{className:`mt-4 flex items-center gap-2 border-t pt-3 text-xs text-muted-foreground`,children:[(0,$.jsx)(q,{className:`size-3.5 shrink-0`}),` You’ll get a certificate when you complete the course.`]})]})]})}function we({activity:e,onToggle:t,busy:n}){return e.completion===`none`?null:e.completed?e.completion===`manual`?(0,$.jsx)(h,{content:`Completed. Click to undo`,children:(0,$.jsx)(`button`,{onClick:t,disabled:n,className:`text-success transition-transform hover:scale-110`,"aria-label":`Mark as not done`,children:(0,$.jsx)(a,{className:`size-5`})})}):(0,$.jsx)(h,{content:`Completed`,children:(0,$.jsx)(a,{className:`size-5 text-success`})}):e.completion===`manual`?(0,$.jsx)(h,{content:`Mark as done`,children:(0,$.jsx)(`button`,{onClick:t,disabled:n,className:`text-muted-foreground/50 transition-colors hover:text-success`,"aria-label":`Mark as done`,children:(0,$.jsx)(H,{className:`size-5`})})}):(0,$.jsx)(h,{content:`Completes automatically`,children:(0,$.jsx)(de,{className:`size-5 text-muted-foreground/40`})})}function Te({open:e,onOpenChange:n,course:r,section:a}){let[s,l]=(0,Q.useState)(a?.title??``),[u,d]=(0,Q.useState)(a?.summary??``),f=Y(),p=c({mutationFn:()=>a?R.patch(`/courses/${r.id}/sections/${a.id}`,{title:s,summary:u}):R.post(`/courses/${r.id}/sections`,{title:s,summary:u}),onSuccess:async()=>{await f(r.slug),n(!1),G.success(a?`Section updated`:`Section added`)},onError:e=>G.error(L(e))});return(0,$.jsx)(o,{open:e,onOpenChange:n,children:(0,$.jsx)(m,{children:(0,$.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),p.mutate()},children:[(0,$.jsx)(t,{title:a?`Edit section`:`New section`,description:`Sections group activities into weeks, topics or modules.`}),(0,$.jsxs)(i,{className:`space-y-4`,children:[(0,$.jsx)(E,{label:`Title`,children:e=>(0,$.jsx)(j,{...e,autoFocus:!0,required:!0,value:s,onChange:e=>l(e.target.value),placeholder:`Week 3: Working with data`})}),(0,$.jsx)(E,{label:`Summary`,optional:!0,children:e=>(0,$.jsx)(D,{...e,rows:3,value:u,onChange:e=>d(e.target.value),placeholder:`What students will do in this section`})})]}),(0,$.jsxs)(T,{children:[(0,$.jsx)(I,{type:`button`,variant:`outline`,onClick:()=>n(!1),children:`Cancel`}),(0,$.jsx)(I,{type:`submit`,loading:p.isPending,children:a?`Save`:`Add section`})]})]})})})}function Ee({activity:t,course:i,editing:a,isStudent:o,onEdit:p,onMove:m,onMoveTo:h}){let v=Y(),x=e(),S=c({mutationFn:()=>t.completed?R.delete(`/activities/${t.id}/complete`):R.post(`/activities/${t.id}/complete`),onSuccess:()=>v(i.slug),onError:e=>G.error(L(e))}),C=c({mutationFn:e=>R.patch(`/activities/${t.id}`,e),onSuccess:()=>v(i.slug),onError:e=>G.error(L(e))}),T=c({mutationFn:()=>R.delete(`/activities/${t.id}`),onSuccess:async()=>{await v(i.slug),G.success(`Activity deleted`)},onError:e=>G.error(L(e))}),E=o&&t.dueAt&&N(t.dueAt)&&!t.completed;return(0,$.jsxs)(`li`,{className:F(`group relative flex items-center gap-3.5 px-5 py-3 transition-colors hover:bg-accent/40`,!t.visible&&`bg-muted/40`),children:[(0,$.jsx)(ne,{type:t.type,className:F(!t.visible&&`opacity-50`)}),(0,$.jsxs)(u,{to:_(i.slug,t.id),className:`min-w-0 flex-1 after:absolute after:inset-0`,children:[(0,$.jsx)(`p`,{className:F(`truncate text-sm font-medium group-hover:text-primary`,!t.visible&&`text-muted-foreground`),children:t.title}),(0,$.jsxs)(`p`,{className:`mt-0.5 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground`,children:[(0,$.jsx)(`span`,{children:te[t.type].label}),t.meta&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/40`,children:`•`}),(0,$.jsx)(`span`,{children:t.meta})]}),t.dueAt&&(0,$.jsxs)($.Fragment,{children:[(0,$.jsx)(`span`,{className:`text-muted-foreground/40`,children:`•`}),(0,$.jsxs)(`span`,{className:F(`flex items-center gap-1`,E&&`font-medium text-destructive`),children:[(0,$.jsx)(w,{className:`size-3`}),z(t.dueAt,!o||t.completed)]})]})]})]}),!t.visible&&(0,$.jsxs)(n,{variant:`outline`,className:`relative`,children:[(0,$.jsx)(r,{}),` Hidden`]}),a?(0,$.jsxs)(`div`,{className:`relative flex items-center gap-0.5`,children:[(0,$.jsx)(I,{variant:`ghost`,size:`icon-sm`,onClick:p,"aria-label":`Edit activity`,children:(0,$.jsx)(W,{})}),(0,$.jsxs)(re,{children:[(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(I,{variant:`ghost`,size:`icon-sm`,"aria-label":`More actions`,children:(0,$.jsx)(U,{})})}),(0,$.jsxs)(y,{children:[(0,$.jsxs)(l,{onSelect:()=>m(-1),children:[(0,$.jsx)(V,{}),` Move up`]}),(0,$.jsxs)(l,{onSelect:()=>m(1),children:[(0,$.jsx)(B,{}),` Move down`]}),(0,$.jsxs)(s,{children:[(0,$.jsxs)(k,{children:[(0,$.jsx)(fe,{}),` Move to section`]}),(0,$.jsx)(f,{children:i.sections.filter(e=>e.id!==t.sectionId).map(e=>(0,$.jsx)(l,{onSelect:()=>h(e.id),children:e.title},e.id))})]}),(0,$.jsxs)(l,{onSelect:()=>C.mutate({visible:!t.visible}),children:[t.visible?(0,$.jsx)(r,{}):(0,$.jsx)(g,{}),` `,t.visible?`Hide from students`:`Show to students`]}),(0,$.jsx)(b,{}),(0,$.jsxs)(l,{destructive:!0,onSelect:async()=>{await x({title:`Delete “${t.title}”?`,description:`This removes the activity and all of its submissions, attempts, posts and grades.`,confirmLabel:`Delete`,destructive:!0})&&T.mutate()},children:[(0,$.jsx)(ee,{}),` Delete`]})]})]})]}):o&&(0,$.jsx)(`span`,{className:`relative`,children:(0,$.jsx)(we,{activity:t,onToggle:()=>S.mutate(),busy:S.isPending})})]})}function De({section:t,index:i,course:o,editing:s,isStudent:u,onAddActivity:f,onEditActivity:p}){let[m,h]=(0,Q.useState)(!0),[_,x]=(0,Q.useState)(!1),C=Y(),w=e(),T=t.activities.filter(e=>e.visible&&e.completion!==`none`),E=T.filter(e=>e.completed).length,D=c({mutationFn:e=>e(),onSuccess:()=>C(o.slug),onError:e=>G.error(L(e))}),O=e=>{let t=o.sections.map(e=>e.id),n=i+e;n<0||n>=t.length||([t[i],t[n]]=[t[n],t[i]],D.mutate(()=>R.put(`/courses/${o.id}/sections/order`,{ids:t})))},k=(e,n)=>{let r=t.activities.map(e=>e.id),i=r.indexOf(e),a=i+n;a<0||a>=r.length||([r[i],r[a]]=[r[a],r[i]],D.mutate(()=>R.put(`/courses/${o.id}/activities/order`,{sectionId:t.id,ids:r})))},j=(e,t)=>{let n=o.sections.find(e=>e.id===t);if(!n)return;let r=[...n.activities.map(e=>e.id),e];D.mutate(()=>R.put(`/courses/${o.id}/activities/order`,{sectionId:t,ids:r}))};return(0,$.jsxs)(A,{className:F(`overflow-hidden`,!t.visible&&`border-dashed`),children:[(0,$.jsxs)(`div`,{className:`flex items-start gap-3 px-5 py-4`,children:[(0,$.jsxs)(`button`,{onClick:()=>h(!m),className:`flex min-w-0 flex-1 items-start gap-3 text-left`,"aria-expanded":m,children:[(0,$.jsx)(`span`,{className:F(`mt-0.5 grid size-7 shrink-0 place-items-center rounded-full text-xs font-semibold`,u&&T.length>0&&E===T.length?`bg-success text-white`:`bg-muted text-muted-foreground`),children:u&&T.length>0&&E===T.length?(0,$.jsx)(a,{className:`size-4`}):i+1}),(0,$.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,$.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,$.jsx)(`span`,{className:`truncate text-[15px] font-semibold tracking-tight`,children:t.title}),!t.visible&&(0,$.jsxs)(n,{variant:`outline`,children:[(0,$.jsx)(r,{}),` Hidden`]})]}),t.summary&&(0,$.jsx)(`span`,{className:`mt-0.5 block text-sm text-muted-foreground`,children:t.summary})]})]}),(0,$.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[u&&T.length>0&&(0,$.jsxs)(`span`,{className:`hidden items-center gap-2 text-xs text-muted-foreground sm:flex`,children:[(0,$.jsx)(K,{value:E/T.length*100,className:`w-16`,tone:E===T.length?`success`:`primary`}),E,`/`,T.length]}),s&&(0,$.jsxs)(re,{children:[(0,$.jsx)(d,{asChild:!0,children:(0,$.jsx)(I,{variant:`ghost`,size:`icon-sm`,"aria-label":`Section actions`,children:(0,$.jsx)(U,{})})}),(0,$.jsxs)(y,{children:[(0,$.jsx)(v,{children:`Section`}),(0,$.jsxs)(l,{onSelect:()=>x(!0),children:[(0,$.jsx)(W,{}),` Rename`]}),(0,$.jsxs)(l,{onSelect:()=>O(-1),disabled:i===0,children:[(0,$.jsx)(V,{}),` Move up`]}),(0,$.jsxs)(l,{onSelect:()=>O(1),disabled:i===o.sections.length-1,children:[(0,$.jsx)(B,{}),` Move down`]}),(0,$.jsxs)(l,{onSelect:()=>D.mutate(()=>R.patch(`/courses/${o.id}/sections/${t.id}`,{visible:!t.visible})),children:[t.visible?(0,$.jsx)(r,{}):(0,$.jsx)(g,{}),` `,t.visible?`Hide section`:`Show section`]}),(0,$.jsx)(b,{}),(0,$.jsxs)(l,{destructive:!0,onSelect:async()=>{await w({title:`Delete “${t.title}”?`,description:`This also deletes its ${t.activities.length} activities and everything students submitted to them.`,confirmLabel:`Delete section`,destructive:!0})&&D.mutate(()=>R.delete(`/courses/${o.id}/sections/${t.id}`))},children:[(0,$.jsx)(ee,{}),` Delete`]})]})]}),(0,$.jsx)(`button`,{onClick:()=>h(!m),className:`text-muted-foreground`,"aria-label":m?`Collapse section`:`Expand section`,children:(0,$.jsx)(ve,{className:F(`size-4.5 transition-transform`,!m&&`-rotate-90`)})})]})]}),m&&(0,$.jsxs)($.Fragment,{children:[t.activities.length>0?(0,$.jsx)(`ul`,{className:`divide-y border-t`,children:t.activities.map(e=>(0,$.jsx)(Ee,{activity:e,course:o,editing:s,isStudent:u,onEdit:()=>p(e.id),onMove:t=>k(e.id,t),onMoveTo:t=>j(e.id,t)},e.id))}):!s&&(0,$.jsx)(`p`,{className:`border-t px-5 py-4 text-sm text-muted-foreground`,children:`Nothing here yet.`}),s&&(0,$.jsx)(`div`,{className:`border-t p-2`,children:(0,$.jsxs)(`button`,{onClick:f,className:`flex w-full items-center justify-center gap-2 rounded-lg border border-dashed py-2.5 text-sm font-medium text-muted-foreground transition-colors hover:border-primary/50 hover:bg-primary/[0.03] hover:text-primary`,children:[(0,$.jsx)(S,{className:`size-4`}),` Add activity`]})})]}),_&&(0,$.jsx)(Te,{open:_,onOpenChange:x,course:o,section:t})]})}function Oe(){let{course:e,editing:t}=_e(),[n,r]=(0,Q.useState)(null),[i,a]=(0,Q.useState)(!1),o=e.myRole===`student`,{data:s}=P({queryKey:[`announcements`,e.id],queryFn:()=>R.get(`/courses/${e.id}/announcements`)}),c=e.sections.flatMap(e=>e.activities).filter(e=>e.dueAt&&!N(e.dueAt)&&e.visible).sort((e,t)=>e.dueAt.localeCompare(t.dueAt)).slice(0,4);return(0,$.jsxs)(x,{children:[t&&(0,$.jsxs)(`div`,{className:`mb-5 flex items-center gap-3 rounded-xl border border-primary/30 bg-primary/[0.05] px-4 py-3 text-sm`,children:[(0,$.jsx)(W,{className:`size-4 text-primary`}),(0,$.jsxs)(`span`,{children:[(0,$.jsx)(`span`,{className:`font-medium`,children:`Edit mode is on.`}),` Add, reorder, hide or delete sections and activities.`]})]}),(0,$.jsxs)(`div`,{className:`grid grid-cols-1 items-start gap-8 lg:grid-cols-[minmax(0,1fr)_300px]`,children:[(0,$.jsxs)(`div`,{className:`space-y-4`,children:[e.sections.length===0&&(0,$.jsx)(pe,{icon:S,title:`This course is empty`,description:`Turn on edit mode to add the first section.`}),e.sections.map((n,i)=>(0,$.jsx)(De,{section:n,index:i,course:e,editing:t,isStudent:o,onAddActivity:()=>r({sectionId:n.id}),onEditActivity:e=>r({activityId:e})},n.id)),t&&(0,$.jsxs)(I,{variant:`outline`,className:`w-full border-dashed`,size:`lg`,onClick:()=>a(!0),children:[(0,$.jsx)(S,{}),` Add section`]})]}),(0,$.jsxs)(`aside`,{className:`space-y-5 lg:sticky lg:top-32`,children:[(0,$.jsx)(Ce,{course:e}),c.length>0&&(0,$.jsxs)(A,{children:[(0,$.jsx)(O,{title:`Coming up`,icon:(0,$.jsx)(w,{className:`size-4.5`})}),(0,$.jsx)(`div`,{className:`space-y-1 px-2 pb-3`,children:c.map(t=>(0,$.jsxs)(u,{to:_(e.slug,t.id),className:`flex items-center gap-3 rounded-lg px-3 py-2 hover:bg-accent/50`,children:[(0,$.jsx)(ne,{type:t.type,size:`sm`}),(0,$.jsxs)(`span`,{className:`min-w-0`,children:[(0,$.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:t.title}),(0,$.jsx)(`span`,{className:`block text-xs text-muted-foreground`,children:z(t.dueAt)})]})]},t.id))})]}),(0,$.jsxs)(A,{children:[(0,$.jsx)(O,{title:`Latest news`,icon:(0,$.jsx)(C,{className:`size-4.5`}),action:(0,$.jsx)(u,{to:`/courses/${e.slug}/announcements`,className:`text-xs font-medium text-primary hover:underline`,children:`View all`})}),(0,$.jsxs)(`div`,{className:`space-y-1 px-2 pb-3`,children:[(s??[]).slice(0,2).map(t=>(0,$.jsxs)(u,{to:`/courses/${e.slug}/announcements`,className:`block rounded-lg px-3 py-2 hover:bg-accent/50`,children:[(0,$.jsx)(`p`,{className:`text-sm font-medium`,children:t.title}),(0,$.jsx)(`p`,{className:`mt-0.5 line-clamp-2 text-xs text-muted-foreground`,children:ae(t.body)}),(0,$.jsx)(`p`,{className:`mt-1 text-[11px] text-muted-foreground`,children:ie(t.createdAt)})]},t.id)),s?.length===0&&(0,$.jsx)(`p`,{className:`px-3 pb-2 text-sm text-muted-foreground`,children:`No announcements yet.`})]})]}),e.description&&(0,$.jsxs)(A,{children:[(0,$.jsx)(O,{title:`Overview`}),(0,$.jsx)(`div`,{className:`max-h-72 overflow-hidden px-5 pb-5 [mask-image:linear-gradient(to_bottom,black_75%,transparent)]`,children:(0,$.jsx)(ge,{source:e.description,className:`prose-sm`})})]})]})]}),n&&(0,$.jsx)(ue,{course:e,open:!!n,onOpenChange:e=>!e&&r(null),sectionId:n.sectionId,activityId:n.activityId}),i&&(0,$.jsx)(Te,{open:i,onOpenChange:a,course:e})]})}export{Oe as default};
@@ -0,0 +1 @@
1
+ import{Bt as e,Gt as t,It as n,Lt as r,Mt as i,N as a,Nt as o,Ot as s,Pt as c,S as l,T as u,Wt as d,_ as f,gt as p,ht as m,kt as h,n as g,t as _,tt as v,u as y,w as b,y as x}from"./index-CEZdqKdi.js";import{t as S}from"./calendar-range-Cfg-P4Md.js";import{t as C}from"./flag-DOzXVys0.js";import{t as w}from"./key-round-fzvV-etw.js";import{t as T}from"./lock-C2edVDOc.js";import{t as ee}from"./pencil-DFUpj3YP.js";import{t as E}from"./settings-BxdCrDf8.js";import{t as D}from"./users-round-CNhv0Whm.js";import{t as O}from"./library-Bcm33ouq.js";import{N as k,_ as A,dt as j,ft as M,g as N,h as P,m as F,mt as I,p as L,r as R,u as z,w as B}from"./hooks-EFhyJ5yU.js";import{E as V,c as H,n as U,o as W}from"./misc-CyGhN6HT.js";import{n as G}from"./markdown-HNlXovsL.js";import K from"./NotFoundPage-BmwVsGAy.js";import{a as q,i as J,n as Y,t as X}from"./context-D8W_QqNi.js";var Z=I(M(),1),Q=j();function $({course:e}){return(0,Q.jsxs)(`div`,{className:`mt-5 flex flex-wrap items-center gap-x-5 gap-y-2 text-sm text-white/85`,children:[e.teachers.length>0&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,Q.jsx)(a,{users:e.teachers,max:3,size:`xs`}),e.teachers.map(e=>e.name).join(`, `)]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(v,{className:`size-4`}),` `,k(e.studentCount,`student`)]}),(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(i,{className:`size-4`}),` `,k(e.activityCount,`activity`,`activities`)]}),(e.startDate||e.endDate)&&(0,Q.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,Q.jsx)(S,{className:`size-4`}),` `,B(e.startDate),` – `,B(e.endDate)]})]})}function te({course:e,editing:t,setEditing:r}){let i=e.capabilities.includes(`course:manageContent`),a=X(e).filter(e=>e.visible&&e.completion!==`none`),o=a.filter(e=>e.completed).length,d=e.myRole===`student`?Y(e):null;return(0,Q.jsxs)(l,{color:e.coverColor,imageUrl:e.coverImageUrl,className:`text-white`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-black/25 to-transparent`}),(0,Q.jsxs)(`div`,{className:`relative mx-auto max-w-7xl px-4 pt-6 pb-8 sm:px-6 lg:px-8 lg:pt-8`,children:[(0,Q.jsxs)(`nav`,{className:`flex items-center gap-1.5 text-[13px] text-white/75`,children:[(0,Q.jsx)(n,{to:`/catalog`,className:`hover:text-white`,children:`Courses`}),e.categoryName&&(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)(s,{className:`size-3.5`}),(0,Q.jsx)(n,{to:`/catalog?category=${e.categoryId}`,className:`hover:text-white`,children:e.categoryName})]})]}),(0,Q.jsxs)(`div`,{className:`mt-4 flex flex-col gap-6 lg:flex-row lg:items-end lg:justify-between`,children:[(0,Q.jsxs)(`div`,{className:`max-w-3xl min-w-0`,children:[(0,Q.jsxs)(`div`,{className:`mb-3 flex flex-wrap gap-2`,children:[e.visibility!==`published`&&(0,Q.jsx)(`span`,{className:`rounded-full bg-white px-2.5 py-0.5 text-xs font-semibold text-slate-900 capitalize`,children:e.visibility}),e.myRole&&(0,Q.jsx)(`span`,{className:`rounded-full bg-white/20 px-2.5 py-0.5 text-xs font-medium backdrop-blur`,children:z[e.myRole]})]}),(0,Q.jsx)(`h1`,{className:`text-3xl font-semibold tracking-tight text-balance sm:text-4xl`,children:e.title}),e.summary&&(0,Q.jsx)(`p`,{className:`mt-2.5 max-w-2xl text-[15px] leading-relaxed text-white/85`,children:e.summary}),(0,Q.jsx)($,{course:e})]}),(0,Q.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-3`,children:[e.progress!=null&&(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 rounded-xl bg-black/15 py-2.5 pr-4 pl-2.5 ring-1 ring-white/20 backdrop-blur-md`,children:[(0,Q.jsx)(W,{value:e.progress,size:46,className:`text-white`}),(0,Q.jsxs)(`div`,{className:`text-sm`,children:[(0,Q.jsx)(`p`,{className:`font-semibold`,children:`Your progress`}),(0,Q.jsxs)(`p`,{className:`text-white/75`,children:[o,` of `,a.length,` done`]})]})]}),d&&(0,Q.jsx)(N,{asChild:!0,className:`bg-white text-slate-900 shadow-lg hover:bg-white/90 hover:brightness-100`,size:`lg`,children:(0,Q.jsxs)(n,{to:u(e.slug,d.id),children:[`Continue `,(0,Q.jsx)(c,{})]})}),i&&(0,Q.jsxs)(N,{size:`lg`,onClick:()=>r(!t),className:A(`hover:brightness-100`,t?`bg-white text-slate-900 hover:bg-white/90`:`bg-white/15 text-white ring-1 ring-white/25 backdrop-blur hover:bg-white/25`),children:[t?(0,Q.jsx)(h,{}):(0,Q.jsx)(ee,{}),t?`Done editing`:`Edit course`]})]})]})]})]})}function ne({course:e}){let[n,r]=(0,Z.useState)(``),i=q(),a=t({mutationFn:()=>F.post(`/courses/${e.id}/enrol`,e.hasEnrolmentKey?{key:n}:{}),onSuccess:async()=>{V.success(`You're enrolled in ${e.title}. Have fun!`),await i(e.slug)},onError:e=>V.error(P(e))});return(0,Q.jsxs)(`div`,{children:[(0,Q.jsxs)(l,{color:e.coverColor,imageUrl:e.coverImageUrl,className:`text-white`,children:[(0,Q.jsx)(`div`,{className:`absolute inset-0 bg-gradient-to-t from-black/25 to-transparent`}),(0,Q.jsxs)(`div`,{className:`relative mx-auto max-w-7xl px-4 pt-10 pb-12 sm:px-6 lg:px-8`,children:[(0,Q.jsx)(`p`,{className:`text-sm text-white/75`,children:e.categoryName??`Course`}),(0,Q.jsx)(`h1`,{className:`mt-2 max-w-3xl text-3xl font-semibold tracking-tight sm:text-5xl`,children:e.title}),(0,Q.jsx)(`p`,{className:`mt-3 max-w-2xl text-base text-white/85`,children:e.summary}),(0,Q.jsx)($,{course:e})]})]}),(0,Q.jsx)(f,{children:(0,Q.jsxs)(`div`,{className:`grid items-start gap-8 lg:grid-cols-[minmax(0,1fr)_360px]`,children:[(0,Q.jsxs)(`div`,{className:`space-y-8`,children:[e.description&&(0,Q.jsx)(_,{className:`p-6`,children:(0,Q.jsx)(G,{source:e.description})}),(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(`h2`,{className:`mb-3 text-lg font-semibold tracking-tight`,children:`Course outline`}),(0,Q.jsx)(`div`,{className:`space-y-3`,children:e.sections.map((e,t)=>(0,Q.jsxs)(_,{children:[(0,Q.jsxs)(`div`,{className:`flex items-center gap-3 border-b px-5 py-3.5`,children:[(0,Q.jsx)(`span`,{className:`grid size-6 place-items-center rounded-full bg-muted text-xs font-semibold`,children:t+1}),(0,Q.jsx)(`p`,{className:`font-medium`,children:e.title}),(0,Q.jsx)(`span`,{className:`ml-auto text-xs text-muted-foreground`,children:k(e.activities.length,`activity`,`activities`)})]}),(0,Q.jsx)(`ul`,{className:`divide-y`,children:e.activities.map(e=>(0,Q.jsxs)(`li`,{className:`flex items-center gap-3 px-5 py-2.5 text-sm`,children:[(0,Q.jsx)(x,{type:e.type,size:`sm`}),(0,Q.jsx)(`span`,{className:`flex-1 truncate`,children:e.title}),(0,Q.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:b[e.type].label}),(0,Q.jsx)(T,{className:`size-3.5 text-muted-foreground/60`})]},e.id))})]},e.id))})]})]}),(0,Q.jsxs)(_,{className:`sticky top-20`,children:[(0,Q.jsx)(g,{title:`Join this course`,description:e.canEnrol?`Get instant access to every lesson and activity.`:void 0}),(0,Q.jsx)(`div`,{className:`space-y-3 px-5 pb-5`,children:e.canEnrol?(0,Q.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),a.mutate()},className:`space-y-3`,children:[e.hasEnrolmentKey&&(0,Q.jsxs)(`div`,{className:`relative`,children:[(0,Q.jsx)(w,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,Q.jsx)(y,{value:n,onChange:e=>r(e.target.value),placeholder:`Enrolment key`,className:`pl-9`,"aria-label":`Enrolment key`})]}),(0,Q.jsx)(N,{type:`submit`,size:`lg`,className:`w-full`,loading:a.isPending,disabled:e.hasEnrolmentKey&&!n.trim(),children:`Enrol now`}),e.hasEnrolmentKey&&(0,Q.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Your teacher gives you the key for this course.`})]}):(0,Q.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This course is invite-only. Ask a teacher to add you.`})})]})]})})]})}function re(){return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(H,{className:`h-64 rounded-none`}),(0,Q.jsx)(f,{children:(0,Q.jsxs)(`div`,{className:`space-y-4`,children:[(0,Q.jsx)(H,{className:`h-40`}),(0,Q.jsx)(H,{className:`h-40`})]})})]})}function ie(){let{slug:t}=d(),{data:n,isLoading:a,error:s,refetch:c}=J(t),[l,u]=(0,Z.useState)(!1);if(R(n?.title),a)return(0,Q.jsx)(re,{});if(s instanceof L&&s.status===404)return(0,Q.jsx)(K,{});if(s||!n)return(0,Q.jsx)(f,{children:(0,Q.jsx)(U,{error:s,onRetry:()=>c()})});if(n.outlineOnly)return(0,Q.jsx)(ne,{course:n});let h=e=>n.capabilities.includes(e),g=[{to:``,label:`Course`,icon:i,end:!0},{to:`announcements`,label:`Announcements`,icon:m},{to:`participants`,label:`Participants`,icon:v,show:h(`course:viewParticipants`)},{to:`groups`,label:`Groups`,icon:D,show:h(`course:manageGroups`)||!!n.myGroups?.length},{to:`grades`,label:`Grades`,icon:o},{to:`completion`,label:`Completion`,icon:C,show:h(`completion:viewReport`)},{to:`badges`,label:`Badges`,icon:p},{to:`question-bank`,label:`Question bank`,icon:O,show:h(`questionbank:manage`)},{to:`settings`,label:`Settings`,icon:E,show:h(`course:update`)}].filter(e=>e.show!==!1);return(0,Q.jsxs)(`div`,{children:[(0,Q.jsx)(te,{course:n,editing:l,setEditing:u}),(0,Q.jsx)(`div`,{className:`sticky top-14 z-20 border-b bg-background/85 backdrop-blur-lg`,children:(0,Q.jsx)(`nav`,{className:`ck-no-scrollbar mx-auto flex max-w-7xl gap-1 overflow-x-auto px-4 sm:px-6 lg:px-8`,children:g.map(e=>(0,Q.jsxs)(r,{to:e.to?`/courses/${n.slug}/${e.to}`:`/courses/${n.slug}`,end:e.end,className:({isActive:e})=>A(`relative flex h-12 shrink-0 items-center gap-2 px-3 text-sm font-medium text-muted-foreground transition-colors hover:text-foreground`,e&&`text-foreground after:absolute after:inset-x-2 after:bottom-0 after:h-0.5 after:rounded-full after:bg-primary`),children:[(0,Q.jsx)(e.icon,{className:`size-4`}),e.label]},e.label))})}),(0,Q.jsx)(e,{context:{course:n,editing:l,setEditing:u,can:h}})]})}export{ie as default};
@@ -0,0 +1 @@
1
+ import{$ as e,A as t,C as n,D as r,E as i,Gt as a,Ht as o,L as s,O as c,P as l,St as u,Vt as d,_ as f,_t as p,at as m,c as h,f as ee,kt as g,l as _,m as v,p as y,s as b,t as x,u as S,y as C}from"./index-CEZdqKdi.js";import{H as w,P as T,U as te,_ as E,c as ne,dt as D,ft as O,g as k,h as A,i as re,k as j,m as M,mt as N,r as P,s as ie,ut as ae}from"./hooks-EFhyJ5yU.js";import{t as F}from"./globe-DDTr53UY.js";import{t as I}from"./key-round-fzvV-etw.js";import{t as L}from"./mail-CQ9yiBph.js";import{E as R,c as oe,n as se}from"./misc-CyGhN6HT.js";import{r as z}from"./constants-DLDWTvvN.js";import{r as B}from"./completion-2z7I-ypT.js";import{t as V}from"./achievements-DaIfUTKU.js";import{t as ce}from"./certificate-sheet-DzW0lfzR.js";import{r as H}from"./markdown-HNlXovsL.js";import{a as U,r as W}from"./context-D8W_QqNi.js";var G={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};G.node;var K=w(G),q={name:`file-lock`,size:24,node:[[`path`,{d:`M4 9.8V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.706.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2h-3`,key:`1432pc`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}],[`path`,{d:`M9 17v-2a2 2 0 0 0-4 0v2`,key:`168m41`}],[`rect`,{width:`8`,height:`5`,x:`3`,y:`17`,rx:`1`,key:`o8vfew`}]],aliases:[`file-lock-2`]};q.node;var le=w(q),J={name:`list-todo`,size:24,node:[[`path`,{d:`M13 5h8`,key:`a7qcls`}],[`path`,{d:`M13 12h8`,key:`h98zly`}],[`path`,{d:`M13 19h8`,key:`c3s6r1`}],[`path`,{d:`m3 17 2 2 4-4`,key:`1jhpwq`}],[`rect`,{x:`3`,y:`4`,width:`6`,height:`6`,rx:`1`,key:`cif1o7`}]]};J.node;var ue=w(J),Y=N(O(),1),X=D();function Z(e){return{enabled:e.enabled,mode:e.mode,activityIds:e.activityIds,minGrade:e.minGrade==null?``:String(e.minGrade),certificate:{...e.certificate}}}function de({title:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 border-b py-8 first:pt-0 last:border-0 last:pb-0 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-[15px] font-semibold`,children:e}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t})]}),(0,X.jsx)(`div`,{className:`min-w-0 space-y-5`,children:n})]})}function fe(e){return e.visible?e.completion===`none`?`Completion tracking is off`:null:`Hidden from students`}function pe({activities:e,selected:t,onToggle:n}){let r=new Set(t),i=(0,Y.useMemo)(()=>{let t=[];for(let n of e){let e=t.at(-1);e?.title===n.sectionTitle?e.items.push(n):t.push({title:n.sectionTitle,items:[n]})}return t},[e]);return e.length===0?(0,X.jsx)(`p`,{className:`text-sm text-muted-foreground`,children:`This course has no activities yet.`}):(0,X.jsxs)(`fieldset`,{className:`min-w-0 overflow-hidden rounded-xl border`,children:[(0,X.jsx)(`legend`,{className:`sr-only`,children:`Required activities`}),(0,X.jsx)(`div`,{className:`ck-scrollbar max-h-80 divide-y overflow-y-auto`,children:i.map(e=>(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`p`,{className:`bg-muted/50 px-3.5 py-1.5 text-xs font-medium text-muted-foreground`,children:e.title}),(0,X.jsx)(`ul`,{className:`divide-y`,children:e.items.map(e=>{let t=fe(e),i=`completion-activity-${e.id}`;return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-3.5 py-2.5`,children:[(0,X.jsx)(b,{id:i,checked:r.has(e.id),disabled:!e.tracked&&!r.has(e.id),onCheckedChange:t=>n(e.id,t===!0)}),(0,X.jsx)(C,{type:e.type,size:`sm`}),(0,X.jsxs)(`label`,{htmlFor:i,className:`min-w-0 flex-1 cursor-pointer text-sm`,children:[(0,X.jsx)(`span`,{className:`block truncate font-medium`,children:e.title}),t&&(0,X.jsxs)(`span`,{className:`block text-xs text-muted-foreground`,children:[t,r.has(e.id)?`, so it doesn’t count for now`:``]})]})]},e.id)})})]},e.title))})]})}function me({onInsert:e}){return(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-xs text-muted-foreground`,children:`Insert:`}),B.map(t=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>e(t.key),className:`rounded-md border bg-card px-1.5 py-0.5 font-mono text-[11px] text-muted-foreground transition-colors hover:border-primary/40 hover:text-foreground`,title:t.label,"aria-label":`Insert ${t.label} (${t.key})`,children:t.key},t.key))]})}function he({course:e}){let o=e.capabilities.includes(`completion:manage`),s=ae(),l=ie(),{data:f}=ne(),{data:m,isLoading:ee,error:g,refetch:b}=te({queryKey:V.settings(e.slug),queryFn:()=>M.get(`/courses/${e.id}/completion/settings`),enabled:o}),[C,w]=(0,Y.useState)(null),[T,E]=(0,Y.useState)(!1),D=(0,Y.useRef)(null),O=(0,Y.useRef)(null),{hash:j}=d();(0,Y.useEffect)(()=>{m&&!C&&w(Z(m.settings))},[m,C]);let N=!!C;(0,Y.useEffect)(()=>{N&&j===`#completion`&&O.current?.scrollIntoView({block:`start`})},[N,j]);let P=m?JSON.stringify(Z(m.settings)):``,F=!!C&&JSON.stringify(C)!==P;re(F);let I=a({mutationFn:t=>M.put(`/courses/${e.id}/completion/settings`,{enabled:t.enabled,mode:t.mode,activityIds:t.activityIds,minGrade:t.minGrade.trim()===``?null:Number(t.minGrade),certificate:t.certificate}),onSuccess:async t=>{let n=[t.newlyCompleted?`${t.newlyCompleted} ${t.newlyCompleted===1?`student has`:`students have`} completed the course`:``,t.certificatesIssued?`${t.certificatesIssued} ${t.certificatesIssued===1?`certificate`:`certificates`} issued`:``].filter(Boolean);R.success(`Completion settings saved`,n.length?{description:`${n.join(`. `)}.`}:void 0),s.setQueryData(V.settings(e.slug),e=>e&&{...e,settings:t.settings}),w(Z(t.settings)),await s.invalidateQueries({queryKey:[`course`,e.slug]})},onError:e=>R.error(A(e))});if(!o)return null;if(g)return(0,X.jsx)(x,{className:`mt-8 p-6`,children:(0,X.jsx)(se,{error:g,onRetry:()=>b()})});if(ee||!m||!C)return(0,X.jsx)(oe,{className:`mt-8 h-72`});let L=(e,t)=>w(n=>n&&{...n,[e]:t}),z=e=>w(t=>t&&{...t,certificate:{...t.certificate,...e}}),B=m.activities.filter(e=>e.tracked),H=m.activities.filter(e=>e.tracked&&C.activityIds.includes(e.id)),U=C.minGrade.trim()===``?null:Number(C.minGrade),W=U!=null&&(!Number.isFinite(U)||U<0||U>100)?`Use a grade from 0 to 100.`:null,G=C.enabled&&C.mode===`selected`&&C.activityIds.length===0?`Choose at least one activity.`:null,K=e=>{let t=D.current,n=C.certificate.body,r=t?.selectionStart??n.length,i=t?.selectionEnd??n.length;z({body:n.slice(0,r)+e+n.slice(i)}),requestAnimationFrame(()=>{t?.focus(),t?.setSelectionRange(r+e.length,r+e.length)})};return(0,X.jsxs)(`form`,{ref:O,id:`completion`,className:`mt-8 scroll-mt-32`,onSubmit:e=>{e.preventDefault(),!W&&!G&&I.mutate(C)},children:[(0,X.jsxs)(x,{className:`p-6 sm:p-8`,children:[(0,X.jsxs)(de,{title:`Course completion`,description:`Decide what completes the course. Students see a checklist on the course page and you see who has finished on the Completion tab.`,children:[(0,X.jsx)(y,{label:`Track course completion`,description:`Completion is checked automatically whenever students finish activities or get grades.`,checked:C.enabled,onCheckedChange:e=>L(`enabled`,e)}),C.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`fieldset`,{className:`min-w-0`,children:[(0,X.jsx)(`legend`,{className:`mb-1.5 text-sm font-medium`,children:`Students must complete`}),(0,X.jsx)(h,{columns:2,value:C.mode,onChange:e=>L(`mode`,e),options:[{value:`all`,label:`All activities`,description:`Every visible activity that tracks completion (${B.length} now).`,icon:(0,X.jsx)(p,{className:`size-4`})},{value:`selected`,label:`Selected activities`,description:`Only the activities you choose below.`,icon:(0,X.jsx)(ue,{className:`size-4`})}]})]}),C.mode===`all`&&B.length===0&&(0,X.jsx)(`p`,{className:`rounded-lg bg-warning/10 px-3.5 py-2.5 text-sm`,children:`No activity tracks completion yet. Turn completion on for some activities, or add a minimum grade.`}),C.mode===`selected`&&(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,X.jsx)(`p`,{className:`text-sm font-medium`,children:`Required activities`}),(0,X.jsxs)(`span`,{className:`text-xs text-muted-foreground`,children:[H.length,` selected`]})]}),(0,X.jsx)(pe,{activities:m.activities,selected:C.activityIds,onToggle:(e,t)=>w(n=>n&&{...n,activityIds:t?[...new Set([...n.activityIds,e])]:n.activityIds.filter(t=>t!==e)})}),G&&(0,X.jsx)(`p`,{className:`text-xs text-destructive`,children:G})]}),(0,X.jsx)(_,{label:`Minimum course grade`,optional:!0,error:W,hint:`The course total from the gradebook, in percent. Leave empty for no grade requirement.`,children:e=>(0,X.jsxs)(`div`,{className:`relative sm:w-40`,children:[(0,X.jsx)(S,{...e,type:`number`,inputMode:`decimal`,min:0,max:100,step:`any`,value:C.minGrade,onChange:e=>L(`minGrade`,e.target.value),className:`pr-8`,placeholder:`None`}),(0,X.jsx)(`span`,{className:`pointer-events-none absolute top-1/2 right-3 -translate-y-1/2 text-sm text-muted-foreground`,children:`%`})]})}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:`Students who have already completed the course keep their completion when you change these settings.`})]})]}),(0,X.jsxs)(de,{title:`Certificate`,description:`A printable certificate with a code anyone can check on this site’s verification page.`,children:[(0,X.jsx)(y,{label:`Issue a certificate on completion`,description:`Students who already completed the course get one too.`,checked:C.certificate.enabled,onCheckedChange:e=>z({enabled:e})}),C.certificate.enabled&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(_,{label:`Title`,children:e=>(0,X.jsx)(S,{...e,required:!0,maxLength:120,value:C.certificate.title,onChange:e=>z({title:e.target.value})})}),(0,X.jsx)(_,{label:`Text`,hint:`Each line is its own line on the certificate. A line with only {name} or {course} is set large.`,children:e=>(0,X.jsxs)(`div`,{className:`space-y-2`,children:[(0,X.jsx)(v,{...e,ref:D,required:!0,rows:6,maxLength:2e3,value:C.certificate.body,onChange:e=>z({body:e.target.value})}),(0,X.jsx)(me,{onInsert:K})]})}),(0,X.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,X.jsx)(_,{label:`Signed by`,optional:!0,children:e=>(0,X.jsx)(S,{...e,maxLength:100,value:C.certificate.signatureName,onChange:e=>z({signatureName:e.target.value}),placeholder:l?.name})}),(0,X.jsx)(_,{label:`Signer’s title`,optional:!0,children:e=>(0,X.jsx)(S,{...e,maxLength:100,value:C.certificate.signatureTitle,onChange:e=>z({signatureTitle:e.target.value}),placeholder:`Course teacher`})})]}),(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,X.jsxs)(k,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>E(!0),children:[(0,X.jsx)(u,{}),` Preview certificate`]}),m.settings.certificate.enabled&&!F&&(0,X.jsx)(n,{variant:`success`,children:`Issuing certificates`})]})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex flex-wrap items-center justify-end gap-3`,children:[F&&(0,X.jsx)(`span`,{className:`mr-auto text-sm text-muted-foreground`,children:`Unsaved completion settings`}),(0,X.jsx)(k,{type:`button`,variant:`ghost`,disabled:!F,onClick:()=>w(Z(m.settings)),children:`Discard`}),(0,X.jsx)(k,{type:`submit`,loading:I.isPending,disabled:!F||!!W||!!G,children:`Save completion settings`})]}),(0,X.jsx)(i,{open:T,onOpenChange:E,children:(0,X.jsxs)(c,{size:`xl`,children:[(0,X.jsx)(t,{title:`Certificate preview`,description:`With your name and today’s date. Real certificates use the student’s details.`}),(0,X.jsx)(r,{className:`pb-6`,children:(0,X.jsx)(ce,{content:{...C.certificate,siteName:f?.site.name??`Coursekit`,recipientName:l?.name??`Student Name`,courseTitle:e.title,completedAt:new Date().toISOString(),code:`7QK2-M9XD-4TPA`}})})]})})]})}function ge({value:e,onChange:t}){return(0,X.jsx)(`div`,{className:`flex flex-wrap gap-2.5`,children:z.map(n=>(0,X.jsx)(`button`,{type:`button`,title:l[n]?.label,onClick:()=>t(n),className:E(`grid size-10 place-items-center rounded-xl ring-offset-2 ring-offset-background transition-transform hover:scale-105`,e===n&&`ring-2 ring-foreground`),style:s(n),children:e===n&&(0,X.jsx)(g,{className:`size-4 text-white`,strokeWidth:3})},n))})}function Q({title:e,description:t,children:n}){return(0,X.jsxs)(`div`,{className:`grid grid-cols-1 gap-6 border-b py-8 first:pt-0 last:border-0 md:grid-cols-[260px_minmax(0,1fr)]`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`text-[15px] font-semibold`,children:e}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:t})]}),(0,X.jsx)(`div`,{className:`space-y-5`,children:n})]})}function $(e){return{title:e.title,slug:e.slug,summary:e.summary,description:e.description,categoryId:e.categoryId??``,coverColor:e.coverColor,visibility:e.visibility,enrolment:e.enrolment,enrolmentKey:e.enrolmentKey??``,startDate:T(e.startDate),endDate:T(e.endDate)}}function _e(){let{course:t}=W();P(`Settings · ${t.title}`);let n=o(),r=U(),i=e(),[s,c]=(0,Y.useState)(()=>$(t)),l=JSON.stringify($(t)),d=JSON.stringify(s)!==l;re(d);let{data:p}=te({queryKey:[`categories`],queryFn:()=>M.get(`/categories`)}),g=a({mutationFn:()=>M.patch(`/courses/${t.id}`,{...s,categoryId:s.categoryId||null,enrolmentKey:s.enrolment===`key`&&s.enrolmentKey.trim()||null,startDate:s.startDate?j(`${s.startDate}T00:00`):null,endDate:s.endDate?j(`${s.endDate}T23:59`):null}),onSuccess:async e=>{R.success(`Course settings saved`),await r(t.slug),e.slug!==t.slug&&n(`/courses/${e.slug}/settings`,{replace:!0})},onError:e=>R.error(A(e))}),y=a({mutationFn:()=>M.delete(`/courses/${t.id}`),onSuccess:async()=>{R.success(`Course deleted`),await r(t.slug),n(`/my-courses`)},onError:e=>R.error(A(e))}),b=(e,t)=>c(n=>({...n,[e]:t}));return(0,X.jsxs)(f,{children:[(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),g.mutate()},children:[(0,X.jsxs)(x,{className:`p-6 sm:p-8`,children:[(0,X.jsxs)(Q,{title:`General`,description:`How the course appears in the catalog and on the dashboard.`,children:[(0,X.jsx)(_,{label:`Title`,children:e=>(0,X.jsx)(S,{...e,required:!0,value:s.title,onChange:e=>b(`title`,e.target.value)})}),(0,X.jsx)(_,{label:`Short summary`,hint:`One or two sentences shown on course cards.`,children:e=>(0,X.jsx)(v,{...e,rows:2,value:s.summary,onChange:e=>b(`summary`,e.target.value)})}),(0,X.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,X.jsx)(_,{label:`URL`,hint:`${window.location.origin}/courses/${s.slug}`,children:e=>(0,X.jsx)(S,{...e,value:s.slug,onChange:e=>b(`slug`,e.target.value.toLowerCase().replace(/[^a-z0-9-]/g,`-`))})}),(0,X.jsx)(_,{label:`Category`,children:e=>(0,X.jsxs)(ee,{...e,value:s.categoryId,onChange:e=>b(`categoryId`,e.target.value),children:[(0,X.jsx)(`option`,{value:``,children:`No category`}),p?.map(e=>(0,X.jsx)(`option`,{value:e.id,children:e.name},e.id))]})})]}),(0,X.jsx)(_,{label:`Cover`,children:()=>(0,X.jsx)(ge,{value:s.coverColor,onChange:e=>b(`coverColor`,e)})})]}),(0,X.jsx)(Q,{title:`Description`,description:`The full course overview shown to people before and after they enrol.`,children:(0,X.jsx)(H,{value:s.description,onChange:e=>b(`description`,e),rows:10})}),(0,X.jsxs)(Q,{title:`Availability`,description:`Drafts are only visible to teachers. Archived courses are read-only.`,children:[(0,X.jsx)(h,{value:s.visibility,onChange:e=>b(`visibility`,e),options:[{value:`draft`,label:`Draft`,description:`Hidden while you build it.`,icon:(0,X.jsx)(le,{className:`size-4`})},{value:`published`,label:`Published`,description:`Listed in the catalog.`,icon:(0,X.jsx)(F,{className:`size-4`})},{value:`archived`,label:`Archived`,description:`Read-only for students.`,icon:(0,X.jsx)(K,{className:`size-4`})}]}),(0,X.jsxs)(`div`,{className:`grid gap-5 sm:grid-cols-2`,children:[(0,X.jsx)(_,{label:`Start date`,optional:!0,children:e=>(0,X.jsx)(S,{...e,type:`date`,value:s.startDate,onChange:e=>b(`startDate`,e.target.value)})}),(0,X.jsx)(_,{label:`End date`,optional:!0,children:e=>(0,X.jsx)(S,{...e,type:`date`,value:s.endDate,onChange:e=>b(`endDate`,e.target.value)})})]})]}),(0,X.jsxs)(Q,{title:`Enrolment`,description:`How students join the course.`,children:[(0,X.jsx)(h,{value:s.enrolment,onChange:e=>b(`enrolment`,e),options:[{value:`open`,label:`Open`,description:`Anyone can enrol themselves.`,icon:(0,X.jsx)(u,{className:`size-4`})},{value:`key`,label:`Enrolment key`,description:`Students need a secret key.`,icon:(0,X.jsx)(I,{className:`size-4`})},{value:`invite`,label:`Invite only`,description:`Teachers add students.`,icon:(0,X.jsx)(L,{className:`size-4`})}]}),s.enrolment===`key`&&(0,X.jsx)(_,{label:`Enrolment key`,hint:`Share this with your students.`,children:e=>(0,X.jsx)(S,{...e,value:s.enrolmentKey,onChange:e=>b(`enrolmentKey`,e.target.value),className:`sm:w-72`})})]})]}),(0,X.jsxs)(`div`,{className:`sticky bottom-4 z-10 mt-6 flex items-center justify-end gap-3 rounded-xl border bg-card/90 p-3 shadow-lg backdrop-blur`,children:[d&&(0,X.jsx)(`span`,{className:`mr-auto pl-2 text-sm text-muted-foreground`,children:`You have unsaved changes`}),(0,X.jsx)(k,{type:`button`,variant:`ghost`,disabled:!d,onClick:()=>c($(t)),children:`Discard`}),(0,X.jsx)(k,{type:`submit`,loading:g.isPending,disabled:!d,children:`Save changes`})]})]}),(0,X.jsx)(he,{course:t}),(0,X.jsx)(x,{className:`mt-8 border-destructive/30 p-6`,children:(0,X.jsxs)(`div`,{className:`flex flex-col gap-4 sm:flex-row sm:items-center sm:justify-between`,children:[(0,X.jsxs)(`div`,{children:[(0,X.jsx)(`h2`,{className:`font-semibold`,children:`Delete this course`}),(0,X.jsx)(`p`,{className:`mt-1 text-sm text-muted-foreground`,children:`Permanently removes the course with all activities, submissions, grades and posts.`})]}),(0,X.jsxs)(k,{variant:`destructive`,loading:y.isPending,onClick:async()=>{await i({title:`Delete “${t.title}”?`,description:`This cannot be undone. Everything in the course, including student work and grades, will be deleted.`,confirmLabel:`Delete course`,destructive:!0})&&y.mutate()},children:[(0,X.jsx)(m,{}),` Delete course`]})]})})]})}export{ge as CoverPicker,_e as default};
@@ -0,0 +1 @@
1
+ import{Gt as e,Ht as t,Pt as n,S as r,_ as i,a,f as o,l as s,m as c,t as l,tt as u,u as d,zt as f}from"./index-CEZdqKdi.js";import{U as p,dt as m,f as h,ft as g,g as _,h as v,m as y,mt as b,r as x,s as S,ut as C}from"./hooks-EFhyJ5yU.js";import{E as w}from"./misc-CyGhN6HT.js";import{CoverPicker as T}from"./CourseSettingsPage-BIagLirb.js";var E=b(g(),1),D=m();function O(){x(`New course`);let m=S(),g=t(),b=C(),[O,k]=(0,E.useState)({title:``,summary:``,categoryId:``,coverColor:`indigo`}),{data:A}=p({queryKey:[`categories`],queryFn:()=>y.get(`/categories`)}),j=e({mutationFn:()=>y.post(`/courses`,{...O,categoryId:O.categoryId||null}),onSuccess:async e=>{await b.invalidateQueries({queryKey:[`courses`]}),w.success(`Course created as a draft. Add your first activities!`),g(`/courses/${e.slug}`)},onError:e=>w.error(v(e))});return h(m?.role)?(0,D.jsxs)(i,{size:`narrow`,children:[(0,D.jsx)(a,{title:`Create a course`,description:`Start with the basics. You can change everything later in course settings.`}),(0,D.jsxs)(`div`,{className:`grid gap-6`,children:[(0,D.jsxs)(l,{className:`overflow-hidden`,children:[(0,D.jsx)(r,{color:O.coverColor,title:O.title||`New course`,className:`h-36`,children:(0,D.jsxs)(`div`,{className:`absolute inset-x-6 bottom-5 text-white`,children:[(0,D.jsx)(`p`,{className:`text-xs font-medium text-white/80`,children:A?.find(e=>e.id===O.categoryId)?.name??`Preview`}),(0,D.jsx)(`p`,{className:`mt-1 truncate text-2xl font-semibold tracking-tight`,children:O.title||`Your course title`})]})}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 px-6 py-3 text-xs text-muted-foreground`,children:[(0,D.jsx)(u,{className:`size-3.5`}),` You'll be the teacher. The course starts as a hidden draft.`]})]}),(0,D.jsx)(l,{className:`p-6`,children:(0,D.jsxs)(`form`,{className:`space-y-5`,onSubmit:e=>{e.preventDefault(),j.mutate()},children:[(0,D.jsx)(s,{label:`Course title`,children:e=>(0,D.jsx)(d,{...e,autoFocus:!0,required:!0,minLength:3,value:O.title,onChange:e=>k({...O,title:e.target.value}),placeholder:`e.g. Introduction to Psychology`})}),(0,D.jsx)(s,{label:`Short summary`,optional:!0,hint:`One or two sentences for the catalog.`,children:e=>(0,D.jsx)(c,{...e,rows:2,value:O.summary,onChange:e=>k({...O,summary:e.target.value})})}),(0,D.jsx)(s,{label:`Category`,optional:!0,children:e=>(0,D.jsxs)(o,{...e,value:O.categoryId,onChange:e=>k({...O,categoryId:e.target.value}),children:[(0,D.jsx)(`option`,{value:``,children:`No category`}),A?.map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))]})}),(0,D.jsx)(s,{label:`Cover`,children:()=>(0,D.jsx)(T,{value:O.coverColor,onChange:e=>k({...O,coverColor:e})})}),(0,D.jsxs)(`div`,{className:`flex justify-end gap-2 pt-2`,children:[(0,D.jsx)(_,{type:`button`,variant:`outline`,onClick:()=>g(-1),children:`Cancel`}),(0,D.jsxs)(_,{type:`submit`,loading:j.isPending,disabled:O.title.trim().length<3,children:[`Create course `,(0,D.jsx)(n,{})]})]})]})})]})]}):(0,D.jsx)(f,{to:`/`,replace:!0})}export{O as default};
@@ -1 +1 @@
1
- import{At as e,B as t,F as n,Ft as r,Lt as i,Q as a,R as o,Rt as s,S as c,U as l,V as u,g as d,j as f,kt as p,q as m,rt as h,t as g,w as _}from"./index-B29bTBiJ.js";import{D as v,H as y,T as b,U as x,_ as S,dt as C,ft as w,g as T,h as E,m as D,mt as O,p as k,r as A,u as j,ut as M}from"./hooks-BBARn-DA.js";import{t as N}from"./lock-BjbqwA_0.js";import{t as P}from"./ellipsis-c2POIN-Y.js";import{t as F}from"./pencil-p0GQmIMo.js";import{t as I}from"./pin-DlYC3uec.js";import{T as L,c as R,n as z}from"./misc-DvgDEI3I.js";import{n as B,r as V}from"./markdown-ykrkPMbn.js";import H from"./NotFoundPage-BRquC7-l.js";var U={name:`lock-open`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]],aliases:[`unlock`]};U.node;var W=y(U),G={name:`pin-off`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]};G.node;var K=y(G),q={name:`reply`,size:24,node:[[`path`,{d:`M20 18v-2a4 4 0 0 0-4-4H4`,key:`5vmcpk`}],[`path`,{d:`m9 17-5-5 5-5`,key:`nvlc11`}]]};q.node;var J=y(q),Y=O(w(),1),X=C();function Z({onSubmit:e,onCancel:t,initial:n=``,submitLabel:r=`Reply`,autoFocus:i}){let[a,o]=(0,Y.useState)(n),[s,c]=(0,Y.useState)(!1);return(0,X.jsxs)(`form`,{className:`space-y-2`,onSubmit:async t=>{t.preventDefault(),c(!0);try{await e(a),o(``)}finally{c(!1)}},children:[(0,X.jsx)(V,{value:a,onChange:o,rows:4,autoFocus:i,placeholder:`Write a reply…`}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t&&(0,X.jsx)(T,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:`Cancel`}),(0,X.jsx)(T,{type:`submit`,size:`sm`,loading:s,disabled:!a.trim(),children:r})]})]})}function Q({post:e,childrenOf:n,depth:r,discussion:i,onReply:a,onEdit:s,onDelete:l}){let[d,p]=(0,Y.useState)(!1),[g,_]=(0,Y.useState)(!1),y=n.get(e.id)??[],x=e.authorRole===`teacher`||e.authorRole===`assistant`;return(0,X.jsxs)(`div`,{className:S(r>0&&`border-l-2 border-border pl-4 sm:pl-6`),children:[(0,X.jsxs)(`div`,{className:`py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(f,{user:e.author,size:`sm`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium`,children:[e.author.name,x&&(0,X.jsx)(c,{variant:`violet`,children:j[e.authorRole]})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,title:b(e.createdAt),children:[v(e.createdAt),e.updatedAt!==e.createdAt&&` · edited`]})]}),(e.canEdit||e.canDelete)&&(0,X.jsxs)(o,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(T,{variant:`ghost`,size:`icon-sm`,"aria-label":`Post actions`,children:(0,X.jsx)(P,{})})}),(0,X.jsxs)(t,{children:[e.canEdit&&(0,X.jsxs)(u,{onSelect:()=>_(!0),children:[(0,X.jsx)(F,{}),` Edit`]}),e.canDelete&&(0,X.jsxs)(u,{destructive:!0,onSelect:()=>l(e),children:[(0,X.jsx)(h,{}),` Delete`]})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-3 pl-11`,children:[g?(0,X.jsx)(Z,{initial:e.body,submitLabel:`Save`,autoFocus:!0,onCancel:()=>_(!1),onSubmit:async t=>{await s(e.id,t),_(!1)}}):(0,X.jsx)(B,{source:e.body,className:`prose-sm`}),i.canReply&&!g&&(0,X.jsxs)(`button`,{onClick:()=>p(!d),className:`mt-2 flex items-center gap-1.5 text-xs font-medium text-muted-foreground hover:text-primary`,children:[(0,X.jsx)(J,{className:`size-3.5`}),` Reply`]}),d&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Z,{autoFocus:!0,onCancel:()=>p(!1),onSubmit:async t=>{await a(e.id,t),p(!1)}})})]})]}),y.length>0&&(0,X.jsx)(`div`,{className:S(r>=3?``:`ml-4 sm:ml-5`),children:y.map(e=>(0,X.jsx)(Q,{post:e,childrenOf:n,depth:Math.min(r+1,4),discussion:i,onReply:a,onEdit:s,onDelete:l},e.id))})]})}function $(){let{slug:f,discussionId:v}=i(),y=M(),b=r(),S=a(),C=[`discussion`,v],{data:w,isLoading:O,error:j,refetch:P}=x({queryKey:C,queryFn:()=>D.get(`/discussions/${v}`)});A(w?.title);let F=()=>Promise.all([y.invalidateQueries({queryKey:C}),y.invalidateQueries({queryKey:[`discussions`]})]),B=(e,t)=>D.post(`/discussions/${v}/posts`,{body:t,parentId:e}).then(F).catch(e=>{throw L.error(E(e)),e}),V=(e,t)=>D.patch(`/posts/${e}`,{body:t}).then(F).catch(e=>{throw L.error(E(e)),e}),U=s({mutationFn:e=>D.patch(`/discussions/${v}`,e),onSuccess:F,onError:e=>L.error(E(e))});if(O)return(0,X.jsxs)(d,{size:`narrow`,children:[(0,X.jsx)(R,{className:`mb-4 h-10 w-2/3`}),(0,X.jsx)(R,{className:`h-64`})]});if(j instanceof k&&j.status===404)return(0,X.jsx)(H,{});if(j||!w)return(0,X.jsx)(d,{children:(0,X.jsx)(z,{error:j,onRetry:()=>P()})});let G=w.posts.find(e=>e.parentId===null),q=new Map;for(let e of w.posts)e.parentId&&q.set(e.parentId,[...q.get(e.parentId)??[],e]);let J=_(w.course.slug,w.activityId),Y=async e=>{let t=e.parentId===null;if(await S({title:t?`Delete this discussion?`:`Delete this post?`,description:t?`The whole discussion and every reply will be removed.`:`Replies to this post are deleted too.`,confirmLabel:`Delete`,destructive:!0}))try{await D.delete(`/posts/${e.id}`),t?(L.success(`Discussion deleted`),b(J)):await F()}catch(e){L.error(E(e))}};return(0,X.jsxs)(d,{size:`narrow`,children:[(0,X.jsxs)(e,{to:J,className:`inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground`,children:[(0,X.jsx)(p,{className:`size-4`}),` `,w.activityTitle]}),(0,X.jsxs)(`div`,{className:`mt-3 mb-6 flex items-start gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`size-2 rounded-[3px]`,style:n(w.course.coverColor)}),(0,X.jsx)(e,{to:`/courses/${f}`,className:`hover:text-foreground`,children:w.course.title})]}),(0,X.jsx)(`h1`,{className:`mt-1.5 text-2xl font-semibold tracking-tight text-balance sm:text-3xl`,children:w.title}),(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[w.pinned&&(0,X.jsxs)(c,{variant:`warning`,children:[(0,X.jsx)(I,{}),` Pinned`]}),w.locked&&(0,X.jsxs)(c,{variant:`neutral`,children:[(0,X.jsx)(N,{}),` Locked: no new replies`]}),(0,X.jsxs)(c,{variant:`neutral`,children:[w.replyCount,` `,w.replyCount===1?`reply`:`replies`]})]})]}),w.canModerate&&(0,X.jsxs)(o,{children:[(0,X.jsx)(m,{asChild:!0,children:(0,X.jsx)(T,{variant:`outline`,size:`sm`,children:`Moderate`})}),(0,X.jsxs)(t,{children:[(0,X.jsxs)(u,{onSelect:()=>U.mutate({pinned:!w.pinned}),children:[w.pinned?(0,X.jsx)(K,{}):(0,X.jsx)(I,{}),` `,w.pinned?`Unpin`:`Pin to top`]}),(0,X.jsxs)(u,{onSelect:()=>U.mutate({locked:!w.locked}),children:[w.locked?(0,X.jsx)(W,{}):(0,X.jsx)(N,{}),` `,w.locked?`Unlock`:`Lock replies`]}),G&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(l,{}),(0,X.jsxs)(u,{destructive:!0,onSelect:()=>Y(G),children:[(0,X.jsx)(h,{}),` Delete discussion`]})]})]})]})]}),(0,X.jsx)(g,{className:`px-5 sm:px-6`,children:G&&(0,X.jsx)(`div`,{className:`divide-y`,children:(0,X.jsx)(Q,{post:G,childrenOf:new Map,depth:0,discussion:{...w,canReply:!1},onReply:(e,t)=>B(e,t),onEdit:V,onDelete:Y})})}),(0,X.jsxs)(`div`,{className:`mt-6`,children:[(0,X.jsxs)(`h2`,{className:`mb-2 text-sm font-semibold text-muted-foreground`,children:[w.replyCount,` `,w.replyCount===1?`reply`:`replies`]}),G&&(q.get(G.id)??[]).length>0&&(0,X.jsx)(g,{className:`divide-y px-5 sm:px-6`,children:(q.get(G.id)??[]).map(e=>(0,X.jsx)(Q,{post:e,childrenOf:q,depth:0,discussion:w,onReply:(e,t)=>B(e,t),onEdit:V,onDelete:Y},e.id))})]}),w.canReply?(0,X.jsxs)(g,{className:`mt-6 p-5`,children:[(0,X.jsx)(`p`,{className:`mb-3 text-sm font-semibold`,children:`Join the discussion`}),(0,X.jsx)(Z,{onSubmit:e=>B(null,e),submitLabel:`Post reply`})]}):w.locked&&(0,X.jsx)(`p`,{className:`mt-6 rounded-lg bg-muted px-4 py-3 text-center text-sm text-muted-foreground`,children:`This discussion is locked.`})]})}export{$ as default};
1
+ import{$ as e,C as t,Ft as n,Gt as r,H as i,Ht as a,I as o,It as s,J as c,M as l,T as u,V as d,W as f,Wt as p,_ as m,at as h,t as g,z as _}from"./index-CEZdqKdi.js";import{D as v,H as y,T as b,U as x,_ as S,dt as C,ft as w,g as T,h as E,m as D,mt as O,p as k,r as A,u as j,ut as M}from"./hooks-EFhyJ5yU.js";import{t as N}from"./lock-C2edVDOc.js";import{t as P}from"./ellipsis-BDmYLoyn.js";import{t as F}from"./pencil-DFUpj3YP.js";import{t as I}from"./pin-DNUQ6-WX.js";import{E as L,c as R,n as z}from"./misc-CyGhN6HT.js";import{n as B,r as V}from"./markdown-HNlXovsL.js";import H from"./NotFoundPage-BmwVsGAy.js";var U={name:`lock-open`,size:24,node:[[`rect`,{width:`18`,height:`11`,x:`3`,y:`11`,rx:`2`,ry:`2`,key:`1w4ew1`}],[`path`,{d:`M7 11V7a5 5 0 0 1 9.9-1`,key:`1mm8w8`}]],aliases:[`unlock`]};U.node;var W=y(U),G={name:`pin-off`,size:24,node:[[`path`,{d:`M12 17v5`,key:`bb1du9`}],[`path`,{d:`M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89`,key:`znwnzq`}],[`path`,{d:`m2 2 20 20`,key:`1ooewy`}],[`path`,{d:`M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11`,key:`c9qhm2`}]]};G.node;var K=y(G),q={name:`reply`,size:24,node:[[`path`,{d:`M20 18v-2a4 4 0 0 0-4-4H4`,key:`5vmcpk`}],[`path`,{d:`m9 17-5-5 5-5`,key:`nvlc11`}]]};q.node;var J=y(q),Y=O(w(),1),X=C();function Z({onSubmit:e,onCancel:t,initial:n=``,submitLabel:r=`Reply`,autoFocus:i}){let[a,o]=(0,Y.useState)(n),[s,c]=(0,Y.useState)(!1);return(0,X.jsxs)(`form`,{className:`space-y-2`,onSubmit:async t=>{t.preventDefault(),c(!0);try{await e(a),o(``)}finally{c(!1)}},children:[(0,X.jsx)(V,{value:a,onChange:o,rows:4,autoFocus:i,placeholder:`Write a reply…`}),(0,X.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[t&&(0,X.jsx)(T,{type:`button`,variant:`ghost`,size:`sm`,onClick:t,children:`Cancel`}),(0,X.jsx)(T,{type:`submit`,size:`sm`,loading:s,disabled:!a.trim(),children:r})]})]})}function Q({post:e,childrenOf:n,depth:r,discussion:a,onReply:o,onEdit:s,onDelete:u}){let[f,p]=(0,Y.useState)(!1),[m,g]=(0,Y.useState)(!1),y=n.get(e.id)??[],x=e.authorRole===`teacher`||e.authorRole===`assistant`;return(0,X.jsxs)(`div`,{className:S(r>0&&`border-l-2 border-border pl-4 sm:pl-6`),children:[(0,X.jsxs)(`div`,{className:`py-4`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,X.jsx)(l,{user:e.author,size:`sm`}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`p`,{className:`flex flex-wrap items-center gap-2 text-sm font-medium`,children:[e.author.name,x&&(0,X.jsx)(t,{variant:`violet`,children:j[e.authorRole]})]}),(0,X.jsxs)(`p`,{className:`text-xs text-muted-foreground`,title:b(e.createdAt),children:[v(e.createdAt),e.updatedAt!==e.createdAt&&` · edited`]})]}),(e.canEdit||e.canDelete)&&(0,X.jsxs)(_,{children:[(0,X.jsx)(c,{asChild:!0,children:(0,X.jsx)(T,{variant:`ghost`,size:`icon-sm`,"aria-label":`Post actions`,children:(0,X.jsx)(P,{})})}),(0,X.jsxs)(d,{children:[e.canEdit&&(0,X.jsxs)(i,{onSelect:()=>g(!0),children:[(0,X.jsx)(F,{}),` Edit`]}),e.canDelete&&(0,X.jsxs)(i,{destructive:!0,onSelect:()=>u(e),children:[(0,X.jsx)(h,{}),` Delete`]})]})]})]}),(0,X.jsxs)(`div`,{className:`mt-3 pl-11`,children:[m?(0,X.jsx)(Z,{initial:e.body,submitLabel:`Save`,autoFocus:!0,onCancel:()=>g(!1),onSubmit:async t=>{await s(e.id,t),g(!1)}}):(0,X.jsx)(B,{source:e.body,className:`prose-sm`}),a.canReply&&!m&&(0,X.jsxs)(`button`,{onClick:()=>p(!f),className:`mt-2 flex items-center gap-1.5 text-xs font-medium text-muted-foreground hover:text-primary`,children:[(0,X.jsx)(J,{className:`size-3.5`}),` Reply`]}),f&&(0,X.jsx)(`div`,{className:`mt-3`,children:(0,X.jsx)(Z,{autoFocus:!0,onCancel:()=>p(!1),onSubmit:async t=>{await o(e.id,t),p(!1)}})})]})]}),y.length>0&&(0,X.jsx)(`div`,{className:S(r>=3?``:`ml-4 sm:ml-5`),children:y.map(e=>(0,X.jsx)(Q,{post:e,childrenOf:n,depth:Math.min(r+1,4),discussion:a,onReply:o,onEdit:s,onDelete:u},e.id))})]})}function $(){let{slug:l,discussionId:v}=p(),y=M(),b=a(),S=e(),C=[`discussion`,v],{data:w,isLoading:O,error:j,refetch:P}=x({queryKey:C,queryFn:()=>D.get(`/discussions/${v}`)});A(w?.title);let F=()=>Promise.all([y.invalidateQueries({queryKey:C}),y.invalidateQueries({queryKey:[`discussions`]})]),B=(e,t)=>D.post(`/discussions/${v}/posts`,{body:t,parentId:e}).then(F).catch(e=>{throw L.error(E(e)),e}),V=(e,t)=>D.patch(`/posts/${e}`,{body:t}).then(F).catch(e=>{throw L.error(E(e)),e}),U=r({mutationFn:e=>D.patch(`/discussions/${v}`,e),onSuccess:F,onError:e=>L.error(E(e))});if(O)return(0,X.jsxs)(m,{size:`narrow`,children:[(0,X.jsx)(R,{className:`mb-4 h-10 w-2/3`}),(0,X.jsx)(R,{className:`h-64`})]});if(j instanceof k&&j.status===404)return(0,X.jsx)(H,{});if(j||!w)return(0,X.jsx)(m,{children:(0,X.jsx)(z,{error:j,onRetry:()=>P()})});let G=w.posts.find(e=>e.parentId===null),q=new Map;for(let e of w.posts)e.parentId&&q.set(e.parentId,[...q.get(e.parentId)??[],e]);let J=u(w.course.slug,w.activityId),Y=async e=>{let t=e.parentId===null;if(await S({title:t?`Delete this discussion?`:`Delete this post?`,description:t?`The whole discussion and every reply will be removed.`:`Replies to this post are deleted too.`,confirmLabel:`Delete`,destructive:!0}))try{await D.delete(`/posts/${e.id}`),t?(L.success(`Discussion deleted`),b(J)):await F()}catch(e){L.error(E(e))}};return(0,X.jsxs)(m,{size:`narrow`,children:[(0,X.jsxs)(s,{to:J,className:`inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground`,children:[(0,X.jsx)(n,{className:`size-4`}),` `,w.activityTitle]}),(0,X.jsxs)(`div`,{className:`mt-3 mb-6 flex items-start gap-3`,children:[(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted-foreground`,children:[(0,X.jsx)(`span`,{className:`size-2 rounded-[3px]`,style:o(w.course.coverColor)}),(0,X.jsx)(s,{to:`/courses/${l}`,className:`hover:text-foreground`,children:w.course.title})]}),(0,X.jsx)(`h1`,{className:`mt-1.5 text-2xl font-semibold tracking-tight text-balance sm:text-3xl`,children:w.title}),(0,X.jsxs)(`div`,{className:`mt-2 flex flex-wrap gap-2`,children:[w.pinned&&(0,X.jsxs)(t,{variant:`warning`,children:[(0,X.jsx)(I,{}),` Pinned`]}),w.locked&&(0,X.jsxs)(t,{variant:`neutral`,children:[(0,X.jsx)(N,{}),` Locked: no new replies`]}),(0,X.jsxs)(t,{variant:`neutral`,children:[w.replyCount,` `,w.replyCount===1?`reply`:`replies`]})]})]}),w.canModerate&&(0,X.jsxs)(_,{children:[(0,X.jsx)(c,{asChild:!0,children:(0,X.jsx)(T,{variant:`outline`,size:`sm`,children:`Moderate`})}),(0,X.jsxs)(d,{children:[(0,X.jsxs)(i,{onSelect:()=>U.mutate({pinned:!w.pinned}),children:[w.pinned?(0,X.jsx)(K,{}):(0,X.jsx)(I,{}),` `,w.pinned?`Unpin`:`Pin to top`]}),(0,X.jsxs)(i,{onSelect:()=>U.mutate({locked:!w.locked}),children:[w.locked?(0,X.jsx)(W,{}):(0,X.jsx)(N,{}),` `,w.locked?`Unlock`:`Lock replies`]}),G&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(f,{}),(0,X.jsxs)(i,{destructive:!0,onSelect:()=>Y(G),children:[(0,X.jsx)(h,{}),` Delete discussion`]})]})]})]})]}),(0,X.jsx)(g,{className:`px-5 sm:px-6`,children:G&&(0,X.jsx)(`div`,{className:`divide-y`,children:(0,X.jsx)(Q,{post:G,childrenOf:new Map,depth:0,discussion:{...w,canReply:!1},onReply:(e,t)=>B(e,t),onEdit:V,onDelete:Y})})}),(0,X.jsxs)(`div`,{className:`mt-6`,children:[(0,X.jsxs)(`h2`,{className:`mb-2 text-sm font-semibold text-muted-foreground`,children:[w.replyCount,` `,w.replyCount===1?`reply`:`replies`]}),G&&(q.get(G.id)??[]).length>0&&(0,X.jsx)(g,{className:`divide-y px-5 sm:px-6`,children:(q.get(G.id)??[]).map(e=>(0,X.jsx)(Q,{post:e,childrenOf:q,depth:0,discussion:w,onReply:(e,t)=>B(e,t),onEdit:V,onDelete:Y},e.id))})]}),w.canReply?(0,X.jsxs)(g,{className:`mt-6 p-5`,children:[(0,X.jsx)(`p`,{className:`mb-3 text-sm font-semibold`,children:`Join the discussion`}),(0,X.jsx)(Z,{onSubmit:e=>B(null,e),submitLabel:`Post reply`})]}):w.locked&&(0,X.jsx)(`p`,{className:`mt-6 rounded-lg bg-muted px-4 py-3 text-center text-sm text-muted-foreground`,children:`This discussion is locked.`})]})}export{$ as default};
@@ -0,0 +1 @@
1
+ import{C as e,Dt as t,Ft as n,Gt as r,It as i,Nt as a,_ as o,at as s,c,dt as l,f as ee,t as te,u,y as d}from"./index-CEZdqKdi.js";import{E as f,H as p,N as m,U as h,_ as g,dt as _,ft as v,g as y,h as b,i as ne,m as x,mt as S,r as C,ut as re}from"./hooks-EFhyJ5yU.js";import{n as ie,t as ae}from"./arrow-up-lI30bvj5.js";import{E as w,c as T,n as E,t as D,w as oe}from"./misc-CyGhN6HT.js";import{t as O}from"./lock-C2edVDOc.js";import{n as se,t as k}from"./grades-ogaD0MDO.js";import{r as A}from"./context-D8W_QqNi.js";var j={name:`scale`,size:24,node:[[`path`,{d:`M12 3v18`,key:`108xh3`}],[`path`,{d:`m19 8 3 8a5 5 0 0 1-6 0zV7`,key:`zcdpyk`}],[`path`,{d:`M3 7h1a17 17 0 0 0 8-2 17 17 0 0 0 8 2h1`,key:`1yorad`}],[`path`,{d:`m5 8 3 8a5 5 0 0 1-6 0zV7`,key:`eua70x`}],[`path`,{d:`M7 21h10`,key:`1b0cd5`}]]};j.node;var M=p(j),N={name:`sigma`,size:24,node:[[`path`,{d:`M18 7V5a1 1 0 0 0-1-1H6.5a.5.5 0 0 0-.4.8l4.5 6a2 2 0 0 1 0 2.4l-4.5 6a.5.5 0 0 0 .4.8H17a1 1 0 0 0 1-1v-2`,key:`wuwx1p`}]]};N.node;var P=p(N),F=S(v(),1),I=_();function L(e){return{aggregation:e.aggregation,categories:e.categories.map(e=>({id:e.id,name:e.name,weight:String(e.weight),dropLowest:String(e.dropLowest),isDefault:e.isDefault})),items:Object.fromEntries(e.items.map(e=>[e.activityId,{categoryId:e.categoryId,weight:e.weight==null?``:String(e.weight)}]))}}var R=e=>e.trim()===``,z=e=>R(e)?0:Number(e);function B(e,t,n,r=!1){if(R(e))return!0;let i=Number(e);return Number.isFinite(i)&&i>=t&&i<=n&&(!r||Number.isInteger(i))}function V(e){return{aggregation:e.aggregation,categories:e.categories.map(e=>({id:e.id,name:e.name.trim(),weight:z(e.weight),dropLowest:z(e.dropLowest)})),items:Object.entries(e.items).map(([e,t])=>({activityId:e,categoryId:t.categoryId,weight:R(t.weight)?null:Number(t.weight)}))}}function ce(e){let t={},n=new Set;for(let r of e.categories){let i={},a=r.name.trim().toLocaleLowerCase();a?n.has(a)&&(i.name=`Another category has this name`):i.name=`Add a name`,n.add(a),e.aggregation===`weighted`&&!B(r.weight,0,100)&&(i.weight=`Use 0 to 100`),B(r.dropLowest,0,50,!0)||(i.dropLowest=`Use a whole number, 0 to 50`),Object.keys(i).length&&(t[r.id]=i)}let r={};if(e.aggregation===`weighted`)for(let[t,n]of Object.entries(e.items))B(n.weight,0,1e4)||(r[t]=`Use 0 to 10,000`);let i=e.aggregation===`weighted`&&!e.categories.some(e=>z(e.weight)>0),a=Object.entries(t)[0];return{categories:t,items:r,noWeight:i,firstField:a?`category-${a[0]}-${Object.keys(a[1])[0]}`:Object.keys(r)[0]?`item-${Object.keys(r)[0]}-weight`:i?`category-${e.categories[0]?.id}-weight`:null}}function H({title:e,description:t,children:n}){return(0,I.jsxs)(`section`,{className:`grid gap-6 border-b py-8 first:pt-0 last:border-0 last:pb-0 md:grid-cols-[240px_minmax(0,1fr)]`,children:[(0,I.jsxs)(`div`,{children:[(0,I.jsx)(`h2`,{className:`text-[15px] font-semibold`,children:e}),(0,I.jsx)(`div`,{className:`mt-1 text-sm text-muted-foreground`,children:t})]}),(0,I.jsx)(`div`,{className:`min-w-0 space-y-4`,children:n})]})}function U({id:e,children:t}){return(0,I.jsx)(`p`,{id:e,className:`mt-1 text-xs text-destructive`,children:t})}function le({weighted:e}){return(0,I.jsx)(`ul`,{className:`list-disc space-y-1 rounded-lg bg-muted/50 py-3 pr-4 pl-8 text-sm text-muted-foreground`,children:(e?[`Each category's subtotal counts by its weight. Categories with no grades yet are left out and the others are scaled up to fill 100%, so weights that don't add up to 100% still work.`,`A category with a weight of 0% never counts.`,`Within a category, activities count by their points unless you give them a weight.`]:[`The course total is the points earned out of the points possible on everything graded so far.`,`Work that hasn't been graded yet counts neither for nor against anyone.`,`Drop-lowest rules apply. Category and activity weights are kept but only used with weighted categories.`]).map(e=>(0,I.jsx)(`li`,{children:e},e))})}function W({setup:n,courseId:i,editable:o}){let p=re(),[h,_]=(0,F.useState)(()=>L(n)),[v,S]=(0,F.useState)(!1),[C,T]=(0,F.useState)(null),E=(0,F.useRef)(1),O=(0,F.useMemo)(()=>JSON.stringify(V(L(n))),[n]),A=JSON.stringify(V(h))!==O;ne(A);let j=ce(h);(0,F.useEffect)(()=>{if(!C)return;let e=document.getElementById(C);e?.focus({preventScroll:!0}),e?.scrollIntoView({block:`nearest`}),T(null)},[C]);let N=r({mutationFn:()=>x.put(`/courses/${i}/grades/setup`,V(h)),onSuccess:async e=>{p.setQueryData([`grade-setup`,i],e),_(L(e)),S(!1),w.success(`Gradebook setup saved`),await p.invalidateQueries({queryKey:[`grades`,i]})},onError:e=>w.error(b(e))}),W=h.aggregation===`weighted`,G=h.categories.find(e=>e.isDefault)?.id??i,K=h.categories.reduce((e,t)=>e+(B(t.weight,0,100)?z(t.weight):0),0),q=Math.abs(K-100)<.005,J=new Map;for(let e of Object.values(h.items))J.set(e.categoryId,(J.get(e.categoryId)??0)+1);let Y=(e,t)=>_(n=>({...n,categories:n.categories.map(n=>n.id===e?{...n,...t}:n)})),X=(e,t)=>_(n=>({...n,items:{...n.items,[e]:{...n.items[e],...t}}})),ue=e=>_(t=>{if(e===`weighted`)return{...t,aggregation:e};let r=L(n),i=new Map(r.categories.map(e=>[e.id,e.weight]));return{...t,aggregation:e,categories:t.categories.map(e=>B(e.weight,0,100)?e:{...e,weight:i.get(e.id)??`0`}),items:Object.fromEntries(Object.entries(t.items).map(([e,t])=>[e,B(t.weight,0,1e4)?t:{...t,weight:r.items[e]?.weight??``}]))}}),de=()=>{let e=`new-${E.current++}`;_(t=>{let n=[...t.categories],r=n[n.length-1]?.isDefault?n.length-1:n.length;return n.splice(r,0,{id:e,name:``,weight:`0`,dropLowest:`0`,isDefault:!1}),{...t,categories:n}}),T(`category-${e}-name`)},fe=e=>{_(t=>({...t,categories:t.categories.filter(t=>t.id!==e),items:Object.fromEntries(Object.entries(t.items).map(([t,n])=>[t,n.categoryId===e?{...n,categoryId:G}:n]))})),T(`add-category`)},Z=(e,t)=>{let n=h.categories.findIndex(t=>t.id===e),r=n+t;if(n<0||r<0||r>=h.categories.length)return;_(e=>{let t=[...e.categories];return[t[n],t[r]]=[t[r],t[n]],{...e,categories:t}});let i=r===0||r===h.categories.length-1;T(`category-${e}-${i?t<0?`down`:`up`:t<0?`up`:`down`}`)},pe=(0,F.useMemo)(()=>{let e=e=>{let t=h.items[e.activityId]?.weight??``;return!W||R(t)?e.maxGrade:B(t,0,1e4)&&e.maxGrade>0?Number(t):0},t=new Map;for(let r of n.items){let n=h.items[r.activityId]?.categoryId??G;t.set(n,(t.get(n)??0)+e(r))}return new Map(n.items.map(n=>{let r=t.get(h.items[n.activityId]?.categoryId??G)??0,i=e(n);return[n.activityId,r>0&&i>0?i/r*100:null]}))},[h.items,n.items,G,W]),Q=W?`sm:grid-cols-[minmax(0,1fr)_12rem_7rem]`:`sm:grid-cols-[minmax(0,1fr)_12rem]`,$=W?`grid-cols-[2rem_minmax(0,1fr)_2.25rem] sm:grid-cols-[2rem_minmax(0,1fr)_6.5rem_6.5rem_5.5rem_2.25rem]`:`grid-cols-[2rem_minmax(0,1fr)_2.25rem] sm:grid-cols-[2rem_minmax(0,1fr)_6.5rem_5.5rem_2.25rem]`;return(0,I.jsx)(`form`,{noValidate:!0,className:`[&_button]:scroll-mt-32 [&_button]:scroll-mb-28 [&_input]:scroll-mt-32 [&_input]:scroll-mb-28 [&_select]:scroll-mt-32 [&_select]:scroll-mb-28`,onSubmit:e=>{e.preventDefault(),j.firstField?(S(!0),T(j.firstField),w.error(`Some fields need fixing before you can save.`)):N.mutate()},children:(0,I.jsxs)(`fieldset`,{disabled:!o,className:`m-0 min-w-0 border-0 p-0`,children:[!o&&(0,I.jsx)(`p`,{className:`mb-4 rounded-lg border bg-muted/40 px-4 py-3 text-sm text-muted-foreground`,children:`You can see how grades are calculated here. Only teachers can change it.`}),(0,I.jsxs)(te,{className:`p-6 sm:p-8`,children:[(0,I.jsxs)(H,{title:`Course total`,description:`How grades add up to each student's course total.`,children:[(0,I.jsx)(c,{columns:2,value:h.aggregation,onChange:ue,options:[{value:`natural`,label:`Natural (points)`,description:`Points earned out of points possible. Activities worth more points count more.`,icon:(0,I.jsx)(P,{className:`size-4`})},{value:`weighted`,label:`Weighted categories`,description:`Each category is worth a set share of the total, however many points it has.`,icon:(0,I.jsx)(M,{className:`size-4`})}]}),(0,I.jsx)(le,{weighted:W})]}),(0,I.jsx)(H,{title:`Categories`,description:(0,I.jsxs)(I.Fragment,{children:[(0,I.jsx)(`p`,{children:`The order is used in the gradebook and on students' grades pages.`}),(0,I.jsxs)(`p`,{className:`mt-2`,children:[(0,I.jsx)(`span`,{className:`font-medium text-foreground`,children:`Drop lowest`}),` leaves out each student's lowest grades in the category. At least one grade always counts.`]})]}),children:(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{"aria-hidden":!0,className:g(`mb-2 hidden gap-x-3 px-2.5 text-xs font-medium text-muted-foreground sm:grid`,$),children:[(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{children:`Name`}),W&&(0,I.jsx)(`span`,{children:`Weight`}),(0,I.jsx)(`span`,{children:`Drop lowest`}),(0,I.jsx)(`span`,{className:`text-right`,children:`Activities`}),(0,I.jsx)(`span`,{})]}),(0,I.jsx)(`ol`,{className:`space-y-2`,children:h.categories.map((t,n)=>{let r=v?j.categories[t.id]??{}:{},i=t.name.trim()||`category ${n+1}`,a=J.get(t.id)??0,o=`category-${t.id}`;return(0,I.jsxs)(`li`,{className:g(`grid items-start gap-x-3 gap-y-2 rounded-lg border bg-card p-2.5 sm:items-center`,$),children:[(0,I.jsxs)(`div`,{className:`row-span-2 flex flex-col items-center sm:row-span-1`,children:[(0,I.jsx)(y,{type:`button`,variant:`ghost`,size:`icon-xs`,id:`${o}-up`,"aria-label":`Move ${i} up`,disabled:n===0,onClick:()=>Z(t.id,-1),children:(0,I.jsx)(ae,{})}),(0,I.jsx)(y,{type:`button`,variant:`ghost`,size:`icon-xs`,id:`${o}-down`,"aria-label":`Move ${i} down`,disabled:n===h.categories.length-1,onClick:()=>Z(t.id,1),children:(0,I.jsx)(ie,{})})]}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(u,{id:`${o}-name`,"aria-label":`Name of category ${n+1}`,placeholder:`Category name`,maxLength:80,value:t.name,onChange:e=>Y(t.id,{name:e.target.value}),"aria-invalid":r.name?!0:void 0,"aria-describedby":r.name?`${o}-name-error`:void 0}),r.name&&(0,I.jsx)(U,{id:`${o}-name-error`,children:r.name}),t.isDefault&&(0,I.jsxs)(`p`,{className:`mt-1.5 text-xs text-muted-foreground`,children:[(0,I.jsx)(e,{variant:`neutral`,className:`mr-1.5`,children:`Default`}),`Activities without a category count here.`]}),W&&a>0&&z(t.weight)===0&&(0,I.jsxs)(`p`,{className:`mt-1 text-xs text-amber-700 dark:text-amber-400`,children:[`Its `,m(a,`activity`,`activities`),` won't count while its weight is 0%.`]})]}),(0,I.jsxs)(`div`,{className:`col-span-2 col-start-2 row-start-2 grid grid-cols-2 items-start gap-x-3 gap-y-1.5 sm:contents`,children:[W&&(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsxs)(`label`,{htmlFor:`${o}-weight`,className:`mb-1 block text-xs text-muted-foreground sm:sr-only`,children:[`Weight`,(0,I.jsxs)(`span`,{className:`sr-only`,children:[` of `,i]})]}),(0,I.jsxs)(`div`,{className:`relative`,children:[(0,I.jsx)(u,{id:`${o}-weight`,type:`number`,inputMode:`decimal`,min:0,max:100,step:`any`,value:t.weight,onChange:e=>Y(t.id,{weight:e.target.value}),className:`[appearance:textfield] pr-7 text-right tabular-nums [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none`,"aria-invalid":r.weight?!0:void 0,"aria-describedby":r.weight?`${o}-weight-error`:void 0}),(0,I.jsx)(`span`,{"aria-hidden":!0,className:`pointer-events-none absolute top-1/2 right-3 -translate-y-1/2 text-sm text-muted-foreground`,children:`%`})]}),r.weight&&(0,I.jsx)(U,{id:`${o}-weight-error`,children:r.weight})]}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsxs)(`label`,{htmlFor:`${o}-dropLowest`,className:`mb-1 block text-xs text-muted-foreground sm:sr-only`,children:[`Drop lowest`,(0,I.jsxs)(`span`,{className:`sr-only`,children:[` in `,i]})]}),(0,I.jsx)(u,{id:`${o}-dropLowest`,type:`number`,inputMode:`numeric`,min:0,max:50,step:1,value:t.dropLowest,onChange:e=>Y(t.id,{dropLowest:e.target.value}),className:`text-right tabular-nums`,"aria-invalid":r.dropLowest?!0:void 0,"aria-describedby":r.dropLowest?`${o}-dropLowest-error`:void 0}),r.dropLowest&&(0,I.jsx)(U,{id:`${o}-dropLowest-error`,children:r.dropLowest})]}),(0,I.jsx)(`p`,{className:`col-span-2 text-xs text-muted-foreground tabular-nums sm:col-span-1 sm:self-center sm:text-right`,children:m(a,`activity`,`activities`)})]}),(0,I.jsx)(`div`,{className:`col-start-3 row-start-1 sm:col-start-auto sm:row-start-auto`,children:!t.isDefault&&(0,I.jsx)(y,{type:`button`,variant:`ghost`,size:`icon-sm`,"aria-label":`Delete ${i}`,className:`text-muted-foreground hover:text-destructive`,onClick:()=>fe(t.id),children:(0,I.jsx)(s,{})})})]},t.id)})}),(0,I.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center justify-between gap-3`,children:[(0,I.jsxs)(y,{type:`button`,variant:`outline`,size:`sm`,id:`add-category`,onClick:de,disabled:h.categories.length>=50,children:[(0,I.jsx)(l,{}),` Add category`]}),W&&(0,I.jsxs)(`p`,{role:`status`,className:g(`inline-flex items-center gap-1.5 text-sm font-medium tabular-nums`,q?`text-emerald-600 dark:text-emerald-400`:`text-amber-700 dark:text-amber-400`),children:[q?(0,I.jsx)(t,{className:`size-4`}):(0,I.jsx)(oe,{className:`size-4`}),`Weights add up to `,se(K)]})]}),W&&!q&&(0,I.jsx)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:`That still works: totals are scaled over the categories that have grades, so weights act as proportions. Make them add up to 100% so they read as shares of the course total.`}),v&&j.noWeight&&(0,I.jsx)(`p`,{className:`mt-2 text-sm text-destructive`,children:`Give at least one category a weight above 0%, or nothing would count.`})]})}),(0,I.jsx)(H,{title:`Graded activities`,description:W?`Choose a category for each activity. Activities count by their points; give one a weight to set its share of the category instead (weights 1 and 3 make 25% and 75%).`:`Choose a category for each activity. With natural totals every activity counts by its points; activity weights come with weighted categories.`,children:n.items.length===0?(0,I.jsx)(D,{icon:a,title:`No graded activities yet`,description:`Assignments and quizzes show up here once you add them. You can set up the categories now.`}):(0,I.jsxs)(`div`,{children:[(0,I.jsxs)(`div`,{"aria-hidden":!0,className:g(`mb-2 hidden gap-x-3 px-3 text-xs font-medium text-muted-foreground sm:grid`,Q),children:[(0,I.jsx)(`span`,{children:`Activity`}),(0,I.jsx)(`span`,{children:`Category`}),W&&(0,I.jsx)(`span`,{className:`text-right`,children:`Weight`})]}),(0,I.jsx)(`ul`,{className:`divide-y rounded-lg border`,children:n.items.map(e=>{let t=h.items[e.activityId]??{categoryId:G,weight:``},n=v?j.items[e.activityId]:void 0,r=pe.get(e.activityId)??null,i=h.categories.find(e=>e.id===t.categoryId)?.name.trim()||`its category`,a=`item-${e.activityId}`;return(0,I.jsxs)(`li`,{className:g(`grid gap-x-3 gap-y-2.5 px-3 py-3 sm:items-center`,Q),children:[(0,I.jsxs)(`div`,{className:`flex min-w-0 items-center gap-3`,children:[(0,I.jsx)(d,{type:e.type,size:`sm`}),(0,I.jsxs)(`div`,{className:`min-w-0`,children:[(0,I.jsx)(`p`,{className:`truncate text-sm font-medium`,id:`${a}-title`,children:e.title}),(0,I.jsxs)(`p`,{className:`truncate text-xs text-muted-foreground`,children:[f(e.maxGrade),` points`,!e.visible&&` · hidden`,` · `,r==null?`doesn't count`:`${k(r)} of ${i}`]})]})]}),(0,I.jsxs)(`div`,{className:g(`grid items-start gap-2 sm:contents`,W&&`grid-cols-[minmax(0,1fr)_7rem]`),children:[(0,I.jsx)(ee,{"aria-label":`Category for ${e.title}`,value:t.categoryId,onChange:t=>X(e.activityId,{categoryId:t.target.value}),children:h.categories.map((e,t)=>(0,I.jsx)(`option`,{value:e.id,children:e.name.trim()||`Category ${t+1}`},e.id))}),W&&(0,I.jsxs)(`div`,{children:[(0,I.jsx)(u,{id:`${a}-weight`,type:`number`,inputMode:`decimal`,min:0,step:`any`,"aria-label":`Weight of ${e.title} in its category`,placeholder:`${f(e.maxGrade)} pts`,value:t.weight,onChange:t=>X(e.activityId,{weight:t.target.value}),className:`text-right tabular-nums`,"aria-invalid":n?!0:void 0,"aria-describedby":n?`${a}-weight-error`:void 0}),n&&(0,I.jsx)(U,{id:`${a}-weight-error`,children:n})]})]})]},e.activityId)})})]})})]}),o&&(0,I.jsxs)(`div`,{className:`sticky bottom-4 z-10 mt-6 flex items-center justify-end gap-3 rounded-xl border bg-card/90 p-3 shadow-lg backdrop-blur`,children:[A&&(0,I.jsx)(`span`,{className:`mr-auto pl-2 text-sm text-muted-foreground`,children:`You have unsaved changes`}),(0,I.jsx)(y,{type:`button`,variant:`ghost`,disabled:!A,onClick:()=>{_(L(n)),S(!1)},children:`Discard`}),(0,I.jsx)(y,{type:`submit`,loading:N.isPending,disabled:!A,children:`Save changes`})]})]})})}function G(){let{course:e,can:t}=A();C(`Categories & weights · ${e.title}`);let r=t(`grades:viewAll`),{data:a,isLoading:s,error:c,refetch:l}=h({queryKey:[`grade-setup`,e.id],queryFn:()=>x.get(`/courses/${e.id}/grades/setup`),enabled:r});return(0,I.jsxs)(o,{children:[(0,I.jsxs)(`div`,{className:`mb-6`,children:[(0,I.jsxs)(i,{to:`/courses/${e.slug}/grades`,className:`inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground`,children:[(0,I.jsx)(n,{className:`size-4`}),` Grades`]}),(0,I.jsx)(`h1`,{className:`mt-2 text-2xl font-semibold tracking-tight`,children:`Categories & weights`}),(0,I.jsx)(`p`,{className:`mt-1 max-w-2xl text-sm text-muted-foreground`,children:`Group graded activities into categories, decide what each one is worth and choose how the course total is calculated.`})]}),r?c?(0,I.jsx)(E,{error:c,onRetry:()=>l()}):s||!a?(0,I.jsx)(T,{className:`h-[560px]`}):(0,I.jsx)(W,{setup:a,courseId:e.id,editable:t(`grades:manage`)}):(0,I.jsx)(D,{icon:O,title:`Only course staff can see this`,description:`Teachers set up grade categories and weights here. Your grades and how they add up are on the Grades page.`,action:(0,I.jsx)(y,{asChild:!0,variant:`outline`,size:`sm`,children:(0,I.jsx)(i,{to:`/courses/${e.slug}/grades`,children:`Go to my grades`})})})]})}export{G as default};
@@ -0,0 +1 @@
1
+ import{C as e,Gt as t,It as n,M as r,Nt as i,T as a,X as o,Y as s,Z as c,_ as l,l as u,lt as d,m as f,t as p,u as m,y as h}from"./index-CEZdqKdi.js";import{E as g,H as _,N as v,U as y,_ as b,dt as x,ft as S,g as C,h as ee,m as w,mt as T,r as E,ut as D,w as O}from"./hooks-EFhyJ5yU.js";import{t as k}from"./download-BrtK5sVk.js";import{t as A}from"./message-square-text-wvO9_guT.js";import{E as j,a as M,c as N,n as P,o as F,t as I}from"./misc-CyGhN6HT.js";import{a as L,i as R,n as z,o as B,r as V,t as H}from"./grades-ogaD0MDO.js";import{n as U,o as W}from"./groups-CrYV_AFp.js";import{r as G}from"./context-D8W_QqNi.js";var K={name:`sliders-horizontal`,size:24,node:[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]};K.node;var q=_(K),J=T(S(),1),Y=x();function X(e,t,n){let r=[e.aggregation===`weighted`?`${z(t)} of total`:`Subtotal`];return n>0&&r.push(`drops lowest ${n}`),r.join(` · `)}function Z({book:e}){let t=R(e);if(t.length===0)return null;let n=e.aggregation===`weighted`;return(0,Y.jsxs)(`tr`,{className:`text-left text-xs`,children:[(0,Y.jsx)(`td`,{className:`sticky left-0 z-10 bg-card`}),t.map(e=>(0,Y.jsx)(`th`,{scope:`colgroup`,colSpan:e.itemCount,className:`px-1.5 pt-3 font-medium`,title:e.name,children:(0,Y.jsxs)(`span`,{className:`flex items-baseline gap-2 border-b-2 border-primary/35 px-1.5 pb-1.5`,children:[(0,Y.jsx)(`span`,{className:`truncate text-foreground`,children:e.name}),n&&(0,Y.jsx)(`span`,{className:`ml-auto shrink-0 font-normal text-muted-foreground tabular-nums`,children:z(e.weight)})]})},e.id)),(0,Y.jsx)(`th`,{scope:`colgroup`,colSpan:t.length,className:`px-1.5 pt-3 font-medium`,children:(0,Y.jsx)(`span`,{className:`block border-b-2 border-foreground/20 px-1.5 pb-1.5 text-foreground`,children:`Category totals`})}),(0,Y.jsx)(`td`,{className:`bg-muted/40`})]})}function te({book:e}){return(0,Y.jsx)(Y.Fragment,{children:R(e).map(t=>(0,Y.jsxs)(`th`,{scope:`col`,className:`min-w-28 border-b px-3 py-3 text-right align-bottom font-medium`,children:[(0,Y.jsx)(`span`,{className:`line-clamp-2 text-foreground`,children:t.name}),(0,Y.jsx)(`span`,{className:`mt-1.5 block font-normal`,children:X(e,t.weight,t.dropLowest)})]},t.id))})}function ne({book:e,row:t}){return(0,Y.jsx)(Y.Fragment,{children:R(e).map(e=>{let n=t.categories[e.id]?.percentage??null;return(0,Y.jsx)(`td`,{className:`border-b px-3 py-2.5 text-right group-hover:bg-accent/40`,children:(0,Y.jsx)(`span`,{className:b(`font-medium tabular-nums`,V(n)),children:H(n)})},e.id)})})}function re({book:e}){return(0,Y.jsx)(Y.Fragment,{children:R(e).map(t=>(0,Y.jsx)(`td`,{className:`bg-muted/60 px-3 py-3 text-right tabular-nums`,children:H(e.categoryAverages[t.id])},t.id))})}function Q({courseSlug:e}){let{can:t}=G();return t(`grades:manage`)?(0,Y.jsx)(C,{asChild:!0,variant:`outline`,size:`sm`,children:(0,Y.jsxs)(n,{to:`/courses/${e}/grades/setup`,"aria-label":`Categories and weights`,children:[(0,Y.jsx)(q,{}),(0,Y.jsx)(`span`,{className:`hidden sm:inline`,children:`Categories & weights`})]})}):null}function ie({item:t,courseSlug:r,category:i}){let o=t.score!=null&&t.maxGrade?t.score/t.maxGrade*100:null;return(0,Y.jsxs)(`div`,{className:`px-5 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(h,{type:t.type}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(n,{to:a(r,t.activityId),className:`block truncate text-sm font-medium hover:text-primary`,children:t.title}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:t.gradedAt?`Graded ${O(t.gradedAt)}`:t.dueAt?`Due ${O(t.dueAt)}`:`Not graded yet`})]}),(0,Y.jsxs)(`div`,{className:`text-right`,children:[(0,Y.jsxs)(`p`,{className:b(`text-sm font-semibold tabular-nums`,t.dropped?`text-muted-foreground line-through`:V(o)),children:[t.score==null?`–`:g(t.score),` `,(0,Y.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`/ `,g(t.maxGrade)]})]}),t.dropped?(0,Y.jsx)(e,{variant:`neutral`,className:`mt-1`,children:`Dropped`}):o!=null&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground tabular-nums`,children:[g(o),`%`]})]})]}),o!=null&&!t.dropped&&(0,Y.jsx)(M,{value:o,className:`mt-3`,tone:o>=85?`success`:`primary`}),t.dropped&&(0,Y.jsxs)(`p`,{className:`mt-2 text-xs text-muted-foreground`,children:[`Not counted: `,i.name,` leaves out your lowest `,i.dropLowest===1?`grade`:`${i.dropLowest} grades`,`, and this is `,i.dropLowest===1?`it`:`one of them`,`.`]}),t.feedback&&(0,Y.jsxs)(`div`,{className:`mt-3 rounded-lg bg-muted/60 px-3.5 py-2.5 text-sm`,children:[(0,Y.jsx)(`p`,{className:`mb-0.5 text-xs font-medium text-muted-foreground`,children:`Feedback`}),t.feedback]})]})}function ae(e,t){let n=[];return t?n.push(e.weight>0?`${z(e.weight)} of the course total`:`Doesn't count towards the course total`):e.possible>0&&n.push(`${g(e.earned,2)} of ${g(e.possible,2)} points`),e.dropLowest>0&&n.push(`lowest ${e.dropLowest===1?`grade`:`${e.dropLowest} grades`} dropped`),n.join(` · `)}function oe({categories:e,weighted:t}){let n=t&&e.some(e=>e.weight>0&&e.share!=null&&Math.abs(e.share-e.weight)>.005);return(0,Y.jsxs)(`div`,{className:`mt-5 border-t pt-4 text-left`,children:[(0,Y.jsx)(`h3`,{className:`text-xs font-medium text-muted-foreground`,children:`How your total adds up`}),(0,Y.jsx)(`ul`,{className:`mt-3 space-y-3`,children:e.map(e=>(0,Y.jsxs)(`li`,{children:[(0,Y.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 text-sm`,children:[(0,Y.jsx)(`span`,{className:`min-w-0 truncate font-medium`,children:e.name}),(0,Y.jsx)(`span`,{className:b(`shrink-0 font-semibold tabular-nums`,V(e.percentage)),children:H(e.percentage)})]}),(0,Y.jsxs)(`div`,{className:`mt-0.5 flex items-baseline justify-between gap-3 text-xs text-muted-foreground`,children:[(0,Y.jsx)(`span`,{children:t?`Weight ${z(e.weight)}`:`${g(e.possible,2)} points so far`}),(0,Y.jsx)(`span`,{className:`tabular-nums`,children:e.share==null?`not counted yet`:`counts ${H(e.share)}`})]}),(0,Y.jsx)(M,{value:e.share??0,className:`mt-1.5 h-1`})]},e.id))}),n&&(0,Y.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Categories without grades yet don't count, so the others are scaled up to make 100%. This changes as more work is graded.`})]})}function se({grades:t,courseSlug:n}){if(t.items.length===0)return(0,Y.jsx)(I,{icon:i,title:`Nothing graded yet`,description:`Grades for assignments and quizzes will show up here.`});let r=t.aggregation===`weighted`,a=L(t.categories,t.items),o=r?t.categories.filter(e=>e.weight>0||a.some(t=>t.id===e.id)):a;return(0,Y.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_300px]`,children:[(0,Y.jsx)(`div`,{className:`space-y-5`,children:a.map(e=>(0,Y.jsx)(p,{className:`overflow-hidden`,children:(0,Y.jsxs)(`section`,{"aria-labelledby":`grade-category-${e.id}`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 border-b bg-muted/30 px-5 py-3`,children:[(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(`h2`,{id:`grade-category-${e.id}`,className:`truncate text-sm font-semibold`,children:e.name}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:ae(e,r)||v(e.itemCount,`activity`,`activities`)})]}),(0,Y.jsxs)(`div`,{className:`shrink-0 text-right`,children:[(0,Y.jsx)(`p`,{className:b(`text-sm font-semibold tabular-nums`,V(e.percentage)),children:H(e.percentage)}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.percentage==null?`Nothing graded yet`:`Subtotal`})]})]}),(0,Y.jsx)(`div`,{className:`divide-y`,children:t.items.filter(t=>t.categoryId===e.id).map(t=>(0,Y.jsx)(ie,{item:t,courseSlug:n,category:e},t.activityId))})]})},e.id))}),(0,Y.jsxs)(p,{className:`p-5 text-center lg:sticky lg:top-32`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Course total`}),(0,Y.jsx)(F,{value:t.percentage??0,size:120,stroke:9,className:`mx-auto mt-4 text-primary`,label:(0,Y.jsx)(`span`,{className:`text-2xl font-semibold`,children:H(t.percentage)})}),(0,Y.jsx)(`p`,{className:`mt-4 text-sm`,children:r?`Weighted by category`:`${g(t.total)} of ${g(t.max)} points`}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Based on graded work so far.`}),t.percentage!=null&&(0,Y.jsx)(e,{variant:t.percentage>=85?`success`:t.percentage>=60?`info`:`warning`,className:`mt-3`,children:t.percentage>=85?`Excellent work`:t.percentage>=60?`On track`:`Needs attention`}),(0,Y.jsx)(oe,{categories:o,weighted:r})]})]})}function $(e){return e==null?`text-muted-foreground`:e>=85?`text-emerald-600 dark:text-emerald-400`:e>=60?`text-foreground`:`text-red-600 dark:text-red-400`}function ce({courseId:e,item:n,userId:r,score:i,feedback:a,editable:l,dropped:d=!1}){let p=D(),[h,_]=(0,J.useState)(!1),[v,y]=(0,J.useState)(i?.toString()??``),[x,S]=(0,J.useState)(a??``),T=t({mutationFn:()=>w.put(`/courses/${e}/grades/${n.activityId}/${r}`,{score:v===``?null:Number(v),feedback:x.trim()||null}),onSuccess:async()=>{_(!1),j.success(`Grade saved`),await p.invalidateQueries({queryKey:[`grades`,e]})},onError:e=>j.error(ee(e))}),E=i!=null&&n.maxGrade?i/n.maxGrade*100:null,O=(0,Y.jsxs)(`span`,{className:b(`inline-flex items-center gap-1 tabular-nums`,d?`text-muted-foreground line-through`:$(E)),title:d?`Dropped: one of the lowest grades in its category`:void 0,children:[i==null?(0,Y.jsx)(`span`,{className:`text-muted-foreground/50`,children:`–`}):g(i),d&&(0,Y.jsx)(`span`,{className:`sr-only`,children:` (dropped)`}),a&&(0,Y.jsx)(A,{className:`size-3 text-muted-foreground`})]});return l?(0,Y.jsxs)(s,{open:h,onOpenChange:e=>{_(e),e&&(y(i?.toString()??``),S(a??``))},children:[(0,Y.jsx)(c,{asChild:!0,children:(0,Y.jsx)(`button`,{className:`w-full rounded-md px-2 py-1 text-right transition-colors hover:bg-accent`,children:O})}),(0,Y.jsx)(o,{align:`end`,className:`w-72`,children:(0,Y.jsxs)(`form`,{className:`space-y-3`,onSubmit:e=>{e.preventDefault(),T.mutate()},children:[(0,Y.jsx)(`p`,{className:`text-sm font-semibold`,children:n.title}),(0,Y.jsx)(u,{label:`Score (out of ${g(n.maxGrade)})`,children:e=>(0,Y.jsx)(m,{...e,type:`number`,step:`any`,min:0,max:n.maxGrade,autoFocus:!0,value:v,onChange:e=>y(e.target.value)})}),(0,Y.jsx)(u,{label:`Feedback`,optional:!0,children:e=>(0,Y.jsx)(f,{...e,rows:3,value:x,onChange:e=>S(e.target.value)})}),(0,Y.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,Y.jsx)(C,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>_(!1),children:`Cancel`}),(0,Y.jsx)(C,{type:`submit`,size:`sm`,loading:T.isPending,children:`Save`})]})]})})]}):O}function le({book:e,courseId:t,courseSlug:o,editable:s,groupFilter:c}){let l=c.groupId?`?groupId=${encodeURIComponent(c.groupId)}`:``,[u,f]=(0,J.useState)(``),_=(0,J.useMemo)(()=>{let t=u.trim().toLowerCase();return e.rows.filter(e=>!t||e.user.name.toLowerCase().includes(t)||e.user.email.toLowerCase().includes(t))},[e.rows,u]);return e.items.length===0?(0,Y.jsx)(I,{icon:i,title:`No graded activities yet`,description:`Assignments and quizzes appear here as soon as you add them.`,action:(0,Y.jsx)(Q,{courseSlug:o})}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)(`div`,{className:`mb-4 flex flex-col gap-3 sm:flex-row sm:items-center`,children:[(0,Y.jsxs)(`div`,{className:`relative sm:w-72`,children:[(0,Y.jsx)(d,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,Y.jsx)(m,{value:u,onChange:e=>f(e.target.value),placeholder:`Find a student`,className:`pl-9`,"aria-label":`Find a student`})]}),(0,Y.jsx)(U,{filter:c}),(0,Y.jsxs)(`div`,{className:`flex items-center gap-4 sm:ml-auto`,children:[(0,Y.jsxs)(`span`,{className:`text-sm text-muted-foreground`,children:[c.active?`Group average`:`Class average`,` `,(0,Y.jsx)(`span`,{className:`font-semibold text-foreground`,children:H(e.courseAverage)})]}),(0,Y.jsx)(Q,{courseSlug:o}),(0,Y.jsx)(C,{asChild:!0,variant:`outline`,size:`sm`,children:(0,Y.jsxs)(`a`,{href:`/api/courses/${t}/grades/export.csv${l}`,download:!0,children:[(0,Y.jsx)(k,{}),` Export CSV`]})})]})]}),(0,Y.jsx)(p,{className:`overflow-hidden`,children:(0,Y.jsx)(`div`,{className:`ck-scrollbar overflow-x-auto`,children:(0,Y.jsxs)(`table`,{className:`w-full border-separate border-spacing-0 text-sm`,children:[(0,Y.jsxs)(`thead`,{children:[(0,Y.jsx)(Z,{book:e}),(0,Y.jsxs)(`tr`,{className:`text-left text-xs text-muted-foreground`,children:[(0,Y.jsx)(`th`,{className:`sticky left-0 z-10 min-w-56 border-b bg-card px-5 py-3 font-medium`,children:`Student`}),e.items.map(e=>(0,Y.jsx)(`th`,{className:`min-w-32 border-b px-3 py-3 text-right align-bottom font-medium`,children:(0,Y.jsxs)(n,{to:a(o,e.activityId),className:`group inline-flex flex-col items-end gap-1.5`,children:[(0,Y.jsx)(h,{type:e.type,size:`sm`}),(0,Y.jsx)(`span`,{className:`line-clamp-2 max-w-32 text-foreground group-hover:text-primary`,children:e.title}),(0,Y.jsxs)(`span`,{className:`font-normal`,children:[`/ `,g(e.maxGrade)]})]})},e.activityId)),(0,Y.jsx)(te,{book:e}),(0,Y.jsx)(`th`,{className:`min-w-28 border-b bg-muted/40 px-5 py-3 text-right align-bottom font-medium text-foreground`,children:`Total`})]})]}),(0,Y.jsx)(`tbody`,{children:_.map(n=>(0,Y.jsxs)(`tr`,{className:`group`,children:[(0,Y.jsx)(`td`,{className:`sticky left-0 z-10 border-b bg-card px-5 py-2.5 group-hover:bg-accent`,children:(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(r,{user:n.user,size:`sm`}),(0,Y.jsxs)(`div`,{className:`min-w-0`,children:[(0,Y.jsx)(`p`,{className:`truncate font-medium`,children:n.user.name}),(0,Y.jsx)(`p`,{className:`truncate text-xs text-muted-foreground`,children:n.user.email})]})]})}),e.items.map(e=>(0,Y.jsx)(`td`,{className:`border-b px-1.5 py-2 text-right group-hover:bg-accent/40`,children:(0,Y.jsx)(ce,{courseId:t,item:e,userId:n.user.id,score:n.cells[e.activityId]?.score??null,feedback:n.cells[e.activityId]?.feedback??null,editable:s,dropped:n.cells[e.activityId]?.dropped})},e.activityId)),(0,Y.jsx)(ne,{book:e,row:n}),(0,Y.jsxs)(`td`,{className:`border-b bg-muted/40 px-5 py-2.5 text-right`,children:[(0,Y.jsx)(`span`,{className:b(`font-semibold tabular-nums`,$(n.percentage)),children:H(n.percentage)}),e.aggregation!==`weighted`&&(0,Y.jsxs)(`span`,{className:`block text-xs text-muted-foreground tabular-nums`,children:[g(n.total),` / `,g(n.max)]})]})]},n.user.id))}),(0,Y.jsx)(`tfoot`,{children:(0,Y.jsxs)(`tr`,{className:`text-xs text-muted-foreground`,children:[(0,Y.jsx)(`td`,{className:`sticky left-0 z-10 bg-muted/60 px-5 py-3 font-medium text-foreground`,children:`Average`}),e.items.map(t=>(0,Y.jsx)(`td`,{className:`bg-muted/60 px-3 py-3 text-right tabular-nums`,children:g(e.averages[t.activityId])},t.activityId)),(0,Y.jsx)(re,{book:e}),(0,Y.jsx)(`td`,{className:`bg-muted/60 px-5 py-3 text-right font-semibold text-foreground tabular-nums`,children:H(e.courseAverage)})]})})]})})}),s&&(0,Y.jsx)(`p`,{className:`mt-3 text-xs text-muted-foreground`,children:`Click any grade to change it or leave feedback. Students are notified when they receive a grade.`})]})}function ue({grades:t,courseSlug:r}){return t.items.length===0?(0,Y.jsx)(I,{icon:i,title:`Nothing graded yet`,description:`Grades for assignments and quizzes will show up here.`}):(0,Y.jsxs)(`div`,{className:`grid items-start gap-6 lg:grid-cols-[minmax(0,1fr)_280px]`,children:[(0,Y.jsx)(p,{className:`divide-y overflow-hidden`,children:t.items.map(e=>{let t=e.score!=null&&e.maxGrade?e.score/e.maxGrade*100:null;return(0,Y.jsxs)(`div`,{className:`px-5 py-4`,children:[(0,Y.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,Y.jsx)(h,{type:e.type}),(0,Y.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,Y.jsx)(n,{to:a(r,e.activityId),className:`truncate text-sm font-medium hover:text-primary`,children:e.title}),(0,Y.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:e.gradedAt?`Graded ${O(e.gradedAt)}`:e.dueAt?`Due ${O(e.dueAt)}`:`Not graded yet`})]}),(0,Y.jsxs)(`div`,{className:`text-right`,children:[(0,Y.jsxs)(`p`,{className:b(`text-sm font-semibold tabular-nums`,$(t)),children:[e.score==null?`–`:g(e.score),` `,(0,Y.jsxs)(`span`,{className:`font-normal text-muted-foreground`,children:[`/ `,g(e.maxGrade)]})]}),t!=null&&(0,Y.jsxs)(`p`,{className:`text-xs text-muted-foreground tabular-nums`,children:[g(t),`%`]})]})]}),t!=null&&(0,Y.jsx)(M,{value:t,className:`mt-3`,tone:t>=85?`success`:`primary`}),e.feedback&&(0,Y.jsxs)(`div`,{className:`mt-3 rounded-lg bg-muted/60 px-3.5 py-2.5 text-sm`,children:[(0,Y.jsx)(`p`,{className:`mb-0.5 text-xs font-medium text-muted-foreground`,children:`Feedback`}),e.feedback]})]},e.activityId)})}),(0,Y.jsxs)(p,{className:`p-5 text-center lg:sticky lg:top-32`,children:[(0,Y.jsx)(`p`,{className:`text-sm font-medium text-muted-foreground`,children:`Course total`}),(0,Y.jsx)(F,{value:t.percentage??0,size:120,stroke:9,className:`mx-auto mt-4 text-primary`,label:(0,Y.jsx)(`span`,{className:`text-2xl font-semibold`,children:H(t.percentage)})}),(0,Y.jsxs)(`p`,{className:`mt-4 text-sm tabular-nums`,children:[g(t.total),` of `,g(t.max),` points`]}),(0,Y.jsx)(`p`,{className:`mt-1 text-xs text-muted-foreground`,children:`Based on graded work so far.`}),t.percentage!=null&&(0,Y.jsx)(e,{variant:t.percentage>=85?`success`:t.percentage>=60?`info`:`warning`,className:`mt-3`,children:t.percentage>=85?`Excellent work`:t.percentage>=60?`On track`:`Needs attention`})]})]})}function de(){let{course:e,can:t}=G();E(`Grades · ${e.title}`);let n=W(t(`grades:viewAll`)?e.id:void 0),r=n.groupId,{data:i,isLoading:a,error:o,refetch:s}=y({queryKey:[`grades`,e.id,r],queryFn:()=>w.get(`/courses/${e.id}/grades${r?`?groupId=${encodeURIComponent(r)}`:``}`),placeholderData:e=>e});return(0,Y.jsx)(l,{size:`wide`,children:o?(0,Y.jsx)(P,{error:o,onRetry:()=>s()}):a||!i?(0,Y.jsx)(N,{className:`h-96`}):i.kind===`gradebook`?(0,Y.jsx)(le,{book:i.gradebook,courseId:e.id,courseSlug:e.slug,editable:t(`grades:edit`),groupFilter:n}):(0,Y.jsx)(`div`,{className:`mx-auto max-w-5xl`,children:B(i.grades)?(0,Y.jsx)(se,{grades:i.grades,courseSlug:e.slug}):(0,Y.jsx)(ue,{grades:i.grades,courseSlug:e.slug})})})}export{de as default};
@@ -0,0 +1 @@
1
+ import{$ as e,A as t,C as n,D as r,E as i,Gt as a,H as o,J as s,M as c,O as l,U as u,V as d,W as f,_ as p,at as m,c as h,dt as g,et as _,k as v,l as y,lt as b,m as x,nt as S,p as C,s as w,t as T,u as E,z as D}from"./index-CEZdqKdi.js";import{H as O,N as k,U as A,_ as j,dt as M,ft as N,g as P,h as F,m as I,mt as L,r as R,s as ee,u as z,ut as te}from"./hooks-EFhyJ5yU.js";import{t as B}from"./ellipsis-BDmYLoyn.js";import{t as ne}from"./pencil-DFUpj3YP.js";import{t as V}from"./shuffle-C1aB_4dp.js";import{t as H}from"./users-round-CNhv0Whm.js";import{E as U,c as W,n as G,s as re,t as K}from"./misc-CyGhN6HT.js";import{a as ie,i as ae,r as oe,t as se}from"./groups-CrYV_AFp.js";import{r as ce}from"./context-D8W_QqNi.js";var q={name:`layout-grid`,size:24,node:[[`rect`,{width:`7`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`1g98yp`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`3`,rx:`1`,key:`6d4xhi`}],[`rect`,{width:`7`,height:`7`,x:`14`,y:`14`,rx:`1`,key:`nxv5o0`}],[`rect`,{width:`7`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`1bb6yr`}]]};q.node;var le=O(q),J={name:`user-round-x`,size:24,node:[[`path`,{d:`m16.5 16.5 5 5`,key:`zc9lw7`}],[`path`,{d:`M2 21a8 8 0 0 1 11.531-7.18`,key:`x5izle`}],[`path`,{d:`m21.5 16.5-5 5`,key:`1empo3`}],[`circle`,{cx:`10`,cy:`8`,r:`5`,key:`o932ke`}]],aliases:[`user-x-2`]};J.node;var ue=O(J),Y=L(N(),1),de=`Group @`;function fe(e){let t=``;for(let n=e;n>0;n=Math.floor((n-1)/26))t=String.fromCharCode(65+(n-1)%26)+t;return t}function pe(e,t,n){let r=new Set([...n].map(e=>e.toLowerCase())),i=/[#@]/.test(e)?e:`${e} #`,a=[];for(let e=1;a.length<t;e++){let t=i.replaceAll(`#`,String(e)).replaceAll(`@`,fe(e));r.has(t.toLowerCase())||(r.add(t.toLowerCase()),a.push(t))}return a}function me(e,t,n){return e===`groups`?t:Math.ceil(n/t)}var X=M(),Z=e=>k(e,`person`,`people`);function he(e){let t=te();return()=>Promise.all([t.invalidateQueries({queryKey:ae(e.id)}),t.invalidateQueries({queryKey:[`participants`,e.id]}),t.invalidateQueries({queryKey:[`course`,e.slug]})])}function Q({value:e,onChange:t,label:n,className:r,autoFocus:i}){return(0,X.jsxs)(`div`,{className:j(`relative`,r),children:[(0,X.jsx)(b,{className:`pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-muted-foreground`}),(0,X.jsx)(E,{value:e,onChange:e=>t(e.target.value),placeholder:n,"aria-label":n,className:`pl-9`,autoFocus:i})]})}function ge({member:e,onRemove:t,groupName:r}){let i=ee();return(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,X.jsx)(c,{user:e,size:`xs`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:[e.name,e.id===i?.id&&(0,X.jsx)(`span`,{className:`ml-1.5 text-xs text-muted-foreground`,children:`(you)`})]}),e.role!==`student`&&(0,X.jsx)(n,{variant:e.role===`teacher`?`violet`:`info`,children:z[e.role]}),e.status===`suspended`&&(0,X.jsx)(n,{variant:`danger`,children:`Suspended`}),t&&(0,X.jsx)(P,{variant:`ghost`,size:`icon-xs`,className:`text-muted-foreground hover:text-destructive`,"aria-label":`Remove ${e.name} from ${r}`,onClick:t,children:(0,X.jsx)(_,{})})]})}function $({group:e,onAdd:t,onEdit:n,onDelete:r,onRemove:i}){let a=!!t;return(0,X.jsxs)(T,{className:`flex h-full flex-col overflow-hidden`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3 px-4 pt-4 pb-3`,children:[(0,X.jsx)(oe,{group:e}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h3`,{className:`truncate text-[15px] font-semibold tracking-tight`,children:e.name}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:k(e.members.length,`member`)})]}),a&&(0,X.jsxs)(D,{children:[(0,X.jsx)(s,{asChild:!0,children:(0,X.jsx)(P,{variant:`ghost`,size:`icon-sm`,"aria-label":`Options for ${e.name}`,children:(0,X.jsx)(B,{})})}),(0,X.jsxs)(d,{children:[(0,X.jsxs)(o,{onSelect:t,children:[(0,X.jsx)(S,{}),` Add people`]}),(0,X.jsxs)(o,{onSelect:n,children:[(0,X.jsx)(ne,{}),` Rename or describe`]}),(0,X.jsx)(f,{}),(0,X.jsxs)(o,{destructive:!0,onSelect:r,children:[(0,X.jsx)(m,{}),` Delete group`]})]})]})]}),e.description&&(0,X.jsx)(`p`,{className:`-mt-1 px-4 pb-3 text-sm text-muted-foreground`,children:e.description}),(0,X.jsxs)(`ul`,{className:`ck-scrollbar max-h-80 flex-1 divide-y overflow-y-auto border-t`,"aria-label":`Members of ${e.name}`,children:[e.members.length===0&&(0,X.jsx)(`li`,{className:`px-4 py-6 text-center text-sm text-muted-foreground`,children:`No one in this group yet.`}),e.members.map(t=>(0,X.jsx)(ge,{member:t,groupName:e.name,onRemove:i?()=>i(t):void 0},t.id))]}),a&&(0,X.jsx)(`div`,{className:`border-t p-2`,children:(0,X.jsxs)(P,{variant:`ghost`,size:`sm`,className:`w-full`,onClick:t,children:[(0,X.jsx)(S,{}),` Add people`]})})]})}function _e({people:e,groups:t,onAdd:n}){return(0,X.jsxs)(T,{className:`flex h-full flex-col overflow-hidden border-dashed bg-muted/20 shadow-none`,children:[(0,X.jsxs)(`div`,{className:`flex items-start gap-3 px-4 pt-4 pb-3`,children:[(0,X.jsx)(`span`,{className:`grid size-9 shrink-0 place-items-center rounded-xl border border-dashed text-muted-foreground`,"aria-hidden":!0,children:(0,X.jsx)(ue,{className:`size-4`})}),(0,X.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`h3`,{className:`text-[15px] font-semibold tracking-tight`,children:`Not in a group`}),(0,X.jsx)(`p`,{className:`text-xs text-muted-foreground`,children:k(e.length,`active student`)})]})]}),(0,X.jsx)(`ul`,{className:`ck-scrollbar max-h-80 flex-1 divide-y overflow-y-auto border-t`,"aria-label":`Students not in a group`,children:e.map(e=>(0,X.jsxs)(`li`,{className:`flex items-center gap-3 px-4 py-2`,children:[(0,X.jsx)(c,{user:e.user,size:`xs`}),(0,X.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:e.user.name}),n&&(0,X.jsxs)(D,{children:[(0,X.jsx)(s,{asChild:!0,children:(0,X.jsxs)(P,{variant:`ghost`,size:`xs`,"aria-label":`Add ${e.user.name} to a group`,children:[(0,X.jsx)(g,{}),` Add to`]})}),(0,X.jsxs)(d,{className:`ck-scrollbar max-h-72 overflow-y-auto`,children:[(0,X.jsx)(u,{children:`Add to group`}),t.map(t=>(0,X.jsxs)(o,{onSelect:()=>n(t,e.user),children:[(0,X.jsx)(H,{}),` `,(0,X.jsx)(`span`,{className:`truncate`,children:t.name})]},t.id))]})]})]},e.user.id))})]})}function ve({course:e,group:n,open:o,onOpenChange:s,onSaved:c}){let[u,d]=(0,Y.useState)(n?.name??``),[f,p]=(0,Y.useState)(n?.description??``),m=a({mutationFn:()=>n?I.patch(`/courses/${e.id}/groups/${n.id}`,{name:u,description:f}).then(()=>null):I.post(`/courses/${e.id}/groups`,{name:u,description:f}),onSuccess:async e=>{U.success(n?`Group saved`:`Created ${u.trim()}`),s(!1),await c(e)},onError:e=>U.error(F(e))});return(0,X.jsx)(i,{open:o,onOpenChange:s,children:(0,X.jsx)(l,{children:(0,X.jsxs)(`form`,{onSubmit:e=>{e.preventDefault(),m.mutate()},children:[(0,X.jsx)(t,{icon:(0,X.jsx)(H,{className:`size-5`}),title:n?`Edit group`:`New group`,description:n?void 0:`You can add people as soon as it is created.`}),(0,X.jsxs)(r,{className:`space-y-4`,children:[(0,X.jsx)(y,{label:`Name`,children:e=>(0,X.jsx)(E,{...e,autoFocus:!0,required:!0,maxLength:100,value:u,onChange:e=>d(e.target.value),placeholder:`Team Aurora`})}),(0,X.jsx)(y,{label:`Description`,optional:!0,hint:`Shown to the people in the group.`,children:e=>(0,X.jsx)(x,{...e,rows:3,maxLength:1e3,value:f,onChange:e=>p(e.target.value)})})]}),(0,X.jsxs)(v,{children:[(0,X.jsx)(P,{type:`button`,variant:`outline`,onClick:()=>s(!1),children:`Cancel`}),(0,X.jsx)(P,{type:`submit`,loading:m.isPending,disabled:!u.trim(),children:n?`Save`:`Create group`})]})]})})})}function ye({group:e,participants:a,open:o,onOpenChange:s,onAdd:u,pending:d}){let[f,p]=(0,Y.useState)(``),[m,h]=(0,Y.useState)(`student`),[g,_]=(0,Y.useState)(()=>new Set),y=new Set(e.members.map(e=>e.id)),b=a.filter(e=>!y.has(e.user.id)&&(m===`all`||e.role===`student`)),x=f.trim().toLowerCase(),C=x?b.filter(e=>e.user.name.toLowerCase().includes(x)||e.user.email?.toLowerCase().includes(x)):b,T=C.length>0&&C.every(e=>g.has(e.user.id)),E=(e,t)=>_(n=>{let r=new Set(n);for(let n of e)t?r.add(n):r.delete(n);return r}),D=[...g].filter(e=>!y.has(e));return(0,X.jsx)(i,{open:o,onOpenChange:s,children:(0,X.jsx)(l,{size:`lg`,children:(0,X.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:async e=>{e.preventDefault();try{await u(D),s(!1)}catch{}},children:[(0,X.jsx)(t,{icon:(0,X.jsx)(S,{className:`size-5`}),title:`Add people to ${e.name}`,description:`Only people enrolled in this course can join its groups. Someone can be in several groups.`}),(0,X.jsxs)(r,{className:`space-y-3`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 sm:flex-row sm:items-center`,children:[(0,X.jsx)(Q,{value:f,onChange:p,label:`Search by name or email`,className:`flex-1`,autoFocus:!0}),(0,X.jsx)(re,{value:m,onChange:h,options:[{value:`student`,label:`Students`},{value:`all`,label:`Everyone`}]})]}),C.length===0?(0,X.jsx)(`p`,{className:`py-8 text-center text-sm text-muted-foreground`,children:b.length===0?`Everyone here is already in this group.`:`No one matches your search.`}):(0,X.jsxs)(`div`,{className:`overflow-hidden rounded-lg border`,children:[(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 border-b bg-muted/40 px-3 py-2 text-xs font-medium text-muted-foreground`,children:[(0,X.jsx)(w,{checked:T,onCheckedChange:e=>E(C.map(e=>e.user.id),e===!0)}),`Select all `,C.length]}),(0,X.jsx)(`ul`,{className:`ck-scrollbar max-h-[45vh] divide-y overflow-y-auto`,children:C.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsxs)(`label`,{className:`flex cursor-pointer items-center gap-3 px-3 py-2 transition-colors hover:bg-accent/40`,children:[(0,X.jsx)(w,{checked:g.has(e.user.id),onCheckedChange:t=>E([e.user.id],t===!0)}),(0,X.jsx)(c,{user:e.user,size:`xs`}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate text-sm font-medium`,children:e.user.name}),e.user.email&&(0,X.jsx)(`span`,{className:`block truncate text-xs text-muted-foreground`,children:e.user.email})]}),(0,X.jsx)(se,{groups:e.groups,className:`hidden justify-end md:flex`}),e.role!==`student`&&(0,X.jsx)(n,{variant:e.role===`teacher`?`violet`:`info`,children:z[e.role]}),e.status===`suspended`&&(0,X.jsx)(n,{variant:`danger`,children:`Suspended`})]})},e.user.id))})]})]}),(0,X.jsxs)(v,{children:[(0,X.jsx)(P,{type:`button`,variant:`outline`,onClick:()=>s(!1),children:`Cancel`}),(0,X.jsx)(P,{type:`submit`,loading:d,disabled:D.length===0,children:D.length?`Add ${Z(D.length)}`:`Add people`})]})]})})})}function be({course:e,data:n,participants:o,open:s,onOpenChange:c,onDone:u}){let[d,f]=(0,Y.useState)(`groups`),[p,m]=(0,Y.useState)(`3`),[g,_]=(0,Y.useState)(de),[b,x]=(0,Y.useState)(!1),S=o.filter(e=>e.role===`student`&&e.status===`active`),w=b?S.filter(e=>!e.groups?.length).length:S.length,T=Number(p),D=p.trim()!==``&&Number.isInteger(T)&&T>=1,O=D&&w?me(d,T,w):0,A=w?D?d===`groups`&&T>w?`There ${w===1?`is only 1 student`:`are only ${w} students`} to place, so make at most ${w}.`:O>200?`That would make ${O} groups. The most at once is 200.`:g.trim()?null:`Enter a naming scheme.`:`Enter a whole number of 1 or more.`:b?`Every active student is already in a group.`:`There are no active students to place yet.`,M=A?[]:pe(g.trim(),Math.min(O,4),n.groups.map(e=>e.name)),N=O?Math.floor(w/O):0,L=O?Math.ceil(w/O):0,R=a({mutationFn:()=>I.post(`/courses/${e.id}/groups/auto`,{split:d,size:T,naming:g.trim(),onlyUngrouped:b}),onSuccess:async e=>{U.success(`Created ${k(e.groups.length,`group`)}`),c(!1),await u()},onError:e=>U.error(F(e))});return(0,X.jsx)(i,{open:s,onOpenChange:c,children:(0,X.jsx)(l,{size:`lg`,children:(0,X.jsxs)(`form`,{className:`flex min-h-0 flex-1 flex-col`,onSubmit:e=>{e.preventDefault(),A||R.mutate()},children:[(0,X.jsx)(t,{icon:(0,X.jsx)(V,{className:`size-5`}),title:`Auto-create groups`,description:`Shuffle the active students into new groups at random, with sizes as even as possible.`}),(0,X.jsxs)(r,{className:`space-y-5`,children:[(0,X.jsx)(h,{columns:2,value:d,onChange:f,options:[{value:`groups`,label:`Number of groups`,description:`Split the class into this many groups.`,icon:(0,X.jsx)(le,{className:`size-4`})},{value:`members`,label:`Members per group`,description:`Make groups of at most this many people.`,icon:(0,X.jsx)(H,{className:`size-4`})}]}),(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2`,children:[(0,X.jsx)(y,{label:d===`groups`?`Number of groups`:`Members per group`,children:e=>(0,X.jsx)(E,{...e,type:`number`,inputMode:`numeric`,min:1,max:d===`groups`?200:1e3,step:1,required:!0,value:p,onChange:e=>m(e.target.value)})}),(0,X.jsx)(y,{label:`Naming scheme`,hint:`# becomes a number and @ a letter.`,children:e=>(0,X.jsx)(E,{...e,required:!0,maxLength:80,value:g,onChange:e=>_(e.target.value)})})]}),(0,X.jsx)(C,{label:`Only students without a group`,description:`Leave people who are already in a group where they are.`,checked:b,onCheckedChange:x}),(0,X.jsx)(`div`,{role:`status`,"aria-live":`polite`,className:j(`rounded-lg border px-4 py-3 text-sm`,A?`border-amber-500/30 bg-amber-500/10 text-amber-800 dark:text-amber-300`:`bg-muted/40`),children:A??(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`p`,{className:`font-medium`,children:[k(O,`group`),` of `,N===L?N:`${N} to ${L}`,` from `,k(w,`student`)]}),(0,X.jsxs)(`p`,{className:`mt-0.5 truncate text-muted-foreground`,children:[M.join(`, `),O>M.length?`, …`:``]})]})})]}),(0,X.jsxs)(v,{children:[(0,X.jsx)(P,{type:`button`,variant:`outline`,onClick:()=>c(!1),children:`Cancel`}),(0,X.jsxs)(P,{type:`submit`,loading:R.isPending,disabled:!!A,children:[(0,X.jsx)(V,{}),` `,O&&!A?`Create ${k(O,`group`)}`:`Create groups`]})]})]})})})}function xe({course:t,data:n}){let r=n.canManage,i=he(t),o=e(),[s,c]=(0,Y.useState)(``),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(!1),{data:h}=A({queryKey:[`participants`,t.id],queryFn:()=>I.get(`/courses/${t.id}/participants`)}),_=a({mutationFn:({group:e,userIds:n})=>I.post(`/courses/${t.id}/groups/${e.id}/members`,{userIds:n}),onSuccess:async(e,{group:t})=>{await i(),e.added.length&&U.success(`Added ${Z(e.added.length)} to ${t.name}`),e.alreadyMembers.length&&U.info(`${Z(e.alreadyMembers.length)} already in ${t.name}`),e.notEnrolled.length&&U.warning(`${Z(e.notEnrolled.length)} not enrolled in the course`)},onError:e=>U.error(F(e))}),v=a({mutationFn:({group:e,member:n})=>I.delete(`/courses/${t.id}/groups/${e.id}/members/${n.id}`),onSuccess:async(e,{group:t,member:n})=>{await i(),U.success(`Removed ${n.name} from ${t.name}`)},onError:e=>U.error(F(e))}),y=a({mutationFn:e=>I.delete(`/courses/${t.id}/groups/${e.id}`),onSuccess:async(e,t)=>{await i(),U.success(`Deleted ${t.name}`)},onError:e=>U.error(F(e))}),x=(h??[]).filter(e=>e.role===`student`&&e.status===`active`&&!e.groups?.length),S=s.trim().toLowerCase(),C=S?n.groups.filter(e=>e.name.toLowerCase().includes(S)||e.members.some(e=>e.name.toLowerCase().includes(S))):n.groups,w=S?x.filter(e=>e.user.name.toLowerCase().includes(S)):x,T=n.groups.find(e=>e.id===d)??null;return(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mb-5 flex flex-col gap-3 sm:flex-row sm:flex-wrap sm:items-center`,children:[n.groups.length>0&&(0,X.jsx)(Q,{value:s,onChange:c,label:`Search groups or people`,className:`sm:w-72`}),(0,X.jsxs)(`p`,{className:`text-sm text-muted-foreground`,children:[k(n.groups.length,`group`),h&&n.groups.length>0&&(x.length?` · ${k(x.length,`student`)} without a group`:` · every student is in a group`)]}),r&&(0,X.jsxs)(`div`,{className:`flex gap-2 sm:ml-auto`,children:[(0,X.jsxs)(P,{variant:`outline`,className:`flex-1 sm:flex-none`,disabled:!h,onClick:()=>m(!0),children:[(0,X.jsx)(V,{}),` Auto-create`]}),(0,X.jsxs)(P,{className:`flex-1 sm:flex-none`,onClick:()=>u(`new`),children:[(0,X.jsx)(g,{}),` New group`]})]})]}),n.groups.length===0?(0,X.jsx)(K,{icon:H,title:`No groups yet`,description:r?`Groups organise students into teams, sections or study groups. Make them one at a time, or split the class automatically.`:`No one has made any groups in this course yet.`,action:r&&(0,X.jsxs)(`div`,{className:`flex flex-wrap justify-center gap-2`,children:[(0,X.jsxs)(P,{variant:`outline`,disabled:!h,onClick:()=>m(!0),children:[(0,X.jsx)(V,{}),` Auto-create groups`]}),(0,X.jsxs)(P,{onClick:()=>u(`new`),children:[(0,X.jsx)(g,{}),` New group`]})]})}):C.length===0&&w.length===0?(0,X.jsx)(K,{icon:b,title:`Nothing matches your search`,description:`Try a group name or the name of someone in it.`}):(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[C.map(e=>(0,X.jsx)($,{group:e,onAdd:r?()=>f(e.id):void 0,onEdit:()=>u(e),onDelete:async()=>{await o({title:`Delete “${e.name}”?`,description:`The people in it stay in the course. Only the group is removed.`,confirmLabel:`Delete group`,destructive:!0})&&y.mutate(e)},onRemove:r?t=>v.mutate({group:e,member:t}):void 0},e.id)),w.length>0&&(0,X.jsx)(_e,{people:w,groups:n.groups,onAdd:r?(e,t)=>_.mutate({group:e,userIds:[t.id]}):void 0})]}),l&&(0,X.jsx)(ve,{course:t,group:l===`new`?void 0:l,open:!!l,onOpenChange:e=>!e&&u(null),onSaved:async e=>{await i(),e&&f(e.id)}}),T&&(0,X.jsx)(ye,{group:T,participants:h??[],open:!!T,onOpenChange:e=>!e&&f(null),pending:_.isPending,onAdd:e=>_.mutateAsync({group:T,userIds:e})},T.id),p&&(0,X.jsx)(be,{course:t,data:n,participants:h??[],open:p,onOpenChange:m,onDone:i})]})}function Se({data:e}){return e.groups.length===0?(0,X.jsx)(K,{icon:H,title:`You're not in a group yet`,description:`When your teacher puts you in a group, it shows up here with the people in it.`}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(`div`,{className:`mb-5`,children:[(0,X.jsx)(`h2`,{className:`text-lg font-semibold tracking-tight`,children:`Your groups`}),(0,X.jsx)(`p`,{className:`mt-0.5 text-sm text-muted-foreground`,children:`The groups you belong to in this course, and who else is in them.`})]}),(0,X.jsx)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:e.groups.map(e=>(0,X.jsx)($,{group:e},e.id))})]})}function Ce(){let{course:e}=ce();R(`Groups · ${e.title}`);let{data:t,isLoading:n,error:r,refetch:i}=ie(e.id);return(0,X.jsx)(p,{children:r?(0,X.jsx)(G,{error:r,onRetry:()=>i()}):n||!t?(0,X.jsxs)(`div`,{className:`grid gap-4 sm:grid-cols-2 xl:grid-cols-3`,children:[(0,X.jsx)(W,{className:`h-64`}),(0,X.jsx)(W,{className:`h-64`}),(0,X.jsx)(W,{className:`h-64`})]}):t.allGroups?(0,X.jsx)(xe,{course:e,data:t}):(0,X.jsx)(Se,{data:t})})}export{Ce as default};
@@ -1 +1 @@
1
- import{U as e,dt as t,ft as n,g as r,m as i,mt as a,r as o}from"./hooks-BBARn-DA.js";import{At as s,Et as c,a as l,b as u,g as d,vt as f,y as p}from"./index-B29bTBiJ.js";import{n as m,s as h,t as g}from"./misc-DvgDEI3I.js";var _=a(n(),1),v=t();function y(){o(`My courses`);let[t,n]=(0,_.useState)(`all`),{data:a,isLoading:y,error:b,refetch:x}=e({queryKey:[`courses`,`mine`],queryFn:()=>i.get(`/courses/mine`)}),S=a??[],C={all:S.length,progress:S.filter(e=>e.myRole===`student`&&(e.progress??0)<100).length,completed:S.filter(e=>e.myRole===`student`&&e.progress===100).length,teaching:S.filter(e=>e.myRole===`teacher`||e.myRole===`assistant`).length},w=S.filter(e=>t===`progress`?e.myRole===`student`&&(e.progress??0)<100:t===`completed`?e.myRole===`student`&&e.progress===100:t!==`teaching`||e.myRole===`teacher`||e.myRole===`assistant`);return(0,v.jsxs)(d,{children:[(0,v.jsx)(l,{title:`My courses`,description:`Everything you're learning and teaching, most recently visited first.`}),(0,v.jsx)(h,{value:t,onChange:n,className:`mb-6`,options:[{value:`all`,label:`All`,count:C.all},{value:`progress`,label:`In progress`,count:C.progress},{value:`completed`,label:`Completed`,count:C.completed},...C.teaching?[{value:`teaching`,label:`Teaching`,count:C.teaching}]:[]]}),b?(0,v.jsx)(m,{error:b,onRetry:()=>x()}):y?(0,v.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3`,children:[0,1,2].map(e=>(0,v.jsx)(u,{},e))}):w.length===0?(0,v.jsx)(g,{icon:t===`completed`?c:f,title:t===`completed`?`No completed courses yet`:`No courses here`,description:t===`completed`?`Finish every activity in a course to see it here.`:`Find a course in the catalog to get started.`,action:(0,v.jsx)(r,{asChild:!0,variant:`outline`,children:(0,v.jsx)(s,{to:`/catalog`,children:`Explore courses`})})}):(0,v.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3`,children:w.map(e=>(0,v.jsx)(p,{course:e},e.id))})]})}export{y as default};
1
+ import{U as e,dt as t,ft as n,g as r,m as i,mt as a,r as o}from"./hooks-EFhyJ5yU.js";import{It as s,Mt as c,_ as l,a as u,b as d,wt as f,x as p}from"./index-CEZdqKdi.js";import{n as m,s as h,t as g}from"./misc-CyGhN6HT.js";var _=a(n(),1),v=t();function y(){o(`My courses`);let[t,n]=(0,_.useState)(`all`),{data:a,isLoading:y,error:b,refetch:x}=e({queryKey:[`courses`,`mine`],queryFn:()=>i.get(`/courses/mine`)}),S=a??[],C={all:S.length,progress:S.filter(e=>e.myRole===`student`&&(e.progress??0)<100).length,completed:S.filter(e=>e.myRole===`student`&&e.progress===100).length,teaching:S.filter(e=>e.myRole===`teacher`||e.myRole===`assistant`).length},w=S.filter(e=>t===`progress`?e.myRole===`student`&&(e.progress??0)<100:t===`completed`?e.myRole===`student`&&e.progress===100:t!==`teaching`||e.myRole===`teacher`||e.myRole===`assistant`);return(0,v.jsxs)(l,{children:[(0,v.jsx)(u,{title:`My courses`,description:`Everything you're learning and teaching, most recently visited first.`}),(0,v.jsx)(h,{value:t,onChange:n,className:`mb-6`,options:[{value:`all`,label:`All`,count:C.all},{value:`progress`,label:`In progress`,count:C.progress},{value:`completed`,label:`Completed`,count:C.completed},...C.teaching?[{value:`teaching`,label:`Teaching`,count:C.teaching}]:[]]}),b?(0,v.jsx)(m,{error:b,onRetry:()=>x()}):y?(0,v.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3`,children:[0,1,2].map(e=>(0,v.jsx)(p,{},e))}):w.length===0?(0,v.jsx)(g,{icon:t===`completed`?c:f,title:t===`completed`?`No completed courses yet`:`No courses here`,description:t===`completed`?`Finish every activity in a course to see it here.`:`Find a course in the catalog to get started.`,action:(0,v.jsx)(r,{asChild:!0,variant:`outline`,children:(0,v.jsx)(s,{to:`/catalog`,children:`Explore courses`})})}):(0,v.jsx)(`div`,{className:`grid gap-5 sm:grid-cols-2 lg:grid-cols-3`,children:w.map(e=>(0,v.jsx)(d,{course:e},e.id))})]})}export{y as default};