diff --git a/.claude/skills/dashboard-design/SKILL.md b/.claude/skills/dashboard-design/SKILL.md index c3c8ed0..c028518 100644 --- a/.claude/skills/dashboard-design/SKILL.md +++ b/.claude/skills/dashboard-design/SKILL.md @@ -56,6 +56,11 @@ Reference: `src/pages/dashboard-page.tsx`. The homepage is a **read-only status itself. The teacher panel reads roll-call counts only for lessons that have started; the student panel never reads roll call. Gate it on the `sessions` module. +- **Teacher homework queue:** `HomeworkQueuePanel` reads the roster + (`/homework/{id}/submissions`) of at most `QUEUE_CAP` of the teacher's own + homework due in the last 14 days or next 2, and says how many have not handed + in and how many wait for a grade; rows link to the homework. No bulk endpoint, + so the cap stays; a failed read drops its row. - **Parent homework:** `ChildHomeworkPanel` reads the selected child's `/homework/report/{user}` (overdue / due this week) with no links — a parent cannot open the course-scoped homework page. diff --git a/src/components/dashboard/homework-queue-panel.tsx b/src/components/dashboard/homework-queue-panel.tsx new file mode 100644 index 0000000..cd1da1d --- /dev/null +++ b/src/components/dashboard/homework-queue-panel.tsx @@ -0,0 +1,80 @@ +import { For, Show, createMemo } from "solid-js"; +import { Link } from "@tanstack/solid-router"; +import { createResource } from "@/lib/create-resource"; +import type { Homework } from "@/api/client"; +import { getHomeworkSubmissions } from "@/api/homework"; +import { EmptyInline } from "@/components/ui/empty-inline"; +import { IconChevronRight } from "@/components/ui/icons"; +import { formatDateTime } from "@/lib/format"; +import { queueCandidates, queueRow, type QueueRow } from "@/lib/homework-queue"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +/** + * TCH "what is waiting on me": for the teacher's own homework due around + * now, how many students have not handed in and how many hand-ins still need + * a grade — as sentences, each linking to that homework. Counts come from + * each homework's roster (`/homework/{id}/submissions`), read for a capped + * handful since there is no bulk endpoint; a failed read drops its row. + */ +export function HomeworkQueuePanel(props: { homework: Homework[]; teacherId: string; now: number }) { + const t = useT(); + const { locale } = usePreferences(); + const candidates = createMemo(() => queueCandidates(props.homework, props.teacherId, props.now)); + const [rows] = createResource( + () => candidates().map((item) => item.id).join(",") || null, + async () => { + const settled = await Promise.all( + candidates().map(async (item) => { + try { + return queueRow(item, (await getHomeworkSubmissions(item.id)).items); + } catch { + return null; + } + }), + ); + return settled.filter((row): row is QueueRow => row != null && row.missing + row.toGrade > 0); + }, + ); + const toGrade = () => (rows() ?? []).reduce((sum, row) => sum + row.toGrade, 0); + + return ( +
+
+

{t("homeworkQueue.title")}

+ 0}> + {t("homeworkQueue.toGradeTotal", { count: toGrade() })} + +
+ 0} + fallback={} + > +
    + + {(row) => ( +
  • + + + {row.homework.title} + + {[ + row.missing > 0 ? t("homeworkQueue.missing", { count: row.missing }) : null, + row.toGrade > 0 ? t("homeworkQueue.toGrade", { count: row.toGrade }) : null, + ].filter(Boolean).join(" · ")} + + + {formatDateTime(row.homework.due_at, locale())} + + +
  • + )} +
    +
