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