Skip to content

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

Align reading and progress UI with integrated navigation

Bingxi Zhao (Frank)5726328d32e3
diff --git a/web/app/(utility)/settings/progress/page.tsx b/web/app/(utility)/settings/progress/page.tsx
index 260c3cd23..b605de5fb 100644
--- a/web/app/(utility)/settings/progress/page.tsx
+++ b/web/app/(utility)/settings/progress/page.tsx
@@ -7,6 +7,7 @@ import {
listLearningRecords,
type LearningRecords,
} from "@/lib/learning-records-api";
+import { listReadingLibraryMaterials } from "@/lib/reading-workspace-api";
function percent(value: number): number {
return Math.round(value * 100);
@@ -15,9 +16,21 @@ function percent(value: number): number {
export default function LearningProgressPage() {
const { t } = useTranslation();
const [records, setRecords] = useState<LearningRecords | null>(null);
+ const [materialTitles, setMaterialTitles] = useState<Record<string, string>>({});
const [error, setError] = useState(false);
- useEffect(() => { void listLearningRecords().then(setRecords).catch(() => setError(true)); }, []);
+ useEffect(() => {
+ void listLearningRecords().then(setRecords).catch(() => setError(true));
+ void listReadingLibraryMaterials()
+ .then(({ materials }) =>
+ setMaterialTitles(
+ Object.fromEntries(materials.map((material) => [material.material_id, material.title])),
+ ),
+ )
+ .catch(() => {
+ // Progress remains usable if the library catalogue is unavailable.
+ });
+ }, []);
const progress = records?.progress ?? [];
const activities = records?.activities ?? [];
@@ -43,7 +56,7 @@ export default function LearningProgressPage() {
<strong className="mt-1 block text-xl">{progress.length}</strong>
</div>
<div className="rounded-md border border-[var(--border)] p-4">
- <span className="block text-xs text-[var(--muted-foreground)]">{t("Learning actions")}</span>
+ <span className="block text-xs text-[var(--muted-foreground)]">{t("Recent learning actions")}</span>
<strong className="mt-1 block text-xl">{activities.length}</strong>
</div>
</div>
@@ -56,7 +69,7 @@ export default function LearningProgressPage() {
{progress.map((record) => (
<li key={record.material_id} className="rounded-md border border-[var(--border)] p-4">
<div className="flex items-center justify-between gap-3">
- <span className="min-w-0 truncate font-medium">{record.material_id}</span>
+ <span className="min-w-0 truncate font-medium">{materialTitles[record.material_id] || record.material_id}</span>
<span className="text-xs text-[var(--muted-foreground)]">
{percent(record.furthest_percentage)}%
</span>
@@ -80,14 +93,14 @@ export default function LearningProgressPage() {
)}
</section>
<section className="mt-6">
- <h2 className="text-sm font-semibold">{t("Learning actions")}</h2>
+ <h2 className="text-sm font-semibold">{t("Recent learning actions")}</h2>
{activities.length === 0 ? (
<p className="mt-3 text-sm text-[var(--muted-foreground)]">{t("No learning actions yet")}</p>
) : (
<ul className="mt-3 grid gap-3">
{activities.map((record) => (
<li key={record.activity_id} className="rounded-md border border-[var(--border)] p-4">
- <span className="font-medium">{record.material_id}</span>
+ <span className="font-medium">{materialTitles[record.material_id] || record.material_id}</span>
<span className="mt-1 block text-xs text-[var(--muted-foreground)]">
{record.action} · {record.extension_id} · {t("Locator")} {record.locator}
</span>
diff --git a/web/components/notebook/NotebookRecordRow.tsx b/web/components/notebook/NotebookRecordRow.tsx
index 7df9d1cf3..5189f89d7 100644
--- a/web/components/notebook/NotebookRecordRow.tsx
+++ b/web/components/notebook/NotebookRecordRow.tsx
@@ -14,7 +14,7 @@ import {
} from "lucide-react";
import { useTranslation } from "react-i18next";
import { ConfirmDialog } from "@/components/ui/ConfirmDialog";
-import Tooltip from "@/components/common/Tooltip";
+import Tooltip from "@/shared/ui/Tooltip";
import NotebookRecordActions from "@/components/notebook/NotebookRecordActions";
import { notify } from "@/lib/notifications";
import type { NotebookRecordItem, NotebookSummary } from "@/lib/notebook-api";
diff --git a/web/components/reading/ReaderPane.tsx b/web/components/reading/ReaderPane.tsx
index ef9eb608e..88aab5cba 100644
--- a/web/components/reading/ReaderPane.tsx
+++ b/web/components/reading/ReaderPane.tsx
@@ -2,7 +2,7 @@
import { browserStorage } from "@/shared/storage";
-import { useCallback, useEffect, useMemo, useRef, useState } from "react";
+import { useCallback, useEffect, useMemo, useRef, useState, type RefObject } from "react";
import {
ArrowLeft,
ArrowRight,
@@ -211,9 +211,38 @@ export function ReaderPane({
>(undefined);
const [showHistory, setShowHistory] = useState(false);
const [showMoreTools, setShowMoreTools] = useState(false);
+ const moreToolsButtonRef = useRef<HTMLButtonElement>(null);
+ const moreToolsMenuRef = useRef<HTMLDivElement>(null);
const [unavailableMaterials, setUnavailableMaterials] = useState<Set<string>>(
new Set(),
);
+
+ useEffect(() => {
+ if (!showMoreTools) return;
+ moreToolsMenuRef.current?.querySelector<HTMLElement>("[role^='menuitem']")?.focus();
+ const onKeyDown = (event: KeyboardEvent) => {
+ if (event.key !== "Escape") return;
+ event.preventDefault();
+ event.stopPropagation();
+ setShowMoreTools(false);
+ moreToolsButtonRef.current?.focus();
+ };
+ const onPointerDown = (event: PointerEvent) => {
+ const target = event.target as Node;
+ if (
+ !moreToolsMenuRef.current?.contains(target) &&
+ !moreToolsButtonRef.current?.contains(target)
+ ) {
+ setShowMoreTools(false);
+ }
+ };
+ document.addEventListener("keydown", onKeyDown);
+ document.addEventListener("pointerdown", onPointerDown);
+ return () => {
+ document.removeEventListener("keydown", onKeyDown);
+ document.removeEventListener("pointerdown", onPointerDown);
+ };
+ }, [showMoreTools]);
const navigationNonceRef = useRef(0);
const pendingNavigationRef = useRef<{
mode: "push" | "replay";
@@ -853,6 +882,7 @@ export function ReaderPane({
label={t("More")}
active={showMoreTools}
menu
+ buttonRef={moreToolsButtonRef}
onClick={() => {
setShowMoreTools(!showMoreTools);
if (!showMoreTools) setShowHistory(false);
@@ -864,6 +894,7 @@ export function ReaderPane({
{showMoreTools && material && (
<div
+ ref={moreToolsMenuRef}
role="menu"
aria-label={t("More")}
className="absolute top-11 right-2 z-40 w-56 rounded-xl border border-[var(--border)] bg-[var(--background)] p-1.5 shadow-xl md:hidden"
@@ -1101,6 +1132,7 @@ function HeaderButton({
spinning,
disabled,
menu = false,
+ buttonRef,
className = "",
}: {
icon: typeof FileText;
@@ -1110,10 +1142,12 @@ function HeaderButton({
spinning?: boolean;
disabled?: boolean;
menu?: boolean;
+ buttonRef?: RefObject<HTMLButtonElement | null>;
className?: string;
}) {
return (
<button
+ ref={buttonRef}
type="button"
title={label}
aria-label={label}
diff --git a/web/components/reading/workspace/ReadingWorkspace.tsx b/web/components/reading/workspace/ReadingWorkspace.tsx
index dbe140c26..928323bcb 100644
--- a/web/components/reading/workspace/ReadingWorkspace.tsx
+++ b/web/components/reading/workspace/ReadingWorkspace.tsx
@@ -3,7 +3,6 @@
import { scopedUrl } from "@/lib/workspace-scope";
import { READING_HOME, readingSessionIdFromPath } from "@/lib/learning-routes";
-
import { browserStorage } from "@/shared/storage";
import Link from "next/link";
@@ -343,14 +342,13 @@ export function ReadingWorkspacePage() {
// At desktop width the companion column is drag-resizable, so its track is
// driven by JS state rather than the Tailwind classes below — a narrow
// hairline "handle" track sits between the reader and the companion only
- // in this case. Every other combination (companion closed, or too narrow
- // for a three-column layout) is exactly what the className already says.
+ // in this case. The navigator has no grid track when it is closed.
const showResizeHandle = isDesktopWide && companionOpen;
const gridStyle: React.CSSProperties | undefined = showResizeHandle
? {
gridTemplateColumns: navigatorOpen
? `minmax(184px,230px) minmax(360px,1fr) 5px ${companionWidth}px`
- : `minmax(184px,230px) minmax(360px,1fr) 5px ${companionWidth}px`,
+ : `minmax(360px,1fr) 5px ${companionWidth}px`,
}
: undefined;
@@ -489,10 +487,10 @@ export function ReadingWorkspacePage() {
companionOpen
? navigatorOpen
? "grid-cols-[minmax(0,1fr)] lg:grid-cols-[minmax(184px,230px)_minmax(360px,1fr)] xl:grid-cols-[minmax(184px,230px)_minmax(360px,1fr)_5px_minmax(330px,420px)]"
- : "grid-cols-[minmax(0,1fr)] lg:grid-cols-[minmax(184px,230px)_minmax(360px,1fr)] xl:grid-cols-[minmax(184px,230px)_minmax(360px,1fr)_minmax(330px,420px)]"
+ : "grid-cols-[minmax(0,1fr)] xl:grid-cols-[minmax(360px,1fr)_5px_minmax(330px,420px)]"
: navigatorOpen
- ? "grid-cols-[minmax(0,1fr)]"
- : "grid-cols-[minmax(0,1fr)] lg:grid-cols-[minmax(184px,230px)_minmax(0,1fr)]"
+ ? "grid-cols-[minmax(0,1fr)] lg:grid-cols-[minmax(184px,230px)_minmax(0,1fr)]"
+ : "grid-cols-[minmax(0,1fr)]"
}`}
style={gridStyle}
>
diff --git a/web/features/settings/navigation/settings-pages.ts b/web/features/settings/navigation/settings-pages.ts
index 5d75e454b..1248ef26d 100644
--- a/web/features/settings/navigation/settings-pages.ts
+++ b/web/features/settings/navigation/settings-pages.ts
@@ -14,7 +14,7 @@ export const SETTINGS_PAGE_GROUPS: { label: Lang; keys: string[] }[] = [
{ label: { en: 'Personal', zh: '个人' }, keys: ['general', 'workspace', 'data-migration', 'appearance', 'usage'] },
{
label: { en: 'Learning & conversation', zh: '学习与对话' },
- keys: ['starters', 'attachments', 'video-learning', 'learner-profile', 'guardian', 'memory'],
+ keys: ['starters', 'attachments', 'video-learning', 'learner-profile', 'progress', 'guardian', 'memory'],
},
{
label: { en: 'Models & services', zh: '模型与服务' },
@@ -60,6 +60,14 @@ export function settingsPageFamily(key: string): string[] {
}
const extraPages: SettingsLeaf[] = [
+ {
+ key: 'progress',
+ label: { en: 'Learning progress', zh: '学习进度' },
+ blurb: { en: 'Reading progress and recent learning actions', zh: '阅读进度与近期学习操作' },
+ icon: BarChart3,
+ href: '/settings/progress',
+ tile: '',
+ },
{
key: 'data-migration',
label: { en: 'Data migration', zh: '数据迁移' },
diff --git a/web/locales/en/app.json b/web/locales/en/app.json
index 720dfb560..0d324b89b 100644
--- a/web/locales/en/app.json
+++ b/web/locales/en/app.json
@@ -5036,6 +5036,7 @@
"Loading progress": "Loading progress",
"No learning activity yet": "No learning activity yet",
"Learning actions": "Learning actions",
+ "Recent learning actions": "Recent learning actions",
"Reading progress": "Reading progress",
"No reading progress yet": "No reading progress yet",
"Furthest reading progress": "Furthest reading progress",
diff --git a/web/locales/zh/app.json b/web/locales/zh/app.json
index 0adccbacf..7eab9ca01 100644
--- a/web/locales/zh/app.json
+++ b/web/locales/zh/app.json
@@ -5036,6 +5036,7 @@
"Loading progress": "正在加载进度",
"No learning activity yet": "还没有学习活动",
"Learning actions": "学习操作",
+ "Recent learning actions": "近期学习操作",
"Reading progress": "阅读进度",
"No reading progress yet": "还没有阅读进度",
"Furthest reading progress": "最远阅读进度",
diff --git a/web/tests/learning-records-api.test.ts b/web/tests/learning-records-api.test.ts
index 62d58b421..3daed8c26 100644
--- a/web/tests/learning-records-api.test.ts
+++ b/web/tests/learning-records-api.test.ts
@@ -21,7 +21,9 @@ test("learning records request the account reading summary", async () => {
try {
const records = await listLearningRecords();
- assert.equal(requestedUrl, "/api/mastery-paths/reading/records");
+ const requested = new URL(requestedUrl, "http://localhost");
+ assert.equal(requested.pathname, "/api/mastery-paths/reading/records");
+ assert.ok(requested.searchParams.has("dt_workspace"));
assert.equal(requestedInit?.method, undefined);
assert.deepEqual(requestedInit?.credentials, "include");
assert.deepEqual(records, { progress: [], activities: [] });
diff --git a/web/tests/reading-toolbar-selection.spec.tsx b/web/tests/reading-toolbar-selection.spec.tsx
index 5518d4adf..3eccb77aa 100644
--- a/web/tests/reading-toolbar-selection.spec.tsx
+++ b/web/tests/reading-toolbar-selection.spec.tsx
@@ -180,10 +180,15 @@ describe("reading toolbar with a live selection", () => {
name: /Auto-jump on/,
});
expect(autoJump.getAttribute("aria-checked")).toBe("true");
+ expect(autoJump).toHaveFocus();
await user.click(autoJump);
expect(
within(menu).getByRole("menuitemcheckbox", { name: /Auto-jump off/ }),
).toHaveAttribute("aria-checked", "false");
+
+ await user.keyboard("{Escape}");
+ expect(screen.queryByRole("menu", { name: "More" })).not.toBeInTheDocument();
+ expect(more).toHaveFocus();
});
});
diff --git a/web/tests/sidebar-prefetch.spec.tsx b/web/tests/sidebar-prefetch.spec.tsx
index 3db12880a..68b66c4fa 100644
--- a/web/tests/sidebar-prefetch.spec.tsx
+++ b/web/tests/sidebar-prefetch.spec.tsx
@@ -1,4 +1,4 @@
-import { fireEvent, render, screen } from "@testing-library/react";
+import { render } from "@testing-library/react";
import { expect, it, vi } from "vitest";
import type { ComponentProps, ReactNode } from "react";
@@ -48,6 +48,9 @@ vi.mock("@/components/layout/AppShell", () => ({
vi.mock("@/hooks/useDevice", () => ({
useDevice: () => ({ isMobile: false }),
}));
+vi.mock("@/hooks/useChatWorkspaces", () => ({
+ useChatWorkspaces: () => ({ workspaces: [], error: "" }),
+}));
vi.mock("@/lib/app-update", () => ({
fetchAppUpdateStatus: vi.fn(() => Promise.resolve({ current_version: "1.0" })),
subscribeAppUpdateStatus: vi.fn(() => () => undefined),
@@ -63,26 +66,16 @@ function expectSidebarLinksToDisablePrefetch() {
}
}
-it("disables viewport prefetch for expanded sidebar navigation", async () => {
- localStorage.setItem(
- "deeptutor.sidebar.navLayout",
- JSON.stringify({ order: [], collapsed: ["/books"] }),
- );
+it("disables viewport prefetch for expanded sidebar navigation", () => {
fixture.collapsed = false;
render(<SidebarShell />);
- fireEvent.click(await screen.findByRole("button", { name: /more/i }));
expectSidebarLinksToDisablePrefetch();
});
-it("disables viewport prefetch for collapsed sidebar overflow navigation", async () => {
- localStorage.setItem(
- "deeptutor.sidebar.navLayout",
- JSON.stringify({ order: [], collapsed: ["/books"] }),
- );
+it("disables viewport prefetch for collapsed sidebar navigation", () => {
fixture.collapsed = true;
render(<SidebarShell />);
- fireEvent.click(await screen.findByRole("button", { name: /more/i }));
expectSidebarLinksToDisablePrefetch();
});