📝 teachers see which homework is waiting on them
Browse files at this commit6716a736affdeb54fa00604621e35752b9503546Parent: a432188- feat
- 📝 teachers see which homework is waiting on them
7 changed files +204 -3
- .claude/skills/dashboard-design/SKILL.md +5 -0
- src/components/dashboard/homework-queue-panel.tsx +80 -0
- src/i18n/messages.ts +15 -0
- src/lib/homework-queue.test.ts +45 -0
- src/lib/homework-queue.ts +35 -0
- src/pages/dashboard-page.test.tsx +15 -0
- src/pages/dashboard-page.tsx +9 -3
.claude/skills/dashboard-design/SKILL.mdmodified+5 -0
| @@ -56,6 +56,11 @@ Reference: `src/pages/dashboard-page.tsx`. The homepage is a **read-only status | |||
| 56 | itself. The teacher panel reads roll-call counts only for lessons that have | 56 | itself. The teacher panel reads roll-call counts only for lessons that have |
| 57 | started; the student panel never reads roll call. Gate it on the `sessions` | 57 | started; the student panel never reads roll call. Gate it on the `sessions` |
| 58 | module. | 58 | module. |
| 59 | +- **Teacher homework queue:** `HomeworkQueuePanel` reads the roster | ||
| 60 | + (`/homework/{id}/submissions`) of at most `QUEUE_CAP` of the teacher's own | ||
| 61 | + homework due in the last 14 days or next 2, and says how many have not handed | ||
| 62 | + in and how many wait for a grade; rows link to the homework. No bulk endpoint, | ||
| 63 | + so the cap stays; a failed read drops its row. | ||
| 59 | - **Parent homework:** `ChildHomeworkPanel` reads the selected child's | 64 | - **Parent homework:** `ChildHomeworkPanel` reads the selected child's |
| 60 | `/homework/report/{user}` (overdue / due this week) with no links — a parent | 65 | `/homework/report/{user}` (overdue / due this week) with no links — a parent |
| 61 | cannot open the course-scoped homework page. | 66 | cannot open the course-scoped homework page. |
src/components/dashboard/homework-queue-panel.tsxadded+80 -0
| @@ -0,0 +1,80 @@ | |||
| 1 | +import { For, Show, createMemo } from "solid-js"; | ||
| 2 | +import { Link } from "@tanstack/solid-router"; | ||
| 3 | +import { createResource } from "@/lib/create-resource"; | ||
| 4 | +import type { Homework } from "@/api/client"; | ||
| 5 | +import { getHomeworkSubmissions } from "@/api/homework"; | ||
| 6 | +import { EmptyInline } from "@/components/ui/empty-inline"; | ||
| 7 | +import { IconChevronRight } from "@/components/ui/icons"; | ||
| 8 | +import { formatDateTime } from "@/lib/format"; | ||
| 9 | +import { queueCandidates, queueRow, type QueueRow } from "@/lib/homework-queue"; | ||
| 10 | +import { usePreferences, useT } from "@/stores/preferences-context"; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * TCH "what is waiting on me": for the teacher's own homework due around | ||
| 14 | + * now, how many students have not handed in and how many hand-ins still need | ||
| 15 | + * a grade — as sentences, each linking to that homework. Counts come from | ||
| 16 | + * each homework's roster (`/homework/{id}/submissions`), read for a capped | ||
| 17 | + * handful since there is no bulk endpoint; a failed read drops its row. | ||
| 18 | + */ | ||
| 19 | +export function HomeworkQueuePanel(props: { homework: Homework[]; teacherId: string; now: number }) { | ||
| 20 | + const t = useT(); | ||
| 21 | + const { locale } = usePreferences(); | ||
| 22 | + const candidates = createMemo(() => queueCandidates(props.homework, props.teacherId, props.now)); | ||
| 23 | + const [rows] = createResource( | ||
| 24 | + () => candidates().map((item) => item.id).join(",") || null, | ||
| 25 | + async () => { | ||
| 26 | + const settled = await Promise.all( | ||
| 27 | + candidates().map(async (item) => { | ||
| 28 | + try { | ||
| 29 | + return queueRow(item, (await getHomeworkSubmissions(item.id)).items); | ||
| 30 | + } catch { | ||
| 31 | + return null; | ||
| 32 | + } | ||
| 33 | + }), | ||
| 34 | + ); | ||
| 35 | + return settled.filter((row): row is QueueRow => row != null && row.missing + row.toGrade > 0); | ||
| 36 | + }, | ||
| 37 | + ); | ||
| 38 | + const toGrade = () => (rows() ?? []).reduce((sum, row) => sum + row.toGrade, 0); | ||
| 39 | + | ||
| 40 | + return ( | ||
| 41 | + <section class="flex flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-4" aria-labelledby="homework-queue-heading"> | ||
| 42 | + <div class="flex flex-wrap items-baseline justify-between gap-2"> | ||
| 43 | + <h2 id="homework-queue-heading" class="text-base font-semibold tracking-tight text-text-strong">{t("homeworkQueue.title")}</h2> | ||
| 44 | + <Show when={toGrade() > 0}> | ||
| 45 | + <span class="text-xs font-medium text-warning-text">{t("homeworkQueue.toGradeTotal", { count: toGrade() })}</span> | ||
| 46 | + </Show> | ||
| 47 | + </div> | ||
| 48 | + <Show | ||
| 49 | + when={(rows() ?? []).length > 0} | ||
| 50 | + fallback={<EmptyInline illustration="calendar-empty" title={t("homeworkQueue.empty")} />} | ||
| 51 | + > | ||
| 52 | + <ul class="divide-y divide-border-hairline"> | ||
| 53 | + <For each={rows()}> | ||
| 54 | + {(row) => ( | ||
| 55 | + <li> | ||
| 56 | + <Link | ||
| 57 | + to="/homework/$id" | ||
| 58 | + params={{ id: row.homework.id }} | ||
| 59 | + class="flex items-center gap-3 py-2.5 outline-hidden hover:bg-muted/40 focus-visible:ring-2 focus-visible:ring-ring" | ||
| 60 | + > | ||
| 61 | + <span class="min-w-0 flex-1"> | ||
| 62 | + <span class="block truncate text-sm font-medium text-text-default">{row.homework.title}</span> | ||
| 63 | + <span class="block text-xs text-muted-foreground"> | ||
| 64 | + {[ | ||
| 65 | + row.missing > 0 ? t("homeworkQueue.missing", { count: row.missing }) : null, | ||
| 66 | + row.toGrade > 0 ? t("homeworkQueue.toGrade", { count: row.toGrade }) : null, | ||
| 67 | + ].filter(Boolean).join(" · ")} | ||
| 68 | + </span> | ||
| 69 | + </span> | ||
| 70 | + <span class="mono shrink-0 text-xs tabular-nums text-muted-foreground">{formatDateTime(row.homework.due_at, locale())}</span> | ||
| 71 | + <IconChevronRight class="h-4 w-4 shrink-0 text-muted-foreground/60" /> | ||
| 72 | + </Link> | ||
| 73 | + </li> | ||
| 74 | + )} | ||
| 75 | + </For> | ||
| 76 | + </ul> | ||
| 77 | + </Show> | ||
| 78 | + </section> | ||
| 79 | + ); | ||
| 80 | +} | ||
src/i18n/messages.tsmodified+15 -0
| @@ -616,6 +616,11 @@ export type MessageKey = | |||
| 616 | | "common.deleted" | 616 | | "common.deleted" |
| 617 | | "common.saved" | 617 | | "common.saved" |
| 618 | | "common.loadAll" | 618 | | "common.loadAll" |
| 619 | + | "homeworkQueue.title" | ||
| 620 | + | "homeworkQueue.toGradeTotal" | ||
| 621 | + | "homeworkQueue.missing" | ||
| 622 | + | "homeworkQueue.toGrade" | ||
| 623 | + | "homeworkQueue.empty" | ||
| 619 | | "aiHub.tab.study" | 624 | | "aiHub.tab.study" |
| 620 | | "today.titleStudent" | 625 | | "today.titleStudent" |
| 621 | | "today.inProgress" | 626 | | "today.inProgress" |
| @@ -2784,6 +2789,11 @@ const en: Dict = { | |||
| 2784 | "common.deleted": "Deleted.", | 2789 | "common.deleted": "Deleted.", |
| 2785 | "common.saved": "Saved successfully.", | 2790 | "common.saved": "Saved successfully.", |
| 2786 | "common.loadAll": "Load all", | 2791 | "common.loadAll": "Load all", |
| 2792 | + "homeworkQueue.title": "Homework waiting on you", | ||
| 2793 | + "homeworkQueue.toGradeTotal": "{count} to grade", | ||
| 2794 | + "homeworkQueue.missing": "{count} not handed in", | ||
| 2795 | + "homeworkQueue.toGrade": "{count} waiting for a grade", | ||
| 2796 | + "homeworkQueue.empty": "Nothing is waiting on your recent homework.", | ||
| 2787 | "aiHub.tab.study": "Study", | 2797 | "aiHub.tab.study": "Study", |
| 2788 | "today.titleStudent": "Today's lessons", | 2798 | "today.titleStudent": "Today's lessons", |
| 2789 | "today.inProgress": "On now", | 2799 | "today.inProgress": "On now", |
| @@ -4954,6 +4964,11 @@ const tr: Dict = { | |||
| 4954 | "common.deleted": "Silindi.", | 4964 | "common.deleted": "Silindi.", |
| 4955 | "common.saved": "Başarıyla kaydedildi.", | 4965 | "common.saved": "Başarıyla kaydedildi.", |
| 4956 | "common.loadAll": "Tümünü yükle", | 4966 | "common.loadAll": "Tümünü yükle", |
| 4967 | + "homeworkQueue.title": "Seni bekleyen ödevler", | ||
| 4968 | + "homeworkQueue.toGradeTotal": "{count} notlanacak", | ||
| 4969 | + "homeworkQueue.missing": "{count} teslim etmedi", | ||
| 4970 | + "homeworkQueue.toGrade": "{count} not bekliyor", | ||
| 4971 | + "homeworkQueue.empty": "Son ödevlerinde bekleyen bir şey yok.", | ||
| 4957 | "aiHub.tab.study": "Çalış", | 4972 | "aiHub.tab.study": "Çalış", |
| 4958 | "today.titleStudent": "Bugünkü derslerin", | 4973 | "today.titleStudent": "Bugünkü derslerin", |
| 4959 | "today.inProgress": "Şimdi", | 4974 | "today.inProgress": "Şimdi", |
src/lib/homework-queue.test.tsadded+45 -0
| @@ -0,0 +1,45 @@ | |||
| 1 | +import type { Homework, HomeworkRosterEntry } from "@/api/client"; | ||
| 2 | +import { queueCandidates, queueRow } from "./homework-queue"; | ||
| 3 | + | ||
| 4 | +const DAY = 24 * 60 * 60 * 1000; | ||
| 5 | +const now = Date.UTC(2026, 8, 19, 9); | ||
| 6 | +const hw = (id: string, due: number, createdBy = "t-1"): Homework => ({ | ||
| 7 | + id, | ||
| 8 | + class_course: "i-1", | ||
| 9 | + subject: "s-1", | ||
| 10 | + title: id, | ||
| 11 | + description: null, | ||
| 12 | + due_at: due, | ||
| 13 | + assigned: null, | ||
| 14 | + created_by: createdBy, | ||
| 15 | + created_at: now - 30 * DAY, | ||
| 16 | +}); | ||
| 17 | +const row = (state: Partial<HomeworkRosterEntry>): HomeworkRosterEntry => ({ | ||
| 18 | + user: "u", | ||
| 19 | + submission: null, | ||
| 20 | + result: null, | ||
| 21 | + missing: false, | ||
| 22 | + unenrolled: false, | ||
| 23 | + ...state, | ||
| 24 | +}); | ||
| 25 | + | ||
| 26 | +it("keeps the teacher's own homework due around now, closest first", () => { | ||
| 27 | + const picked = queueCandidates( | ||
| 28 | + [hw("old", now - 20 * DAY), hw("yesterday", now - DAY), hw("other-teacher", now - DAY, "t-2"), hw("tomorrow", now + DAY), hw("next-week", now + 7 * DAY), hw("last-week", now - 7 * DAY)], | ||
| 29 | + "t-1", | ||
| 30 | + now, | ||
| 31 | + ); | ||
| 32 | + expect(picked.map((item) => item.id)).toEqual(["yesterday", "tomorrow", "last-week"]); | ||
| 33 | +}); | ||
| 34 | + | ||
| 35 | +it("counts missing and ungraded work, leaving unenrolled rows out", () => { | ||
| 36 | + const submission = { text: "done", submitted_at: now, updated_at: now, late: false, files: [] }; | ||
| 37 | + const counts = queueRow(hw("h", now), [ | ||
| 38 | + row({ missing: true }), | ||
| 39 | + row({ missing: true, unenrolled: true }), | ||
| 40 | + row({ submission }), | ||
| 41 | + row({ submission, result: { mark: 80 } as never }), | ||
| 42 | + row({}), | ||
| 43 | + ]); | ||
| 44 | + expect(counts).toMatchObject({ missing: 1, toGrade: 1 }); | ||
| 45 | +}); | ||
src/lib/homework-queue.tsadded+35 -0
| @@ -0,0 +1,35 @@ | |||
| 1 | +import type { Homework, HomeworkRosterEntry } from "@/api/client"; | ||
| 2 | + | ||
| 3 | +const DAY_MS = 24 * 60 * 60 * 1000; | ||
| 4 | +/** How far back a due date still counts as work waiting on the teacher. */ | ||
| 5 | +export const QUEUE_LOOKBACK_MS = 14 * DAY_MS; | ||
| 6 | +/** How far ahead: homework due in the next two days is worth a glance now. */ | ||
| 7 | +export const QUEUE_LOOKAHEAD_MS = 2 * DAY_MS; | ||
| 8 | +/** Roster reads per board load; there is no bulk endpoint. */ | ||
| 9 | +export const QUEUE_CAP = 6; | ||
| 10 | + | ||
| 11 | +export type QueueRow = { | ||
| 12 | + homework: Homework; | ||
| 13 | + /** Students in the audience who have not handed in (`missing`). */ | ||
| 14 | + missing: number; | ||
| 15 | + /** Handed in, not graded yet. */ | ||
| 16 | + toGrade: number; | ||
| 17 | +}; | ||
| 18 | + | ||
| 19 | +/** The teacher's own homework due around now, most recently due first. */ | ||
| 20 | +export function queueCandidates(items: Homework[], teacherId: string, now: number): Homework[] { | ||
| 21 | + return items | ||
| 22 | + .filter((item) => item.created_by === teacherId && item.due_at >= now - QUEUE_LOOKBACK_MS && item.due_at <= now + QUEUE_LOOKAHEAD_MS) | ||
| 23 | + .sort((a, b) => Math.abs(now - a.due_at) - Math.abs(now - b.due_at)) | ||
| 24 | + .slice(0, QUEUE_CAP); | ||
| 25 | +} | ||
| 26 | + | ||
| 27 | +/** Counts from one homework's roster; rows left behind by an unenrollment are not owed. */ | ||
| 28 | +export function queueRow(homework: Homework, roster: HomeworkRosterEntry[]): QueueRow { | ||
| 29 | + const current = roster.filter((row) => !row.unenrolled); | ||
| 30 | + return { | ||
| 31 | + homework, | ||
| 32 | + missing: current.filter((row) => row.missing).length, | ||
| 33 | + toGrade: current.filter((row) => row.submission != null && row.result == null).length, | ||
| 34 | + }; | ||
| 35 | +} | ||
src/pages/dashboard-page.test.tsxmodified+15 -0
| @@ -165,6 +165,11 @@ vi.mock("@/api/events", () => ({ | |||
| 165 | ]), | 165 | ]), |
| 166 | })); | 166 | })); |
| 167 | vi.mock("@/api/homework", () => ({ | 167 | vi.mock("@/api/homework", () => ({ |
| 168 | + getHomeworkSubmissions: async () => page([ | ||
| 169 | + { user: "s-1", submission: null, result: null, missing: true, unenrolled: false }, | ||
| 170 | + { user: "s-2", submission: { text: "x", submitted_at: now, updated_at: now, late: false, files: [] }, result: null, missing: false, unenrolled: false }, | ||
| 171 | + { user: "s-3", submission: { text: "y", submitted_at: now, updated_at: now, late: false, files: [] }, result: null, missing: false, unenrolled: false }, | ||
| 172 | + ]), | ||
| 168 | getHomeworkReport: async () => page([ | 173 | getHomeworkReport: async () => page([ |
| 169 | { class_course: "instance-1", homework: "hw-late", title: "Essay draft", subject: "s-1", due_at: now - 2 * DAY, submitted: false, late: false, missing: true, result: null }, | 174 | { class_course: "instance-1", homework: "hw-late", title: "Essay draft", subject: "s-1", due_at: now - 2 * DAY, submitted: false, late: false, missing: true, result: null }, |
| 170 | { class_course: "instance-1", homework: "hw-soon", title: "Worksheet 4", subject: "s-1", due_at: now + 2 * DAY, submitted: false, late: false, missing: false, result: null }, | 175 | { class_course: "instance-1", homework: "hw-soon", title: "Worksheet 4", subject: "s-1", due_at: now + 2 * DAY, submitted: false, late: false, missing: false, result: null }, |
| @@ -175,6 +180,7 @@ vi.mock("@/api/homework", () => ({ | |||
| 175 | id: "homework-1", | 180 | id: "homework-1", |
| 176 | title: "Homework deadline", | 181 | title: "Homework deadline", |
| 177 | due_at: now + 5_000, | 182 | due_at: now + 5_000, |
| 183 | + created_by: "u-1", | ||
| 178 | }, | 184 | }, |
| 179 | { id: "homework-past", title: "Past homework", due_at: now - 6 * DAY }, | 185 | { id: "homework-past", title: "Past homework", due_at: now - 6 * DAY }, |
| 180 | ]), | 186 | ]), |
| @@ -365,3 +371,12 @@ test("a student's board shows the day's lessons with no roll-call reads", async | |||
| 365 | expect(within(panel).getByText(/On now|Şimdi/)).toBeTruthy(); | 371 | expect(within(panel).getByText(/On now|Şimdi/)).toBeTruthy(); |
| 366 | expect(within(panel).queryByText(/Roll call|Yoklama/)).toBeNull(); | 372 | expect(within(panel).queryByText(/Roll call|Yoklama/)).toBeNull(); |
| 367 | }); | 373 | }); |
| 374 | + | ||
| 375 | +test("a teacher sees which of their homework is waiting on them, in plain sentences", async () => { | ||
| 376 | + renderDashboard("teacher"); | ||
| 377 | + | ||
| 378 | + const panel = await screen.findByRole("region", { name: /Homework waiting on you|Seni bekleyen ödevler/ }); | ||
| 379 | + expect(within(panel).getByText("Homework deadline")).toBeTruthy(); | ||
| 380 | + expect(within(panel).getByText(/1 not handed in · 2 waiting for a grade|1 teslim etmedi · 2 not bekliyor/)).toBeTruthy(); | ||
| 381 | + expect(within(panel).getByText(/2 to grade|2 notlanacak/)).toBeTruthy(); | ||
| 382 | +}); | ||
src/pages/dashboard-page.tsxmodified+9 -3
| @@ -32,6 +32,7 @@ import { DataTable } from "@/components/ui/data-table"; | |||
| 32 | import { CommandSearchField } from "@/components/dashboard/command-search-field"; | 32 | import { CommandSearchField } from "@/components/dashboard/command-search-field"; |
| 33 | import { QuickLinkColumn, type QuickLinkRow } from "@/components/dashboard/quick-link-column"; | 33 | import { QuickLinkColumn, type QuickLinkRow } from "@/components/dashboard/quick-link-column"; |
| 34 | import { ChildHomeworkPanel } from "@/components/dashboard/child-homework-panel"; | 34 | import { ChildHomeworkPanel } from "@/components/dashboard/child-homework-panel"; |
| 35 | +import { HomeworkQueuePanel } from "@/components/dashboard/homework-queue-panel"; | ||
| 35 | import { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel"; | 36 | import { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel"; |
| 36 | import { StatTile } from "@/components/dashboard/stat-tile"; | 37 | import { StatTile } from "@/components/dashboard/stat-tile"; |
| 37 | import { | 38 | import { |
| @@ -850,9 +851,14 @@ function DashboardContent() { | |||
| 850 | out, so it keeps its ComingSoonPanel slot. The AI suggestion | 851 | out, so it keeps its ComingSoonPanel slot. The AI suggestion |
| 851 | queue has no backend at all. The one real rail item behind that | 852 | queue has no backend at all. The one real rail item behind that |
| 852 | queue — a pending appointment request — gets the rail. */} | 853 | queue — a pending appointment request — gets the rail. */} |
| 853 | - <Show when={on("sessions") && clock()}> | 854 | + <div class="grid grid-cols-1 gap-3 lg:grid-cols-2"> |
| 854 | - {(ready) => <TodayLessonsPanel now={ready().now} courseTitle={courseTitleOf} />} | 855 | + <Show when={on("sessions") && clock()}> |
| 855 | - </Show> | 856 | + {(ready) => <TodayLessonsPanel now={ready().now} courseTitle={courseTitleOf} />} |
| 857 | + </Show> | ||
| 858 | + <Show when={on("homework") && clock()}> | ||
| 859 | + {(ready) => <HomeworkQueuePanel homework={homework()?.items ?? []} teacherId={user().id} now={ready().now} />} | ||
| 860 | + </Show> | ||
| 861 | + </div> | ||
| 856 | <div class="grid grid-cols-1 gap-3 lg:grid-cols-3"> | 862 | <div class="grid grid-cols-1 gap-3 lg:grid-cols-3"> |
| 857 | <Show when={on("exams")}> | 863 | <Show when={on("exams")}> |
| 858 | <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:col-span-2"> | 864 | <div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:col-span-2"> |