fix: keep mastery board horizontal scrolling accessible

This commit is contained in:
我也有友人账
2026-11-03 14:48:17 -08:00
parent f7aed0744c
commit f6cbb25e72
2 changed files with 127 additions and 76 deletions

View File

@@ -598,7 +598,7 @@ export default function MasteryTopicPage() {
)}
</section>
<div className="mt-6 grid min-h-0 flex-1 items-start gap-7 lg:grid-cols-[minmax(0,1fr)_340px] lg:items-stretch">
<div className="mt-6 grid min-h-0 flex-1 grid-cols-1 items-start gap-7 lg:grid-cols-[minmax(0,1fr)_340px] lg:items-stretch">
{needsRouteRepair ? (
// A goal starts without an outline: the first session is where the
// tutor asks about the learner and designs one with them. Writing
@@ -637,7 +637,7 @@ export default function MasteryTopicPage() {
</button>
</section>
) : (
<div className="flex min-h-0 flex-col gap-5 lg:h-full">
<div className="flex min-h-0 min-w-0 flex-col gap-5 lg:h-full">
{/* The three things a mastery goal owns — outline, review plan,
sessions — are named the same way and sit at the same level,
so the page reads as one goal's assets rather than a map with
@@ -681,7 +681,13 @@ export default function MasteryTopicPage() {
</div>
{/* The outline is the tall thing on this page, so it is the one
that scrolls. Everything else keeps its place. */}
<div className="min-h-0 lg:min-h-[260px] lg:flex-1 lg:overflow-y-auto lg:pr-1">
<div
className={`min-h-0 min-w-0 lg:min-h-[260px] lg:flex-1 ${
topicView === "board"
? "flex flex-col"
: "lg:overflow-y-auto lg:pr-1"
}`}
>
{topicView === "outline" ? (
<ModuleOutline
topic={topic}
@@ -748,7 +754,7 @@ export default function MasteryTopicPage() {
/>
</div>
)}
<div className="flex min-h-0 flex-col gap-5 lg:h-full">
<div className="flex min-h-0 min-w-0 flex-col gap-5 lg:h-full">
<LearnerProfileCard profile={topic.learner_profile} />
<SessionCamp
pathId={pathId}

View File

@@ -1,6 +1,6 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { useCallback, useEffect, useRef, useState } from "react";
import { useTranslation } from "react-i18next";
import {
BookOpen,
@@ -53,6 +53,26 @@ export function LearningBoard({
onStartTutoring: (knowledgePointName: string) => void;
}) {
const { t } = useTranslation();
const scrollport = useRef<HTMLDivElement>(null);
const columns = useRef<HTMLDivElement>(null);
const [scrollRange, setScrollRange] = useState(0);
const [scrollPosition, setScrollPosition] = useState(0);
useEffect(() => {
const viewport = scrollport.current;
const content = columns.current;
if (!viewport || !content) return;
const measure = () => {
setScrollRange(Math.max(0, viewport.scrollWidth - viewport.clientWidth));
setScrollPosition(Math.max(0, viewport.scrollLeft));
};
const observer = new ResizeObserver(measure);
observer.observe(viewport);
observer.observe(content);
measure();
return () => observer.disconnect();
}, []);
const [openId, setOpenId] = useState<string | null>(null);
const [report, setReport] = useState<ObjectiveReport | null>(null);
const [reportError, setReportError] = useState(false);
@@ -81,83 +101,108 @@ export function LearningBoard({
}, []);
return (
<div className="flex gap-4 overflow-x-auto pb-2">
{modules.map((module) => (
<div
key={module.id}
className="flex w-64 shrink-0 flex-col gap-2 rounded-lg border border-[var(--border)] bg-[var(--muted)]/40 p-3"
>
<div className="flex items-center justify-between gap-2">
<h3 className="min-w-0 truncate text-[13px] font-semibold text-[var(--foreground)]">
{module.name}
</h3>
<span className="shrink-0 text-[11px] tabular-nums text-[var(--muted-foreground)]">
{module.mastered}/{module.total}
</span>
</div>
<div className="flex min-h-0 min-w-0 flex-col gap-2 lg:flex-1">
<div
ref={scrollport}
onScroll={(event) => setScrollPosition(Math.max(0, event.currentTarget.scrollLeft))}
tabIndex={0}
role="region"
aria-label={t("Board")}
className="max-h-[65vh] min-h-0 min-w-0 overflow-auto pb-2 [scrollbar-color:var(--muted-foreground)_var(--muted)] lg:max-h-none"
>
<div ref={columns} className="flex w-max min-w-full items-start gap-4">
{modules.map((module) => (
<div
key={module.id}
className="flex w-64 shrink-0 flex-col gap-2 rounded-lg border border-[var(--border)] bg-[var(--muted)]/40 p-3"
>
<div className="flex items-center justify-between gap-2">
<h3 className="min-w-0 truncate text-[13px] font-semibold text-[var(--foreground)]">
{module.name}
</h3>
<span className="shrink-0 text-[11px] tabular-nums text-[var(--muted-foreground)]">
{module.mastered}/{module.total}
</span>
</div>
{module.cards.map((card) => {
const open = openId === card.id;
return (
<div key={card.id}>
<button
type="button"
onClick={() => toggle(card.id)}
aria-expanded={open}
className={`w-full rounded-lg border bg-[var(--card)] p-3 text-left transition hover:bg-[var(--muted)]/60 ${STATUS_BORDER[card.status]}`}
>
<div className="flex items-start justify-between gap-2">
<span className="text-[13px] leading-snug text-[var(--foreground)]">
{card.name}
</span>
{STATUS_ICON[card.status]}
</div>
<div className="mt-2 flex items-center justify-between gap-2 text-[11px]">
<span className="rounded-full bg-[var(--muted)] px-1.5 py-0.5 text-[var(--muted-foreground)]">
{knowledgeTypeLabel(card.type, t)}
</span>
<span className="shrink-0 tabular-nums text-[var(--muted-foreground)]">
{Math.round(card.mastery_level * 100)}%
</span>
</div>
{card.next_review_at && (
<div className="mt-1.5 flex items-center gap-1 text-[11px] text-[var(--muted-foreground)]">
<BookOpen className="h-3 w-3" />
{t("Review")} {formatRelative(card.next_review_at, zh)}
</div>
)}
</button>
{module.cards.map((card) => {
const open = openId === card.id;
return (
<div key={card.id}>
<button
type="button"
onClick={() => toggle(card.id)}
aria-expanded={open}
className={`w-full rounded-lg border bg-[var(--card)] p-3 text-left transition hover:bg-[var(--muted)]/60 ${STATUS_BORDER[card.status]}`}
>
<div className="flex items-start justify-between gap-2">
<span className="text-[13px] leading-snug text-[var(--foreground)]">
{card.name}
</span>
{STATUS_ICON[card.status]}
</div>
<div className="mt-2 flex items-center justify-between gap-2 text-[11px]">
<span className="rounded-full bg-[var(--muted)] px-1.5 py-0.5 text-[var(--muted-foreground)]">
{knowledgeTypeLabel(card.type, t)}
</span>
<span className="shrink-0 tabular-nums text-[var(--muted-foreground)]">
{Math.round(card.mastery_level * 100)}%
</span>
</div>
{card.next_review_at && (
<div className="mt-1.5 flex items-center gap-1 text-[11px] text-[var(--muted-foreground)]">
<BookOpen className="h-3 w-3" />
{t("Review")} {formatRelative(card.next_review_at, zh)}
</div>
)}
</button>
{open && (
<div className="mt-2 rounded-lg border border-[var(--border)] bg-[var(--card)] p-3">
{loaded && report ? (
<>
<ObjectiveDetail report={report} zh={zh} />
<button
type="button"
onClick={() => onStartTutoring(card.name)}
className="mt-2 flex h-8 w-full items-center justify-center gap-1.5 rounded-lg bg-[var(--primary)] px-3 text-xs font-medium text-[var(--primary-foreground)] transition hover:opacity-90"
>
<MessageSquare className="h-3.5 w-3.5" />
{t("Start tutoring")}
</button>
</>
) : reportError ? (
<p className="py-3 text-center text-xs text-[var(--muted-foreground)]">
{t("Evidence could not be loaded")}
</p>
) : (
<div className="flex items-center justify-center py-3 text-[var(--muted-foreground)]">
<Loader2 className="h-4 w-4 animate-spin" />
{open && (
<div className="mt-2 rounded-lg border border-[var(--border)] bg-[var(--card)] p-3">
{loaded && report ? (
<>
<ObjectiveDetail report={report} zh={zh} />
<button
type="button"
onClick={() => onStartTutoring(card.name)}
className="mt-2 flex h-8 w-full items-center justify-center gap-1.5 rounded-lg bg-[var(--primary)] px-3 text-xs font-medium text-[var(--primary-foreground)] transition hover:opacity-90"
>
<MessageSquare className="h-3.5 w-3.5" />
{t("Start tutoring")}
</button>
</>
) : reportError ? (
<p className="py-3 text-center text-xs text-[var(--muted-foreground)]">
{t("Evidence could not be loaded")}
</p>
) : (
<div className="flex items-center justify-center py-3 text-[var(--muted-foreground)]">
<Loader2 className="h-4 w-4 animate-spin" />
</div>
)}
</div>
)}
</div>
)}
</div>
);
})}
);
})}
</div>
))}
</div>
))}
</div>
{scrollRange > 0 && (
<input
type="range"
min={0}
max={scrollRange}
value={Math.min(scrollPosition, scrollRange)}
aria-label={zh ? "看板横向滚动" : "Scroll board horizontally"}
className="w-full shrink-0 cursor-ew-resize accent-[var(--primary)]"
onChange={(event) => {
const viewport = scrollport.current;
if (viewport) viewport.scrollLeft = event.currentTarget.valueAsNumber;
}}
/>
)}
</div>
);
}