diff --git a/src/components/dashboard/child-homework-panel.tsx b/src/components/dashboard/child-homework-panel.tsx new file mode 100644 index 0000000..7f741a7 --- /dev/null +++ b/src/components/dashboard/child-homework-panel.tsx @@ -0,0 +1,79 @@ +import { For, Show } from "solid-js"; +import { createResource } from "@/lib/create-resource"; +import { formatApiError } from "@/api/client"; +import { getHomeworkReport } from "@/api/homework"; +import type { HomeworkReportEntry } from "@/api/client"; +import { EmptyInline } from "@/components/ui/empty-inline"; +import { summarizeChildHomework } from "@/lib/child-homework"; +import { cn } from "@/lib/cn"; +import { formatDateTime } from "@/lib/format"; +import { usePreferences, useT } from "@/stores/preferences-context"; + +/** Rows per list; the counts in the sentences above them stay exact. */ +const LIST_CAP = 5; + +/** + * PAR "what needs attention": the selected child's homework report turned + * into two plain sentences — how much is overdue, how much is due this week — + * with the rows behind each. Read only, and only the report's own fields: + * the parent route serves statuses and marks, never the submitted files. + */ +export function ChildHomeworkPanel(props: { childId: string; now: number; class?: string }) { + const t = useT(); + const { locale } = usePreferences(); + const [report] = createResource( + () => props.childId, + async (childId): Promise<{ items: HomeworkReportEntry[]; error: string }> => { + try { + return { items: (await getHomeworkReport(childId)).items, error: "" }; + } catch (err) { + return { items: [], error: formatApiError(err) }; + } + }, + ); + const summary = () => summarizeChildHomework(report()?.items ?? [], props.now); + + const renderList = (rows: HomeworkReportEntry[], tone: "late" | "soon") => ( + + ); + + return ( +
+

{t("childHomework.title")}

+ +

{report()!.error}

+
+ + 0} + fallback={} + > +
+
+

0 ? "text-destructive-text" : "text-muted-foreground")}> + {summary().missing.length > 0 ? t("childHomework.missing", { count: summary().missing.length }) : t("childHomework.noneMissing")} +

+ {renderList(summary().missing, "late")} +
+
+

+ {summary().dueSoon.length > 0 ? t("childHomework.dueSoon", { count: summary().dueSoon.length }) : t("childHomework.noneDueSoon")} +

