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())}
  • )}
); }