diff --git a/web/app/(workspace)/learning/[bookId]/page.tsx b/web/app/(workspace)/learning/[bookId]/page.tsx index befce85c1..95ffe8568 100644 --- a/web/app/(workspace)/learning/[bookId]/page.tsx +++ b/web/app/(workspace)/learning/[bookId]/page.tsx @@ -44,6 +44,7 @@ export default function LearningBookPage() { const currentStageRef = useRef(""); const [connecting, setConnecting] = useState(true); const [error, setError] = useState(null); + const [toast, setToast] = useState(""); const wsRef = useRef(null); interface ModuleData { @@ -95,7 +96,7 @@ export default function LearningBookPage() { } catch { /* ignore parse errors */ } }; - ws.onerror = () => setError("Connection error"); + ws.onerror = () => setError(t("guidedLearning.connectionError")); ws.onclose = () => setConnecting(true); }, [params.bookId]); @@ -129,12 +130,19 @@ export default function LearningBookPage() { } } else if (evt.type === "error") { setError(evt.content); + setToast(t("guidedLearning.stageFailed")); setStages(prev => prev.map(s => s.stage === currentStageRef.current ? { ...s, status: "error" } : s )); } }; + useEffect(() => { + if (!toast) return; + const timer = setTimeout(() => setToast(""), 3500); + return () => clearTimeout(timer); + }, [toast]); + // Fetch learning progress for module tree useEffect(() => { fetchProgress(); @@ -146,13 +154,18 @@ export default function LearningBookPage() { }, [connect]); return ( -
+
+ {toast && ( +
+ {toast} +
+ )} {/* Sidebar */}
{/* Module tree */} {modules.length > 0 && (
-

Modules

+

{t("guidedLearning.modules")}

- Learning Stages + {t("guidedLearning.stages")}

{connecting && } {stages.map((s) => ( @@ -190,7 +203,7 @@ export default function LearningBookPage() {
) : (
- {connecting ? : "Ready to start learning"} + {connecting ? : t("guidedLearning.ready")}
)}
diff --git a/web/app/(workspace)/learning/page.tsx b/web/app/(workspace)/learning/page.tsx index 5d4b48c2a..7cb0b417f 100644 --- a/web/app/(workspace)/learning/page.tsx +++ b/web/app/(workspace)/learning/page.tsx @@ -3,6 +3,7 @@ import { useEffect, useState, useCallback } from "react"; import { useRouter } from "next/navigation"; import { BookOpen, Loader2, Play } from "lucide-react"; +import { useTranslation } from "react-i18next"; import { fetchProgress } from "@/lib/learning-api"; interface ModuleSummary { @@ -15,9 +16,17 @@ interface ModuleSummary { export default function LearningPage() { const router = useRouter(); + const { t } = useTranslation(); const [modules, setModules] = useState([]); const [masteryLevels, setMasteryLevels] = useState>({}); const [loading, setLoading] = useState(true); + const [toast, setToast] = useState(""); + + useEffect(() => { + if (!toast) return; + const timer = setTimeout(() => setToast(""), 3500); + return () => clearTimeout(timer); + }, [toast]); const loadProgress = useCallback(async () => { try { @@ -25,11 +34,11 @@ export default function LearningPage() { setModules(data.modules ?? []); setMasteryLevels(data.mastery_levels ?? {}); } catch { - // No progress yet — show empty state + setToast(t("guidedLearning.connectionError")); } finally { setLoading(false); } - }, []); + }, [t]); useEffect(() => { loadProgress(); @@ -50,13 +59,18 @@ export default function LearningPage() { return (
+ {toast && ( +
+ {toast} +
+ )}
-

Learning Modules

+

{t("guidedLearning.title")}

{modules.length > 0 - ? `${modules.length} module${modules.length > 1 ? "s" : ""} available` - : "Start a learning session to generate modules"} + ? `${modules.length} ${t("guidedLearning.modules")}` + : t("guidedLearning.description")}

{modules.length === 0 ? (
-

No modules yet

+

{t("guidedLearning.noModules")}

- Click "Start Learning" to begin — modules will be created automatically. + {t("guidedLearning.description")}

) : ( @@ -94,12 +108,12 @@ export default function LearningPage() { {mod.name}

- {total} knowledge point{total !== 1 ? "s" : ""} + {t("guidedLearning.moduleProgress", { count: total })}

{total > 0 && (
- {mastered}/{total} mastered + {t("guidedLearning.masteredProgress", { mastered, total })} {pct}%
diff --git a/web/locales/en/app.json b/web/locales/en/app.json index 6567ee00c..d2ab3d60f 100644 --- a/web/locales/en/app.json +++ b/web/locales/en/app.json @@ -1605,5 +1605,18 @@ "Co-Writer tooltip": "AI-powered document editor.", "Book tooltip": "Create AI-powered books.", "Knowledge tooltip": "Manage learning personas.", - "Space tooltip": "Your personal learning library." + "Space tooltip": "Your personal learning library.", + "guidedLearning.title": "Guided Learning", + "guidedLearning.description": "Framework v1.8.2 — structured mastery-based learning", + "guidedLearning.noModules": "No modules yet", + "guidedLearning.startLearning": "Start Learning", + "guidedLearning.modules": "Modules", + "guidedLearning.knowledgePoints": "knowledge points", + "guidedLearning.mastered": "mastered", + "guidedLearning.stages": "Learning Stages", + "guidedLearning.ready": "Ready to start learning", + "guidedLearning.connectionError": "Connection error", + "guidedLearning.stageFailed": "Stage execution failed. Progress saved, will retry this stage.", + "guidedLearning.moduleProgress": "{{count}} knowledge point(s)", + "guidedLearning.masteredProgress": "{{mastered}}/{{total}} mastered" } diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json index df1d71db9..051067b46 100644 --- a/web/locales/zh/app.json +++ b/web/locales/zh/app.json @@ -1605,5 +1605,18 @@ "Co-Writer tooltip": "AI 驱动的协作文档编辑器。", "Book tooltip": "生成交互式 AI 书籍。", "Knowledge tooltip": "管理文档与教学人设。", - "Space tooltip": "你的个人学习空间。" + "Space tooltip": "你的个人学习空间。", + "guidedLearning.title": "引导式学习", + "guidedLearning.description": "框架 v1.8.2 — 结构化掌握式学习", + "guidedLearning.noModules": "暂无模块", + "guidedLearning.startLearning": "开始学习", + "guidedLearning.modules": "学习模块", + "guidedLearning.knowledgePoints": "个知识点", + "guidedLearning.mastered": "已掌握", + "guidedLearning.stages": "学习阶段", + "guidedLearning.ready": "准备开始学习", + "guidedLearning.connectionError": "连接错误", + "guidedLearning.stageFailed": "阶段执行失败。进度已保存,将重试该阶段。", + "guidedLearning.moduleProgress": "{{count}} 个知识点", + "guidedLearning.masteredProgress": "已掌握 {{mastered}}/{{total}}" }