✨ support course kind labels
Browse files at this commit708f89b160133dc3416834cf5f62d84b9cd6ff34Parent: f3306dd- feat
- ✨ support course kind labels
6 changed files +51 -4
- src/api/patchCourseById.ts +2 -1
- src/api/postCourse.ts +2 -1
- src/api/types.ts +2 -0
- src/i18n/messages.ts +9 -0
- src/pages/course-detail-page.tsx +19 -0
- src/pages/courses-page.tsx +17 -2
src/api/patchCourseById.tsmodified+2 -1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import { client } from "./client"; |
| 2 | -import type { Course } from "./types"; | |
| 2 | +import type { Course, CourseKind } from "./types"; | |
| 3 | 3 | |
| 4 | 4 | export type PatchCourseBody = { |
| 5 | 5 | title?: string | null; |
| 6 | 6 | description?: string | null; |
| 7 | + kind?: CourseKind | null; | |
| 7 | 8 | term_id?: string | null; |
| 8 | 9 | }; |
| 9 | 10 |
src/api/postCourse.tsmodified+2 -1
| @@ -1,9 +1,10 @@ | ||
| 1 | 1 | import { client } from "./client"; |
| 2 | -import type { Course } from "./types"; | |
| 2 | +import type { Course, CourseKind } from "./types"; | |
| 3 | 3 | |
| 4 | 4 | export type PostCourseBody = { |
| 5 | 5 | title: string; |
| 6 | 6 | description?: string | null; |
| 7 | + kind?: CourseKind | null; | |
| 7 | 8 | term_id?: string | null; |
| 8 | 9 | }; |
| 9 | 10 |
src/api/types.tsmodified+2 -0
| @@ -3,6 +3,7 @@ export type { Page, PageParams } from "./page"; | ||
| 3 | 3 | export type Role = "student" | "teacher" | "manager" | "admin"; |
| 4 | 4 | export type UserTheme = "light" | "dark"; |
| 5 | 5 | export type UserLanguage = "tr" | "en"; |
| 6 | +export type CourseKind = "course" | "study" | string; | |
| 6 | 7 | export type CoreAttendanceStatus = "present" | "absent" | "late" | "excused"; |
| 7 | 8 | export type AttendanceStatus = CoreAttendanceStatus | string; |
| 8 | 9 | export type KnownExamKind = "homework" | "quiz" | "midterm" | "final" | "project" | "oral"; |
| @@ -73,6 +74,7 @@ export type Course = { | ||
| 73 | 74 | creator: string; |
| 74 | 75 | title: string; |
| 75 | 76 | description: string; |
| 77 | + kind: CourseKind; | |
| 76 | 78 | /** Academic term id from API (`CourseResponse.term`). */ |
| 77 | 79 | term?: string | null; |
| 78 | 80 | }; |
src/i18n/messages.tsmodified+9 -0
| @@ -386,6 +386,9 @@ export type MessageKey = | ||
| 386 | 386 | | "courses.addExam" |
| 387 | 387 | | "courses.weight" |
| 388 | 388 | | "courses.delete" |
| 389 | + | "courses.kind" | |
| 390 | + | "courses.kind.course" | |
| 391 | + | "courses.kind.study" | |
| 389 | 392 | | "marks.title" |
| 390 | 393 | | "marks.subtitle" |
| 391 | 394 | | "marks.overall" |
| @@ -926,6 +929,9 @@ const en: Dict = { | ||
| 926 | 929 | "courses.addExam": "Add exam", |
| 927 | 930 | "courses.weight": "Weight", |
| 928 | 931 | "courses.delete": "Delete course", |
| 932 | + "courses.kind": "Course type", | |
| 933 | + "courses.kind.course": "Course", | |
| 934 | + "courses.kind.study": "Study", | |
| 929 | 935 | "marks.title": "Report card", |
| 930 | 936 | "marks.subtitle": "Weighted averages across enrolled courses.", |
| 931 | 937 | "marks.overall": "Overall average", |
| @@ -1465,6 +1471,9 @@ const tr: Dict = { | ||
| 1465 | 1471 | "courses.addExam": "Sınav ekle", |
| 1466 | 1472 | "courses.weight": "Ağırlık", |
| 1467 | 1473 | "courses.delete": "Dersi sil", |
| 1474 | + "courses.kind": "Ders türü", | |
| 1475 | + "courses.kind.course": "Ders", | |
| 1476 | + "courses.kind.study": "Etüt", | |
| 1468 | 1477 | "marks.title": "Karnem", |
| 1469 | 1478 | "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.", |
| 1470 | 1479 | "marks.overall": "Genel ortalama", |
src/pages/course-detail-page.tsxmodified+19 -0
| @@ -12,6 +12,7 @@ import { patchCourseById } from "@/api/patchCourseById"; | ||
| 12 | 12 | import { postCourseEnrollment } from "@/api/postCourseEnrollment"; |
| 13 | 13 | import { postCourseExam } from "@/api/postCourseExam"; |
| 14 | 14 | import { formatApiError } from "@/api/client"; |
| 15 | +import type { CourseKind } from "@/api/types"; | |
| 15 | 16 | import { ExamLink } from "@/components/exams/exam-link"; |
| 16 | 17 | import { ExamForm } from "@/components/exams/exam-form"; |
| 17 | 18 | import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel"; |
| @@ -46,6 +47,8 @@ import { examKindLabel } from "@/lib/exam-labels"; | ||
| 46 | 47 | import { examWeight } from "@/lib/exam-weight"; |
| 47 | 48 | import { hasMinRole } from "@/lib/roles"; |
| 48 | 49 | |
| 50 | +const COURSE_KINDS: CourseKind[] = ["course", "study"]; | |
| 51 | + | |
| 49 | 52 | export default function CourseDetailPage() { |
| 50 | 53 | return ( |
| 51 | 54 | <RouteGuard> |
| @@ -88,6 +91,7 @@ function CourseDetailContent() { | ||
| 88 | 91 | const [editing, setEditing] = createSignal(false); |
| 89 | 92 | const [title, setTitle] = createSignal(""); |
| 90 | 93 | const [description, setDescription] = createSignal(""); |
| 94 | + const [kind, setKind] = createSignal<CourseKind>("course"); | |
| 91 | 95 | const [termId, setTermId] = createSignal(""); |
| 92 | 96 | const [showExamForm, setShowExamForm] = createSignal(false); |
| 93 | 97 | const [showSessionForm, setShowSessionForm] = createSignal(false); |
| @@ -117,6 +121,8 @@ function CourseDetailContent() { | ||
| 117 | 121 | if (mode === "open") return t("exams.mode.open"); |
| 118 | 122 | return t("exams.unscheduled"); |
| 119 | 123 | }; |
| 124 | + const courseKindLabel = (value: CourseKind | undefined) => | |
| 125 | + value === "study" ? t("courses.kind.study") : t("courses.kind.course"); | |
| 120 | 126 | |
| 121 | 127 | const examCount = createMemo(() => exams()?.length ?? 0); |
| 122 | 128 | const rosterCount = createMemo(() => roster()?.length ?? 0); |
| @@ -144,6 +150,7 @@ function CourseDetailContent() { | ||
| 144 | 150 | if (!c) return; |
| 145 | 151 | setTitle(c.title); |
| 146 | 152 | setDescription(c.description); |
| 153 | + setKind(c.kind ?? "course"); | |
| 147 | 154 | setTermId(c.term ?? ""); |
| 148 | 155 | setEditing(true); |
| 149 | 156 | }; |
| @@ -198,6 +205,11 @@ function CourseDetailContent() { | ||
| 198 | 205 | </div> |
| 199 | 206 | } |
| 200 | 207 | /> |
| 208 | + <div class="flex flex-wrap gap-2"> | |
| 209 | + <Badge variant="outline" class="rounded-sm"> | |
| 210 | + {courseKindLabel(c().kind)} | |
| 211 | + </Badge> | |
| 212 | + </div> | |
| 201 | 213 | </div> |
| 202 | 214 | |
| 203 | 215 | <ConfirmDialog |
| @@ -243,6 +255,7 @@ function CourseDetailContent() { | ||
| 243 | 255 | await patchCourseById(id(), { |
| 244 | 256 | title: title().trim(), |
| 245 | 257 | description: description(), |
| 258 | + kind: kind(), | |
| 246 | 259 | term_id: termId() || null, |
| 247 | 260 | }); |
| 248 | 261 | setEditing(false); |
| @@ -268,6 +281,12 @@ function CourseDetailContent() { | ||
| 268 | 281 | onInput={(e) => setDescription(e.currentTarget.value)} |
| 269 | 282 | /> |
| 270 | 283 | </div> |
| 284 | + <div class="space-y-1.5"> | |
| 285 | + <Label for="edit-course-kind">{t("courses.kind")}</Label> | |
| 286 | + <Select id="edit-course-kind" value={kind()} onChange={(e) => setKind(e.currentTarget.value as CourseKind)}> | |
| 287 | + <For each={COURSE_KINDS}>{(item) => <option value={item}>{courseKindLabel(item)}</option>}</For> | |
| 288 | + </Select> | |
| 289 | + </div> | |
| 271 | 290 | <div class="space-y-1.5"> |
| 272 | 291 | <Label for="edit-course-term">{t("terms.term")}</Label> |
| 273 | 292 | <Select id="edit-course-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}> |
src/pages/courses-page.tsxmodified+17 -2
| @@ -6,7 +6,7 @@ import { getTerms } from "@/api/getTerms"; | ||
| 6 | 6 | import { getUsers } from "@/api/getUsers"; |
| 7 | 7 | import { postCourse } from "@/api/postCourse"; |
| 8 | 8 | import { formatApiError } from "@/api/client"; |
| 9 | -import type { Course } from "@/api/types"; | |
| 9 | +import type { Course, CourseKind } from "@/api/types"; | |
| 10 | 10 | import { Alert } from "@/components/ui/alert"; |
| 11 | 11 | import { RouteGuard } from "@/components/layout/route-guard"; |
| 12 | 12 | import { PageHeader } from "@/components/layout/page-header"; |
| @@ -29,6 +29,7 @@ import { useT } from "@/stores/preferences-context"; | ||
| 29 | 29 | import { hasMinRole } from "@/lib/roles"; |
| 30 | 30 | |
| 31 | 31 | const COURSE_PAGE_SIZE = 12; |
| 32 | +const COURSE_KINDS: CourseKind[] = ["course", "study"]; | |
| 32 | 33 | |
| 33 | 34 | export default function CoursesPage() { |
| 34 | 35 | return ( |
| @@ -45,6 +46,7 @@ function CoursesContent() { | ||
| 45 | 46 | const [showForm, setShowForm] = createSignal(false); |
| 46 | 47 | const [title, setTitle] = createSignal(""); |
| 47 | 48 | const [description, setDescription] = createSignal(""); |
| 49 | + const [kind, setKind] = createSignal<CourseKind>("course"); | |
| 48 | 50 | const [termId, setTermId] = createSignal(""); |
| 49 | 51 | const [error, setError] = createSignal(""); |
| 50 | 52 | const [pending, setPending] = createSignal(false); |
| @@ -63,6 +65,8 @@ function CoursesContent() { | ||
| 63 | 65 | ); |
| 64 | 66 | |
| 65 | 67 | const termName = (id: string | null | undefined) => terms()?.find((term) => term.id === id)?.name ?? t("terms.unassigned"); |
| 68 | + const courseKindLabel = (value: CourseKind | undefined) => | |
| 69 | + value === "study" ? t("courses.kind.study") : t("courses.kind.course"); | |
| 66 | 70 | const creatorName = (creatorId: string) => { |
| 67 | 71 | if (creatorId === auth.user()?.id) return auth.user()?.username ?? creatorId; |
| 68 | 72 | return users()?.find((user) => user.id === creatorId)?.username ?? creatorId; |
| @@ -75,7 +79,7 @@ function CoursesContent() { | ||
| 75 | 79 | if (selectedTerm === "unassigned" && course.term) return false; |
| 76 | 80 | if (selectedTerm !== "all" && selectedTerm !== "unassigned" && course.term !== selectedTerm) return false; |
| 77 | 81 | if (!needle) return true; |
| 78 | - return [course.title, course.description, course.creator, creatorName(course.creator), termName(course.term)] | |
| 82 | + return [course.title, course.description, course.creator, creatorName(course.creator), termName(course.term), courseKindLabel(course.kind)] | |
| 79 | 83 | .join(" ") |
| 80 | 84 | .toLocaleLowerCase() |
| 81 | 85 | .includes(needle); |
| @@ -115,10 +119,12 @@ function CoursesContent() { | ||
| 115 | 119 | await postCourse({ |
| 116 | 120 | title: title().trim(), |
| 117 | 121 | description: description().trim() || undefined, |
| 122 | + kind: kind(), | |
| 118 | 123 | term_id: termId() || null, |
| 119 | 124 | }); |
| 120 | 125 | setTitle(""); |
| 121 | 126 | setDescription(""); |
| 127 | + setKind("course"); | |
| 122 | 128 | setTermId(""); |
| 123 | 129 | setShowForm(false); |
| 124 | 130 | await refetch(); |
| @@ -163,6 +169,12 @@ function CoursesContent() { | ||
| 163 | 169 | <Label for="course-desc">{t("form.description")}</Label> |
| 164 | 170 | <Textarea id="course-desc" maxlength={2000} rows={3} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} /> |
| 165 | 171 | </div> |
| 172 | + <div class="space-y-1.5"> | |
| 173 | + <Label for="course-kind">{t("courses.kind")}</Label> | |
| 174 | + <Select id="course-kind" value={kind()} onChange={(e) => setKind(e.currentTarget.value as CourseKind)}> | |
| 175 | + <For each={COURSE_KINDS}>{(item) => <option value={item}>{courseKindLabel(item)}</option>}</For> | |
| 176 | + </Select> | |
| 177 | + </div> | |
| 166 | 178 | <div class="space-y-1.5"> |
| 167 | 179 | <Label for="course-term">{t("terms.term")}</Label> |
| 168 | 180 | <Select id="course-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}> |
| @@ -251,6 +263,9 @@ function CoursesContent() { | ||
| 251 | 263 | <TableCell> |
| 252 | 264 | <div class="min-w-0 space-y-1"> |
| 253 | 265 | <p class="truncate font-medium">{course.title}</p> |
| 266 | + <Badge variant="outline" class="rounded-sm text-[11px]"> | |
| 267 | + {courseKindLabel(course.kind)} | |
| 268 | + </Badge> | |
| 254 | 269 | <Show when={isStudent()}> |
| 255 | 270 | <Badge variant="secondary" class="rounded-sm">{t("courses.enrolled")}</Badge> |
| 256 | 271 | </Show> |