+
+
+ ); +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 7d4401e..3c88954 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -616,6 +616,11 @@ export type MessageKey = | "common.deleted" | "common.saved" | "common.loadAll" + | "homeworkQueue.title" + | "homeworkQueue.toGradeTotal" + | "homeworkQueue.missing" + | "homeworkQueue.toGrade" + | "homeworkQueue.empty" | "aiHub.tab.study" | "today.titleStudent" | "today.inProgress" @@ -2784,6 +2789,11 @@ const en: Dict = { "common.deleted": "Deleted.", "common.saved": "Saved successfully.", "common.loadAll": "Load all", + "homeworkQueue.title": "Homework waiting on you", + "homeworkQueue.toGradeTotal": "{count} to grade", + "homeworkQueue.missing": "{count} not handed in", + "homeworkQueue.toGrade": "{count} waiting for a grade", + "homeworkQueue.empty": "Nothing is waiting on your recent homework.", "aiHub.tab.study": "Study", "today.titleStudent": "Today's lessons", "today.inProgress": "On now", @@ -4954,6 +4964,11 @@ const tr: Dict = { "common.deleted": "Silindi.", "common.saved": "Başarıyla kaydedildi.", "common.loadAll": "Tümünü yükle", + "homeworkQueue.title": "Seni bekleyen ödevler", + "homeworkQueue.toGradeTotal": "{count} notlanacak", + "homeworkQueue.missing": "{count} teslim etmedi", + "homeworkQueue.toGrade": "{count} not bekliyor", + "homeworkQueue.empty": "Son ödevlerinde bekleyen bir şey yok.", "aiHub.tab.study": "Çalış", "today.titleStudent": "Bugünkü derslerin", "today.inProgress": "Şimdi", diff --git a/src/lib/homework-queue.test.ts b/src/lib/homework-queue.test.ts new file mode 100644 index 0000000..6aeb07f --- /dev/null +++ b/src/lib/homework-queue.test.ts @@ -0,0 +1,45 @@ +import type { Homework, HomeworkRosterEntry } from "@/api/client"; +import { queueCandidates, queueRow } from "./homework-queue"; + +const DAY = 24 * 60 * 60 * 1000; +const now = Date.UTC(2026, 8, 19, 9); +const hw = (id: string, due: number, createdBy = "t-1"): Homework => ({ + id, + class_course: "i-1", + subject: "s-1", + title: id, + description: null, + due_at: due, + assigned: null, + created_by: createdBy, + created_at: now - 30 * DAY, +}); +const row = (state: Partial): HomeworkRosterEntry => ({ + user: "u", + submission: null, + result: null, + missing: false, + unenrolled: false, + ...state, +}); + +it("keeps the teacher's own homework due around now, closest first", () => { + const picked = queueCandidates( + [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)], + "t-1", + now, + ); + expect(picked.map((item) => item.id)).toEqual(["yesterday", "tomorrow", "last-week"]); +}); + +it("counts missing and ungraded work, leaving unenrolled rows out", () => { + const submission = { text: "done", submitted_at: now, updated_at: now, late: false, files: [] }; + const counts = queueRow(hw("h", now), [ + row({ missing: true }), + row({ missing: true, unenrolled: true }), + row({ submission }), + row({ submission, result: { mark: 80 } as never }), + row({}), + ]); + expect(counts).toMatchObject({ missing: 1, toGrade: 1 }); +}); diff --git a/src/lib/homework-queue.ts b/src/lib/homework-queue.ts new file mode 100644 index 0000000..d276ff3 --- /dev/null +++ b/src/lib/homework-queue.ts @@ -0,0 +1,35 @@ +import type { Homework, HomeworkRosterEntry } from "@/api/client"; + +const DAY_MS = 24 * 60 * 60 * 1000; +/** How far back a due date still counts as work waiting on the teacher. */ +export const QUEUE_LOOKBACK_MS = 14 * DAY_MS; +/** How far ahead: homework due in the next two days is worth a glance now. */ +export const QUEUE_LOOKAHEAD_MS = 2 * DAY_MS; +/** Roster reads per board load; there is no bulk endpoint. */ +export const QUEUE_CAP = 6; + +export type QueueRow = { + homework: Homework; + /** Students in the audience who have not handed in (`missing`). */ + missing: number; + /** Handed in, not graded yet. */ + toGrade: number; +}; + +/** The teacher's own homework due around now, most recently due first. */ +export function queueCandidates(items: Homework[], teacherId: string, now: number): Homework[] { + return items + .filter((item) => item.created_by === teacherId && item.due_at >= now - QUEUE_LOOKBACK_MS && item.due_at <= now + QUEUE_LOOKAHEAD_MS) + .sort((a, b) => Math.abs(now - a.due_at) - Math.abs(now - b.due_at)) + .slice(0, QUEUE_CAP); +} + +/** Counts from one homework's roster; rows left behind by an unenrollment are not owed. */ +export function queueRow(homework: Homework, roster: HomeworkRosterEntry[]): QueueRow { + const current = roster.filter((row) => !row.unenrolled); + return { + homework, + missing: current.filter((row) => row.missing).length, + toGrade: current.filter((row) => row.submission != null && row.result == null).length, + }; +} diff --git a/src/pages/dashboard-page.test.tsx b/src/pages/dashboard-page.test.tsx index e632cb4..30e2dbe 100644 --- a/src/pages/dashboard-page.test.tsx +++ b/src/pages/dashboard-page.test.tsx @@ -165,6 +165,11 @@ vi.mock("@/api/events", () => ({ ]), })); vi.mock("@/api/homework", () => ({ + getHomeworkSubmissions: async () => page([ + { user: "s-1", submission: null, result: null, missing: true, unenrolled: false }, + { user: "s-2", submission: { text: "x", submitted_at: now, updated_at: now, late: false, files: [] }, result: null, missing: false, unenrolled: false }, + { user: "s-3", submission: { text: "y", submitted_at: now, updated_at: now, late: false, files: [] }, result: null, missing: false, unenrolled: false }, + ]), getHomeworkReport: async () => page([ { 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 }, { 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", () => ({ id: "homework-1", title: "Homework deadline", due_at: now + 5_000, + created_by: "u-1", }, { id: "homework-past", title: "Past homework", due_at: now - 6 * DAY }, ]), @@ -365,3 +371,12 @@ test("a student's board shows the day's lessons with no roll-call reads", async expect(within(panel).getByText(/On now|Şimdi/)).toBeTruthy(); expect(within(panel).queryByText(/Roll call|Yoklama/)).toBeNull(); }); + +test("a teacher sees which of their homework is waiting on them, in plain sentences", async () => { + renderDashboard("teacher"); + + const panel = await screen.findByRole("region", { name: /Homework waiting on you|Seni bekleyen ödevler/ }); + expect(within(panel).getByText("Homework deadline")).toBeTruthy(); + expect(within(panel).getByText(/1 not handed in · 2 waiting for a grade|1 teslim etmedi · 2 not bekliyor/)).toBeTruthy(); + expect(within(panel).getByText(/2 to grade|2 notlanacak/)).toBeTruthy(); +}); diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index 966666a..6bb5024 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -32,6 +32,7 @@ import { DataTable } from "@/components/ui/data-table"; import { CommandSearchField } from "@/components/dashboard/command-search-field"; import { QuickLinkColumn, type QuickLinkRow } from "@/components/dashboard/quick-link-column"; import { ChildHomeworkPanel } from "@/components/dashboard/child-homework-panel"; +import { HomeworkQueuePanel } from "@/components/dashboard/homework-queue-panel"; import { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel"; import { StatTile } from "@/components/dashboard/stat-tile"; import { @@ -850,9 +851,14 @@ function DashboardContent() { out, so it keeps its ComingSoonPanel slot. The AI suggestion queue has no backend at all. The one real rail item behind that queue — a pending appointment request — gets the rail. */} - - {(ready) => } - +
+ + {(ready) => } + + + {(ready) => } + +