forge
Explore
Log in

Don't you dare go Hollow

✨ support course kind labels

Browse files at this commit

708f89b160133dc3416834cf5f62d84b9cd6ff34Burak BoduroğluParent: f3306dd
  • feat
    • ✨ support course kind labels
Show full message
feat: ✨ support course kind labels

- add course kind typing and create/edit API payload support

- let teachers choose course or study when creating and editing courses

- show localized course kind badges in course list and detail views
src/api/patchCourseById.tsmodified+2 -1
@@ -1,9 +1,10 @@
11 import { client } from "./client";
2-import type { Course } from "./types";
2+import type { Course, CourseKind } from "./types";
33
44 export type PatchCourseBody = {
55 title?: string | null;
66 description?: string | null;
7+ kind?: CourseKind | null;
78 term_id?: string | null;
89 };
910
src/api/postCourse.tsmodified+2 -1
@@ -1,9 +1,10 @@
11 import { client } from "./client";
2-import type { Course } from "./types";
2+import type { Course, CourseKind } from "./types";
33
44 export type PostCourseBody = {
55 title: string;
66 description?: string | null;
7+ kind?: CourseKind | null;
78 term_id?: string | null;
89 };
910
src/api/types.tsmodified+2 -0
@@ -3,6 +3,7 @@ export type { Page, PageParams } from "./page";
33 export type Role = "student" | "teacher" | "manager" | "admin";
44 export type UserTheme = "light" | "dark";
55 export type UserLanguage = "tr" | "en";
6+export type CourseKind = "course" | "study" | string;
67 export type CoreAttendanceStatus = "present" | "absent" | "late" | "excused";
78 export type AttendanceStatus = CoreAttendanceStatus | string;
89 export type KnownExamKind = "homework" | "quiz" | "midterm" | "final" | "project" | "oral";
@@ -73,6 +74,7 @@ export type Course = {
7374 creator: string;
7475 title: string;
7576 description: string;
77+ kind: CourseKind;
7678 /** Academic term id from API (`CourseResponse.term`). */
7779 term?: string | null;
7880 };
src/i18n/messages.tsmodified+9 -0
@@ -386,6 +386,9 @@ export type MessageKey =
386386 | "courses.addExam"
387387 | "courses.weight"
388388 | "courses.delete"
389+ | "courses.kind"
390+ | "courses.kind.course"
391+ | "courses.kind.study"
389392 | "marks.title"
390393 | "marks.subtitle"
391394 | "marks.overall"
@@ -926,6 +929,9 @@ const en: Dict = {
926929 "courses.addExam": "Add exam",
927930 "courses.weight": "Weight",
928931 "courses.delete": "Delete course",
932+ "courses.kind": "Course type",
933+ "courses.kind.course": "Course",
934+ "courses.kind.study": "Study",
929935 "marks.title": "Report card",
930936 "marks.subtitle": "Weighted averages across enrolled courses.",
931937 "marks.overall": "Overall average",
@@ -1465,6 +1471,9 @@ const tr: Dict = {
14651471 "courses.addExam": "Sınav ekle",
14661472 "courses.weight": "Ağırlık",
14671473 "courses.delete": "Dersi sil",
1474+ "courses.kind": "Ders türü",
1475+ "courses.kind.course": "Ders",
1476+ "courses.kind.study": "Etüt",
14681477 "marks.title": "Karnem",
14691478 "marks.subtitle": "Kayıtlı derslerdeki ağırlıklı ortalamalar.",
14701479 "marks.overall": "Genel ortalama",
src/pages/course-detail-page.tsxmodified+19 -0
@@ -12,6 +12,7 @@ import { patchCourseById } from "@/api/patchCourseById";
1212 import { postCourseEnrollment } from "@/api/postCourseEnrollment";
1313 import { postCourseExam } from "@/api/postCourseExam";
1414 import { formatApiError } from "@/api/client";
15+import type { CourseKind } from "@/api/types";
1516 import { ExamLink } from "@/components/exams/exam-link";
1617 import { ExamForm } from "@/components/exams/exam-form";
1718 import { CourseSessionsPanel } from "@/components/sessions/course-sessions-panel";
@@ -46,6 +47,8 @@ import { examKindLabel } from "@/lib/exam-labels";
4647 import { examWeight } from "@/lib/exam-weight";
4748 import { hasMinRole } from "@/lib/roles";
4849
50+const COURSE_KINDS: CourseKind[] = ["course", "study"];
51+
4952 export default function CourseDetailPage() {
5053 return (
5154 <RouteGuard>
@@ -88,6 +91,7 @@ function CourseDetailContent() {
8891 const [editing, setEditing] = createSignal(false);
8992 const [title, setTitle] = createSignal("");
9093 const [description, setDescription] = createSignal("");
94+ const [kind, setKind] = createSignal<CourseKind>("course");
9195 const [termId, setTermId] = createSignal("");
9296 const [showExamForm, setShowExamForm] = createSignal(false);
9397 const [showSessionForm, setShowSessionForm] = createSignal(false);
@@ -117,6 +121,8 @@ function CourseDetailContent() {
117121 if (mode === "open") return t("exams.mode.open");
118122 return t("exams.unscheduled");
119123 };
124+ const courseKindLabel = (value: CourseKind | undefined) =>
125+ value === "study" ? t("courses.kind.study") : t("courses.kind.course");
120126
121127 const examCount = createMemo(() => exams()?.length ?? 0);
122128 const rosterCount = createMemo(() => roster()?.length ?? 0);
@@ -144,6 +150,7 @@ function CourseDetailContent() {
144150 if (!c) return;
145151 setTitle(c.title);
146152 setDescription(c.description);
153+ setKind(c.kind ?? "course");
147154 setTermId(c.term ?? "");
148155 setEditing(true);
149156 };
@@ -198,6 +205,11 @@ function CourseDetailContent() {
198205 </div>
199206 }
200207 />
208+ <div class="flex flex-wrap gap-2">
209+ <Badge variant="outline" class="rounded-sm">
210+ {courseKindLabel(c().kind)}
211+ </Badge>
212+ </div>
201213 </div>
202214
203215 <ConfirmDialog
@@ -243,6 +255,7 @@ function CourseDetailContent() {
243255 await patchCourseById(id(), {
244256 title: title().trim(),
245257 description: description(),
258+ kind: kind(),
246259 term_id: termId() || null,
247260 });
248261 setEditing(false);
@@ -268,6 +281,12 @@ function CourseDetailContent() {
268281 onInput={(e) => setDescription(e.currentTarget.value)}
269282 />
270283 </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>
271290 <div class="space-y-1.5">
272291 <Label for="edit-course-term">{t("terms.term")}</Label>
273292 <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";
66 import { getUsers } from "@/api/getUsers";
77 import { postCourse } from "@/api/postCourse";
88 import { formatApiError } from "@/api/client";
9-import type { Course } from "@/api/types";
9+import type { Course, CourseKind } from "@/api/types";
1010 import { Alert } from "@/components/ui/alert";
1111 import { RouteGuard } from "@/components/layout/route-guard";
1212 import { PageHeader } from "@/components/layout/page-header";
@@ -29,6 +29,7 @@ import { useT } from "@/stores/preferences-context";
2929 import { hasMinRole } from "@/lib/roles";
3030
3131 const COURSE_PAGE_SIZE = 12;
32+const COURSE_KINDS: CourseKind[] = ["course", "study"];
3233
3334 export default function CoursesPage() {
3435 return (
@@ -45,6 +46,7 @@ function CoursesContent() {
4546 const [showForm, setShowForm] = createSignal(false);
4647 const [title, setTitle] = createSignal("");
4748 const [description, setDescription] = createSignal("");
49+ const [kind, setKind] = createSignal<CourseKind>("course");
4850 const [termId, setTermId] = createSignal("");
4951 const [error, setError] = createSignal("");
5052 const [pending, setPending] = createSignal(false);
@@ -63,6 +65,8 @@ function CoursesContent() {
6365 );
6466
6567 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");
6670 const creatorName = (creatorId: string) => {
6771 if (creatorId === auth.user()?.id) return auth.user()?.username ?? creatorId;
6872 return users()?.find((user) => user.id === creatorId)?.username ?? creatorId;
@@ -75,7 +79,7 @@ function CoursesContent() {
7579 if (selectedTerm === "unassigned" && course.term) return false;
7680 if (selectedTerm !== "all" && selectedTerm !== "unassigned" && course.term !== selectedTerm) return false;
7781 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)]
7983 .join(" ")
8084 .toLocaleLowerCase()
8185 .includes(needle);
@@ -115,10 +119,12 @@ function CoursesContent() {
115119 await postCourse({
116120 title: title().trim(),
117121 description: description().trim() || undefined,
122+ kind: kind(),
118123 term_id: termId() || null,
119124 });
120125 setTitle("");
121126 setDescription("");
127+ setKind("course");
122128 setTermId("");
123129 setShowForm(false);
124130 await refetch();
@@ -163,6 +169,12 @@ function CoursesContent() {
163169 <Label for="course-desc">{t("form.description")}</Label>
164170 <Textarea id="course-desc" maxlength={2000} rows={3} value={description()} onInput={(e) => setDescription(e.currentTarget.value)} />
165171 </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>
166178 <div class="space-y-1.5">
167179 <Label for="course-term">{t("terms.term")}</Label>
168180 <Select id="course-term" value={termId()} onChange={(e) => setTermId(e.currentTarget.value)}>
@@ -251,6 +263,9 @@ function CoursesContent() {
251263 <TableCell>
252264 <div class="min-w-0 space-y-1">
253265 <p class="truncate font-medium">{course.title}</p>
266+ <Badge variant="outline" class="rounded-sm text-[11px]">
267+ {courseKindLabel(course.kind)}
268+ </Badge>
254269 <Show when={isStudent()}>
255270 <Badge variant="secondary" class="rounded-sm">{t("courses.enrolled")}</Badge>
256271 </Show>