mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-06 10:30:26 +08:00
feat(learner): add personal learning progress view
This commit is contained in:
20
web/app/(utility)/settings/progress/page.tsx
Normal file
20
web/app/(utility)/settings/progress/page.tsx
Normal file
@@ -0,0 +1,20 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import { listLearningRecords, type LearningRecord } from "@/lib/learning-records-api";
|
||||
|
||||
function label(record: LearningRecord): string {
|
||||
return String(record.title ?? record.material_title ?? record.material_id ?? "Learning activity");
|
||||
}
|
||||
|
||||
export default function LearningProgressPage() {
|
||||
const { t } = useTranslation();
|
||||
const [records, setRecords] = useState<LearningRecord[] | null>(null);
|
||||
const [error, setError] = useState(false);
|
||||
|
||||
useEffect(() => { void listLearningRecords().then(setRecords).catch(() => setError(true)); }, []);
|
||||
|
||||
return <main className="mx-auto max-w-3xl px-6 py-8"><h1 className="text-xl font-semibold">{t("Learning progress")}</h1><p className="mt-1 text-sm text-[var(--muted-foreground)]">{t("Review your own reading and learning activity.")}</p>{error ? <p className="mt-8 text-sm text-red-600">{t("Unable to load learning progress")}</p> : records === null ? <p className="mt-8 text-sm text-[var(--muted-foreground)]">{t("Loading progress")}</p> : records.length === 0 ? <p className="mt-8 text-sm text-[var(--muted-foreground)]">{t("No learning activity yet")}</p> : <ul className="mt-6 grid gap-3">{records.map((record, index) => <li key={String(record.event_id ?? record.id ?? index)} className="rounded-md border border-[var(--border)] p-4"><span className="font-medium">{label(record)}</span><span className="mt-1 block text-xs text-[var(--muted-foreground)]">{String(record.action ?? record.kind ?? "")}</span></li>)}</ul>}</main>;
|
||||
}
|
||||
@@ -24,6 +24,7 @@ import {
|
||||
ShieldCheck,
|
||||
SlidersHorizontal,
|
||||
Sparkles,
|
||||
ChartNoAxesCombined,
|
||||
UserRound,
|
||||
Wrench,
|
||||
type LucideIcon,
|
||||
@@ -471,6 +472,13 @@ export const SETTINGS_CATEGORIES: SettingsCategory[] = [
|
||||
href: "/settings#agents",
|
||||
children: AGENT_CHILDREN,
|
||||
},
|
||||
{
|
||||
key: "progress",
|
||||
label: { zh: "学习进度", en: "Learning progress" },
|
||||
blurb: { zh: "查看自己的阅读与学习记录。", en: "Review your reading and learning activity." },
|
||||
icon: ChartNoAxesCombined,
|
||||
href: "/settings/progress",
|
||||
},
|
||||
{
|
||||
key: "learner-profile",
|
||||
learnerOnly: true,
|
||||
|
||||
11
web/lib/learning-records-api.ts
Normal file
11
web/lib/learning-records-api.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { apiFetch, apiUrl } from "@/lib/api";
|
||||
|
||||
export interface LearningRecord {
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export async function listLearningRecords(): Promise<LearningRecord[]> {
|
||||
const response = await apiFetch(apiUrl("/api/v1/learning/records"));
|
||||
if (!response.ok) throw new Error("Failed to load learning progress");
|
||||
return response.json() as Promise<LearningRecord[]>;
|
||||
}
|
||||
Reference in New Issue
Block a user