Skip to content

DeepTutor: Lifelong Personalized Tutoring. https://deeptutor.info/.

Block 10+11: Module list page with progress cards + learning-api client

whf92ae45e36178
diff --git a/web/app/(workspace)/learning/page.tsx b/web/app/(workspace)/learning/page.tsx
index 44b808acc..5d4b48c2a 100644
--- a/web/app/(workspace)/learning/page.tsx
+++ b/web/app/(workspace)/learning/page.tsx
@@ -1,18 +1,120 @@
"use client";
-import { useTranslation } from "react-i18next";
-import { Lightbulb } from "lucide-react";
+import { useEffect, useState, useCallback } from "react";
+import { useRouter } from "next/navigation";
+import { BookOpen, Loader2, Play } from "lucide-react";
+import { fetchProgress } from "@/lib/learning-api";
+
+interface ModuleSummary {
+ id: string;
+ name: string;
+ order: number;
+ pass_threshold: number;
+ knowledge_points: { id: string; name: string }[];
+}
export default function LearningPage() {
- const { t } = useTranslation();
+ const router = useRouter();
+ const [modules, setModules] = useState<ModuleSummary[]>([]);
+ const [masteryLevels, setMasteryLevels] = useState<Record<string, number>>({});
+ const [loading, setLoading] = useState(true);
+
+ const loadProgress = useCallback(async () => {
+ try {
+ const data = await fetchProgress("default");
+ setModules(data.modules ?? []);
+ setMasteryLevels(data.mastery_levels ?? {});
+ } catch {
+ // No progress yet — show empty state
+ } finally {
+ setLoading(false);
+ }
+ }, []);
+
+ useEffect(() => {
+ loadProgress();
+ }, [loadProgress]);
+
+ const masteredCount = (mod: ModuleSummary) =>
+ mod.knowledge_points.filter(
+ (kp) => (masteryLevels[kp.id] ?? 0) >= mod.pass_threshold,
+ ).length;
+
+ if (loading) {
+ return (
+ <div className="flex items-center justify-center h-full">
+ <Loader2 className="w-8 h-8 animate-spin text-[var(--muted-foreground)]" />
+ </div>
+ );
+ }
return (
- <div className="flex flex-col items-center justify-center h-full p-8">
- <Lightbulb className="w-16 h-16 text-[var(--primary)] mb-4" />
- <h1 className="text-2xl font-bold mb-2">Guided Learning</h1>
- <p className="text-[var(--muted-foreground)]">
- Framework v1.8.2 — structured mastery-based learning
- </p>
+ <div className="p-8 max-w-4xl mx-auto">
+ <div className="flex items-center justify-between mb-6">
+ <div>
+ <h1 className="text-2xl font-bold">Learning Modules</h1>
+ <p className="text-[var(--muted-foreground)] text-sm mt-1">
+ {modules.length > 0
+ ? `${modules.length} module${modules.length > 1 ? "s" : ""} available`
+ : "Start a learning session to generate modules"}
+ </p>
+ </div>
+ <button
+ onClick={() => router.push("/learning/default")}
+ className="flex items-center gap-2 px-4 py-2 rounded-lg bg-[var(--primary)] text-[var(--primary-foreground)] text-sm font-medium hover:opacity-90 transition-opacity"
+ >
+ <Play className="w-4 h-4" />
+ Start Learning
+ </button>
+ </div>
+
+ {modules.length === 0 ? (
+ <div className="flex flex-col items-center justify-center py-20 text-[var(--muted-foreground)]">
+ <BookOpen className="w-12 h-12 mb-4 opacity-50" />
+ <p className="text-lg font-medium">No modules yet</p>
+ <p className="text-sm mt-1">
+ Click &quot;Start Learning&quot; to begin — modules will be created automatically.
+ </p>
+ </div>
+ ) : (
+ <div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
+ {modules
+ .sort((a, b) => a.order - b.order)
+ .map((mod) => {
+ const mastered = masteredCount(mod);
+ const total = mod.knowledge_points.length;
+ const pct = total > 0 ? Math.round((mastered / total) * 100) : 0;
+
+ return (
+ <div
+ key={mod.id}
+ className="p-5 rounded-xl border border-[var(--border)] bg-[var(--card)]"
+ >
+ <h3 className="font-semibold text-[var(--foreground)] truncate">
+ {mod.name}
+ </h3>
+ <p className="text-sm text-[var(--muted-foreground)] mt-1">
+ {total} knowledge point{total !== 1 ? "s" : ""}
+ </p>
+ {total > 0 && (
+ <div className="mt-3">
+ <div className="flex items-center justify-between text-xs text-[var(--muted-foreground)] mb-1">
+ <span>{mastered}/{total} mastered</span>
+ <span>{pct}%</span>
+ </div>
+ <div className="w-full h-1.5 rounded-full bg-[var(--muted)]">
+ <div
+ className="h-full rounded-full bg-[var(--primary)] transition-all"
+ style={{ width: `${pct}%` }}
+ />
+ </div>
+ </div>
+ )}
+ </div>
+ );
+ })}
+ </div>
+ )}
</div>
);
}
diff --git a/web/lib/learning-api.ts b/web/lib/learning-api.ts
new file mode 100644
index 000000000..648f480fc
--- /dev/null
+++ b/web/lib/learning-api.ts
@@ -0,0 +1,46 @@
+import { apiUrl, apiFetch } from "./api";
+
+export interface AnswerRequest {
+ question_id: string;
+ knowledge_point_id: string;
+ module_id?: string;
+ is_correct: boolean;
+ user_answer?: string;
+ error_type?: string;
+ self_attribution?: string;
+ mastery_estimate?: number;
+}
+
+export interface ModuleInit {
+ id: string;
+ name: string;
+ order: number;
+ pass_threshold?: number;
+ knowledge_points: { id: string; name: string; type: string; module_id: string }[];
+}
+
+export async function fetchProgress(bookId: string) {
+ const res = await apiFetch(apiUrl(`/api/v1/learning/progress/${bookId}`));
+ if (!res.ok) throw new Error(`Failed to fetch progress: ${res.status}`);
+ return res.json();
+}
+
+export async function submitAnswer(bookId: string, body: AnswerRequest) {
+ const res = await apiFetch(apiUrl(`/api/v1/learning/progress/${bookId}/answer`), {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify(body),
+ });
+ if (!res.ok) throw new Error(`Failed to submit answer: ${res.status}`);
+ return res.json();
+}
+
+export async function initModules(bookId: string, modules: ModuleInit[]) {
+ const res = await apiFetch(apiUrl(`/api/v1/learning/progress/${bookId}/init-modules`), {
+ method: "POST",
+ headers: { "Content-Type": "application/json" },
+ body: JSON.stringify({ modules }),
+ });
+ if (!res.ok) throw new Error(`Failed to init modules: ${res.status}`);
+ return res.json();
+}