Files
DeepTutor/web/components/courses/CourseProgress.tsx
Bingxi Zhao (Frank) 43c9fe7ea0 feat(course): make a course the container, not a dashboard
A course held the right model — the syllabus that gives progress a
denominator, resources as references, conventions apart from the
assistant's own notes — but almost nothing crossed the edges between it
and the surfaces it was supposed to contain.

Getting in. Course Study was offered in the composer's mode menu while
the only way to bind a course was a link on the course page, so choosing
it there produced a conversation identical to an inert one, and the mode
advised pressing a button that did not exist. The composer now carries
the binding next to the mode: shown whenever there is one, and offered
as an unfinished field in Course Study when there is not. `_course_id`
rides every turn, so detaching detaches and the pill can never drift
from what the turn actually saw.

What a conversation inherits. `default_capability` and `default_persona`
were stored, validated and returned by the API while changing nothing:
`_apply_course_defaults` only fills fields a payload *omits*, and this
composer always sent all of them. They are applied client-side now,
along with the course's knowledge bases, where the learner can watch the
mode and material become the course's before they type. The dialog grows
the editor they never had.

Conventions. "Every conversation in this course starts knowing these" was
true only if the model happened to call `course_overview`. They ride in
the per-turn summary now, and — because the promise is not scoped to one
mode — in the system prompt of any course-bound turn.

Coming back. Mastery Path and Immersive Reading now read `?course=`,
scope themselves to it, and attach whatever is built there; the tiles and
hand-offs pass it; the picker offers to start one. A course could only
ever reference what already existed, so filling a new one meant leaving,
building, and remembering to return.

Hand-offs. A target with no ref stored an opening line for an index that
never consumes it, which then surfaced weeks later in an unrelated path.
An unresolvable ref was passed straight through: observed live, a
syllabus unit id ("u2") sent as a mastery path, producing a card pointing
at a page that does not exist. Refs are checked against the subsystem
that owns them — existence, not membership, since a path built outside
this course routes perfectly well.

Also: the sidebar groups conversations by course, so filing them is
finally readable; a course-scoped notebook console no longer shows
another course's notes beside a list saying there are none (the clear
raced an in-flight detail fetch that landed after it); a hand-off the
model also printed as prose is not rendered twice; a provider error is no
longer stored as a conversation's permanent title; `/space/courses` goes,
having been an unreferenced copy of `/courses`; and the Visualize mode
description gets its missing Chinese.
2026-08-30 00:09:36 +08:00

164 lines
5.2 KiB
TypeScript

"use client";
import Link from "next/link";
import {
ClipboardList,
GraduationCap,
NotebookPen,
ScrollText,
} from "lucide-react";
import { useTranslation } from "react-i18next";
import type { CourseState } from "@/lib/courses-api";
/**
* Where this course stands, as four entry points that carry their own numbers.
*
* These replaced four bare shortcuts that linked to the global notebook,
* question bank, and mastery-path surfaces with no course scope at all — the
* page promised "this course's three things" and delivered site-wide
* navigation. Every figure below comes from `GET /api/v1/courses/{id}/state`,
* which counts only what this course references or produced, and every link
* carries the course through so the destination can scope itself too.
*
* A section with nothing in it still renders, saying what would put something
* there. A tile that disappears when empty takes the way to fix that with it.
*/
export default function CourseProgress({
state,
courseId,
}: {
state: CourseState | null;
courseId: string;
}) {
const { t } = useTranslation();
const course = encodeURIComponent(courseId);
const paths = state?.mastery.paths ?? [];
const objectivesMastered = paths.reduce((sum, path) => sum + path.objectives_mastered, 0);
const objectivesTotal = paths.reduce((sum, path) => sum + path.objectives_total, 0);
const weakest = paths.flatMap((path) => path.weak_points)[0] ?? "";
const bank = state?.question_bank;
const weakCategory = bank?.weak_categories?.[0];
const workspaces = state?.reading.workspaces ?? [];
const materials = workspaces.reduce(
(sum, workspace) => sum + workspace.materials,
0,
);
const notebooks = (state?.resources ?? []).filter(
(resource) => resource.kind === "notebook",
);
return (
<div className="grid gap-3 sm:grid-cols-2 lg:grid-cols-4">
<Tile
// The index carries the course so it opens as this course's shelf: what
// gets built there attaches back here instead of stranding the learner
// one manual step away from the container they started in.
href={
paths.length === 1
? `/mastery/${encodeURIComponent(paths[0].path_id)}`
: `/mastery?course=${course}`
}
icon={GraduationCap}
label={t("Mastery Path")}
value={
objectivesTotal > 0
? `${objectivesMastered}/${objectivesTotal}`
: "—"
}
detail={
objectivesTotal > 0
? weakest
? t("{{count}} objectives · weakest {{name}}", {
count: objectivesTotal,
name: weakest,
})
: t("{{count}} objectives across {{paths}} paths", {
count: objectivesTotal,
paths: paths.length,
})
: t("Attach or build a path to track mastery")
}
/>
<Tile
href={`/space/questions?course=${course}`}
icon={ClipboardList}
label={t("Question Bank")}
value={bank && bank.total > 0 ? String(bank.wrong) : "—"}
detail={
bank && bank.total > 0
? weakCategory
? t("wrong of {{total}} · weakest {{name}}", {
total: bank.total,
name: weakCategory.name,
})
: t("wrong of {{total}}", { total: bank.total })
: t("Questions you get wrong land here")
}
/>
<Tile
href={
workspaces.length === 1
? `/reading/${encodeURIComponent(workspaces[0].workspace_id)}`
: `/reading?course=${course}`
}
icon={ScrollText}
label={t("Immersive Reading")}
value={materials > 0 ? String(materials) : "—"}
detail={
materials > 0
? t("{{count}} materials open", { count: materials })
: t("Attach a reading workspace to read alongside the tutor")
}
/>
<Tile
href={`/notebook?course=${course}`}
icon={NotebookPen}
label={t("Notebooks")}
value={notebooks.length > 0 ? String(notebooks.length) : "—"}
detail={
notebooks.length > 0
? notebooks[0].label
: t("Attach a notebook to keep this course's notes together")
}
/>
</div>
);
}
function Tile({
href,
icon: Icon,
label,
value,
detail,
}: {
href: string;
icon: typeof GraduationCap;
label: string;
value: string;
detail: string;
}) {
return (
<Link
href={href}
className="group rounded-xl border border-[var(--border)] bg-[var(--card)] p-3.5 transition-all duration-150 hover:-translate-y-0.5 hover:border-[var(--foreground)]/20 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ring)]"
>
<div className="flex items-center gap-2 text-[var(--muted-foreground)]">
<Icon size={14} strokeWidth={1.7} />
<span className="text-[11.5px]">{label}</span>
</div>
<p className="mt-2 font-serif text-[20px] font-semibold leading-none text-[var(--foreground)]">
{value}
</p>
<p className="mt-1.5 line-clamp-2 text-[11px] leading-relaxed text-[var(--muted-foreground)]">
{detail}
</p>
</Link>
);
}