+ {renderList(summary().dueSoon, "soon")} +
+
+
+
+
+ ); +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 8f4381d..7be7e4b 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -616,6 +616,12 @@ export type MessageKey = | "common.deleted" | "common.saved" | "common.loadAll" + | "childHomework.title" + | "childHomework.missing" + | "childHomework.noneMissing" + | "childHomework.dueSoon" + | "childHomework.noneDueSoon" + | "childHomework.allClear" | "today.title" | "today.owed" | "today.empty" @@ -2774,6 +2780,12 @@ const en: Dict = { "common.deleted": "Deleted.", "common.saved": "Saved successfully.", "common.loadAll": "Load all", + "childHomework.title": "Homework", + "childHomework.missing": "{count} homework not handed in", + "childHomework.noneMissing": "Nothing overdue", + "childHomework.dueSoon": "{count} due this week", + "childHomework.noneDueSoon": "Nothing due this week", + "childHomework.allClear": "Nothing overdue and nothing due this week.", "today.title": "Today's lessons", "today.owed": "{count} roll calls waiting", "today.empty": "No lessons today.", @@ -4934,6 +4946,12 @@ const tr: Dict = { "common.deleted": "Silindi.", "common.saved": "Başarıyla kaydedildi.", "common.loadAll": "Tümünü yükle", + "childHomework.title": "Ödevler", + "childHomework.missing": "{count} ödev teslim edilmedi", + "childHomework.noneMissing": "Geciken ödev yok", + "childHomework.dueSoon": "{count} ödevin teslimi bu hafta", + "childHomework.noneDueSoon": "Bu hafta teslim yok", + "childHomework.allClear": "Geciken ya da bu hafta teslim edilecek ödev yok.", "today.title": "Bugünkü derslerim", "today.owed": "{count} yoklama bekliyor", "today.empty": "Bugün dersin yok.", diff --git a/src/lib/child-homework.test.ts b/src/lib/child-homework.test.ts new file mode 100644 index 0000000..55c3be6 --- /dev/null +++ b/src/lib/child-homework.test.ts @@ -0,0 +1,33 @@ +import type { HomeworkReportEntry } from "@/api/client"; +import { summarizeChildHomework } from "./child-homework"; + +const DAY = 24 * 60 * 60 * 1000; +const now = Date.UTC(2026, 8, 18, 9); +const entry = (id: string, due: number, state: Partial = {}): HomeworkReportEntry => ({ + class_course: "instance-1", + homework: id, + title: id, + subject: "subject-1", + due_at: due, + submitted: false, + late: false, + missing: false, + result: null, + ...state, +}); + +it("splits a report into missing work and work due this week", () => { + const summary = summarizeChildHomework( + [ + entry("in-two-days", now + 2 * DAY), + entry("missing-new", now - DAY, { missing: true }), + entry("tomorrow", now + DAY), + entry("missing-old", now - 5 * DAY, { missing: true }), + entry("handed-in", now + DAY, { submitted: true }), + entry("next-month", now + 30 * DAY), + ], + now, + ); + expect(summary.missing.map((row) => row.homework)).toEqual(["missing-old", "missing-new"]); + expect(summary.dueSoon.map((row) => row.homework)).toEqual(["tomorrow", "in-two-days"]); +}); diff --git a/src/lib/child-homework.ts b/src/lib/child-homework.ts new file mode 100644 index 0000000..b632b85 --- /dev/null +++ b/src/lib/child-homework.ts @@ -0,0 +1,20 @@ +import type { HomeworkReportEntry } from "@/api/client"; + +const WEEK_MS = 7 * 24 * 60 * 60 * 1000; + +export type ChildHomeworkSummary = { + /** Past due and not handed in, most overdue first. */ + missing: HomeworkReportEntry[]; + /** Not handed in and due within the next seven days, soonest first. */ + dueSoon: HomeworkReportEntry[]; +}; + +/** A parent's view of a child's homework report: what is late and what is next. */ +export function summarizeChildHomework(entries: HomeworkReportEntry[], now: number): ChildHomeworkSummary { + return { + missing: entries.filter((entry) => entry.missing).sort((a, b) => a.due_at - b.due_at), + dueSoon: entries + .filter((entry) => !entry.submitted && !entry.missing && entry.due_at >= now && entry.due_at < now + WEEK_MS) + .sort((a, b) => a.due_at - b.due_at), + }; +} diff --git a/src/pages/dashboard-page.test.tsx b/src/pages/dashboard-page.test.tsx index c47c3c4..b2161b8 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", () => ({ + 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 }, + { 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 }, + ]), getHomework: async () => page([ { id: "homework-1", @@ -340,3 +345,14 @@ test("a teacher's board leads with today's lessons and what their roll call need expect(within(panel).getByText(/Roll call not taken|Yoklama alınmadı/)).toBeTruthy(); expect(within(panel).getByRole("link").getAttribute("href")).toBe("/instances/$id"); }); + +test("a parent sees the child's overdue and due-this-week homework in plain sentences", async () => { + renderDashboard("parent"); + + const panel = await screen.findByRole("region", { name: /^(Homework|Ödevler)$/ }); + expect(within(panel).getByText(/1 homework not handed in|1 ödev teslim edilmedi/)).toBeTruthy(); + expect(within(panel).getByText("Essay draft")).toBeTruthy(); + expect(within(panel).getByText(/1 due this week|1 ödevin teslimi bu hafta/)).toBeTruthy(); + expect(within(panel).getByText("Worksheet 4")).toBeTruthy(); + expect(within(panel).queryByText("Handed in")).toBeNull(); +}); diff --git a/src/pages/dashboard-page.tsx b/src/pages/dashboard-page.tsx index 173549d..70e8a96 100644 --- a/src/pages/dashboard-page.tsx +++ b/src/pages/dashboard-page.tsx @@ -31,6 +31,7 @@ import { ChartProgressRing } from "@/components/ui/chart-progress-ring"; 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 { TodayLessonsPanel } from "@/components/dashboard/today-lessons-panel"; import { StatTile } from "@/components/dashboard/stat-tile"; import { @@ -1012,7 +1013,15 @@ function DashboardContent() {
- + {/* PAR progress: the child's homework report (a parent-readable + route) as overdue / due-this-week, in place of the coming-soon + slot; marks-based progress still has no parent-facing trend. */} + } + > + +