forge
Explore
Log in

Don't you dare go Hollow

🎒 parents see what their child's homework needs

Browse files at this commit

ee27f6726d9e973bb2813fb1fa7834c7c3f190feBurak BoduroğluParent: 7a0de35
  • feat
    • 🎒 parents see what their child's homework needs
Show full message
feat: 🎒 parents see what their child's homework needs
- ChildHomeworkPanel replaces the parent board's progress coming-soon slot
  with the selected child's homework report (GET /homework/report/{user},
  a parent-readable route): how many are not handed in and how many are
  due this week, as plain sentences with the rows behind each
- read only and report fields only (statuses, never files); no links,
  since a parent cannot open the course-scoped homework page
- summarizeChildHomework helper with tests; dashboard test for the panel
src/components/dashboard/child-homework-panel.tsxadded+79 -0
@@ -0,0 +1,79 @@
1+import { For, Show } from "solid-js";
2+import { createResource } from "@/lib/create-resource";
3+import { formatApiError } from "@/api/client";
4+import { getHomeworkReport } from "@/api/homework";
5+import type { HomeworkReportEntry } from "@/api/client";
6+import { EmptyInline } from "@/components/ui/empty-inline";
7+import { summarizeChildHomework } from "@/lib/child-homework";
8+import { cn } from "@/lib/cn";
9+import { formatDateTime } from "@/lib/format";
10+import { usePreferences, useT } from "@/stores/preferences-context";
11+
12+/** Rows per list; the counts in the sentences above them stay exact. */
13+const LIST_CAP = 5;
14+
15+/**
16+ * PAR "what needs attention": the selected child's homework report turned
17+ * into two plain sentences — how much is overdue, how much is due this week —
18+ * with the rows behind each. Read only, and only the report's own fields:
19+ * the parent route serves statuses and marks, never the submitted files.
20+ */
21+export function ChildHomeworkPanel(props: { childId: string; now: number; class?: string }) {
22+ const t = useT();
23+ const { locale } = usePreferences();
24+ const [report] = createResource(
25+ () => props.childId,
26+ async (childId): Promise<{ items: HomeworkReportEntry[]; error: string }> => {
27+ try {
28+ return { items: (await getHomeworkReport(childId)).items, error: "" };
29+ } catch (err) {
30+ return { items: [], error: formatApiError(err) };
31+ }
32+ },
33+ );
34+ const summary = () => summarizeChildHomework(report()?.items ?? [], props.now);
35+
36+ const renderList = (rows: HomeworkReportEntry[], tone: "late" | "soon") => (
37+ <ul class="divide-y divide-border-hairline">
38+ <For each={rows.slice(0, LIST_CAP)}>
39+ {(row) => (
40+ <li class="flex items-center gap-3 py-2">
41+ <span class={cn("h-2 w-2 shrink-0 rounded-full", tone === "late" ? "bg-destructive" : "bg-warning")} aria-hidden="true" />
42+ <span class="min-w-0 flex-1 truncate text-sm text-text-default">{row.title}</span>
43+ <span class="mono shrink-0 text-xs tabular-nums text-muted-foreground">{formatDateTime(row.due_at, locale())}</span>
44+ </li>
45+ )}
46+ </For>
47+ </ul>
48+ );
49+
50+ return (
51+ <section class={cn("flex flex-col gap-3 rounded-xl border border-border-line bg-surface-base p-4", props.class)} aria-labelledby="child-homework-heading">
52+ <h2 id="child-homework-heading" class="text-base font-semibold tracking-tight text-text-strong">{t("childHomework.title")}</h2>
53+ <Show when={report()?.error}>
54+ <p class="text-sm text-destructive-text">{report()!.error}</p>
55+ </Show>
56+ <Show when={!report()?.error}>
57+ <Show
58+ when={summary().missing.length + summary().dueSoon.length > 0}
59+ fallback={<EmptyInline illustration="calendar-empty" title={t("childHomework.allClear")} />}
60+ >
61+ <div class="grid gap-4 sm:grid-cols-2">
62+ <div class="space-y-1.5">
63+ <p class={cn("text-sm font-medium", summary().missing.length > 0 ? "text-destructive-text" : "text-muted-foreground")}>
64+ {summary().missing.length > 0 ? t("childHomework.missing", { count: summary().missing.length }) : t("childHomework.noneMissing")}
65+ </p>
66+ {renderList(summary().missing, "late")}
67+ </div>
68+ <div class="space-y-1.5">
69+ <p class="text-sm font-medium text-text-default">
70+ {summary().dueSoon.length > 0 ? t("childHomework.dueSoon", { count: summary().dueSoon.length }) : t("childHomework.noneDueSoon")}
71+ </p>
72+ {renderList(summary().dueSoon, "soon")}
73+ </div>
74+ </div>
75+ </Show>
76+ </Show>
77+ </section>
78+ );
79+}
src/i18n/messages.tsmodified+18 -0
@@ -616,6 +616,12 @@ export type MessageKey =
616 | "common.deleted"616 | "common.deleted"
617 | "common.saved"617 | "common.saved"
618 | "common.loadAll"618 | "common.loadAll"
619+ | "childHomework.title"
620+ | "childHomework.missing"
621+ | "childHomework.noneMissing"
622+ | "childHomework.dueSoon"
623+ | "childHomework.noneDueSoon"
624+ | "childHomework.allClear"
619 | "today.title"625 | "today.title"
620 | "today.owed"626 | "today.owed"
621 | "today.empty"627 | "today.empty"
@@ -2774,6 +2780,12 @@ const en: Dict = {
2774 "common.deleted": "Deleted.",2780 "common.deleted": "Deleted.",
2775 "common.saved": "Saved successfully.",2781 "common.saved": "Saved successfully.",
2776 "common.loadAll": "Load all",2782 "common.loadAll": "Load all",
2783+ "childHomework.title": "Homework",
2784+ "childHomework.missing": "{count} homework not handed in",
2785+ "childHomework.noneMissing": "Nothing overdue",
2786+ "childHomework.dueSoon": "{count} due this week",
2787+ "childHomework.noneDueSoon": "Nothing due this week",
2788+ "childHomework.allClear": "Nothing overdue and nothing due this week.",
2777 "today.title": "Today's lessons",2789 "today.title": "Today's lessons",
2778 "today.owed": "{count} roll calls waiting",2790 "today.owed": "{count} roll calls waiting",
2779 "today.empty": "No lessons today.",2791 "today.empty": "No lessons today.",
@@ -4934,6 +4946,12 @@ const tr: Dict = {
4934 "common.deleted": "Silindi.",4946 "common.deleted": "Silindi.",
4935 "common.saved": "Başarıyla kaydedildi.",4947 "common.saved": "Başarıyla kaydedildi.",
4936 "common.loadAll": "Tümünü yükle",4948 "common.loadAll": "Tümünü yükle",
4949+ "childHomework.title": "Ödevler",
4950+ "childHomework.missing": "{count} ödev teslim edilmedi",
4951+ "childHomework.noneMissing": "Geciken ödev yok",
4952+ "childHomework.dueSoon": "{count} ödevin teslimi bu hafta",
4953+ "childHomework.noneDueSoon": "Bu hafta teslim yok",
4954+ "childHomework.allClear": "Geciken ya da bu hafta teslim edilecek ödev yok.",
4937 "today.title": "Bugünkü derslerim",4955 "today.title": "Bugünkü derslerim",
4938 "today.owed": "{count} yoklama bekliyor",4956 "today.owed": "{count} yoklama bekliyor",
4939 "today.empty": "Bugün dersin yok.",4957 "today.empty": "Bugün dersin yok.",
src/lib/child-homework.test.tsadded+33 -0
@@ -0,0 +1,33 @@
1+import type { HomeworkReportEntry } from "@/api/client";
2+import { summarizeChildHomework } from "./child-homework";
3+
4+const DAY = 24 * 60 * 60 * 1000;
5+const now = Date.UTC(2026, 8, 18, 9);
6+const entry = (id: string, due: number, state: Partial<HomeworkReportEntry> = {}): HomeworkReportEntry => ({
7+ class_course: "instance-1",
8+ homework: id,
9+ title: id,
10+ subject: "subject-1",
11+ due_at: due,
12+ submitted: false,
13+ late: false,
14+ missing: false,
15+ result: null,
16+ ...state,
17+});
18+
19+it("splits a report into missing work and work due this week", () => {
20+ const summary = summarizeChildHomework(
21+ [
22+ entry("in-two-days", now + 2 * DAY),
23+ entry("missing-new", now - DAY, { missing: true }),
24+ entry("tomorrow", now + DAY),
25+ entry("missing-old", now - 5 * DAY, { missing: true }),
26+ entry("handed-in", now + DAY, { submitted: true }),
27+ entry("next-month", now + 30 * DAY),
28+ ],
29+ now,
30+ );
31+ expect(summary.missing.map((row) => row.homework)).toEqual(["missing-old", "missing-new"]);
32+ expect(summary.dueSoon.map((row) => row.homework)).toEqual(["tomorrow", "in-two-days"]);
33+});
src/lib/child-homework.tsadded+20 -0
@@ -0,0 +1,20 @@
1+import type { HomeworkReportEntry } from "@/api/client";
2+
3+const WEEK_MS = 7 * 24 * 60 * 60 * 1000;
4+
5+export type ChildHomeworkSummary = {
6+ /** Past due and not handed in, most overdue first. */
7+ missing: HomeworkReportEntry[];
8+ /** Not handed in and due within the next seven days, soonest first. */
9+ dueSoon: HomeworkReportEntry[];
10+};
11+
12+/** A parent's view of a child's homework report: what is late and what is next. */
13+export function summarizeChildHomework(entries: HomeworkReportEntry[], now: number): ChildHomeworkSummary {
14+ return {
15+ missing: entries.filter((entry) => entry.missing).sort((a, b) => a.due_at - b.due_at),
16+ dueSoon: entries
17+ .filter((entry) => !entry.submitted && !entry.missing && entry.due_at >= now && entry.due_at < now + WEEK_MS)
18+ .sort((a, b) => a.due_at - b.due_at),
19+ };
20+}
src/pages/dashboard-page.test.tsxmodified+16 -0
@@ -165,6 +165,11 @@ vi.mock("@/api/events", () => ({
165 ]),165 ]),
166 }));166 }));
167 vi.mock("@/api/homework", () => ({167 vi.mock("@/api/homework", () => ({
168+ 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 },
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 },
171+ { class_course: "instance-1", homework: "hw-done", title: "Handed in", subject: "s-1", due_at: now + DAY, submitted: true, late: false, missing: false, result: null },
172+ ]),
168 getHomework: async () => page([173 getHomework: async () => page([
169 {174 {
170 id: "homework-1",175 id: "homework-1",
@@ -340,3 +345,14 @@ test("a teacher's board leads with today's lessons and what their roll call need
340 expect(within(panel).getByText(/Roll call not taken|Yoklama alınmadı/)).toBeTruthy();345 expect(within(panel).getByText(/Roll call not taken|Yoklama alınmadı/)).toBeTruthy();
341 expect(within(panel).getByRole("link").getAttribute("href")).toBe("/instances/$id");346 expect(within(panel).getByRole("link").getAttribute("href")).toBe("/instances/$id");
342 });347 });
348+
349+test("a parent sees the child's overdue and due-this-week homework in plain sentences", async () => {
350+ renderDashboard("parent");
351+
352+ const panel = await screen.findByRole("region", { name: /^(Homework|Ödevler)$/ });
353+ expect(within(panel).getByText(/1 homework not handed in|1 ödev teslim edilmedi/)).toBeTruthy();
354+ expect(within(panel).getByText("Essay draft")).toBeTruthy();
355+ expect(within(panel).getByText(/1 due this week|1 ödevin teslimi bu hafta/)).toBeTruthy();
356+ expect(within(panel).getByText("Worksheet 4")).toBeTruthy();
357+ expect(within(panel).queryByText("Handed in")).toBeNull();
358+});
src/pages/dashboard-page.tsxmodified+10 -1
@@ -31,6 +31,7 @@ import { ChartProgressRing } from "@/components/ui/chart-progress-ring";
31 import { DataTable } from "@/components/ui/data-table";31 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 { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel";35 import { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel";
35 import { StatTile } from "@/components/dashboard/stat-tile";36 import { StatTile } from "@/components/dashboard/stat-tile";
36 import {37 import {
@@ -1012,7 +1013,15 @@ function DashboardContent() {
1012 </Show>1013 </Show>
1013 </div>1014 </div>
1014 <div class="grid grid-cols-1 gap-3 lg:grid-cols-3">1015 <div class="grid grid-cols-1 gap-3 lg:grid-cols-3">
1015- <ComingSoonPanel class="lg:col-span-2" title={t("dashboard.parent.progress")} />1016+ {/* PAR progress: the child's homework report (a parent-readable
1017+ route) as overdue / due-this-week, in place of the coming-soon
1018+ slot; marks-based progress still has no parent-facing trend. */}
1019+ <Show
1020+ when={on("homework") && selectedChildId() && clock()}
1021+ fallback={<ComingSoonPanel class="lg:col-span-2" title={t("dashboard.parent.progress")} />}
1022+ >
1023+ <ChildHomeworkPanel class="lg:col-span-2" childId={selectedChildId()} now={clock()!.now} />
1024+ </Show>
1016 <ComingSoonPanel title={t("dashboard.parent.teacherNotes")} />1025 <ComingSoonPanel title={t("dashboard.parent.teacherNotes")} />
1017 </div>1026 </div>
1018 </Show>1027 </Show>