Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,31 @@ file-by-file review surface with inline comments. The UI also supports full-file
image diffs, syntax themes, typography settings, continuous chapter review, and keyboard
navigation.

The chapter progress strip shows which chapters are reviewed, visited, or not yet started.
Click a segment to open that chapter; in Scroll view, it scrolls to the chapter in place.
Visiting a chapter does not mark it reviewed. Review progress follows the existing **Mark as
viewed** controls: mark a chapter, or mark every file in it, to count it as reviewed.
Visited state resets when you reload or switch runs; review marks remain saved.

Under **Display → Chapter progress**, choose **Compact** (the default), **With titles**, or **Hidden**.
Compact shows chapter numbers, with the full title and status on hover or keyboard focus.
With titles adds truncated chapter titles on wider screens. Hidden removes the entire progress
strip, including its counters and navigation. The display preference is saved between sessions;
showing the strip again preserves your review progress.

<details>
<summary>Chapter progress layouts</summary>

Compact:

![Compact chapter progress](assets/chapter-progress-compact.png)

With titles:

![Chapter progress with titles](assets/chapter-progress-with-titles.png)

</details>

### Options

| Flag | Description |
Expand Down
Binary file added assets/chapter-progress-compact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/chapter-progress-with-titles.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 2 additions & 3 deletions packages/web/src/app/runs.$runId.chapters.$chapterNumber.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createFileRoute } from "@tanstack/react-router";
import { parseChapterNumber } from "@/lib/chapter-number";
import { ChapterDetailPage } from "@/routes/chapter-detail-page";

export const Route = createFileRoute("/runs/$runId/chapters/$chapterNumber")({
Expand All @@ -7,7 +8,5 @@ export const Route = createFileRoute("/runs/$runId/chapters/$chapterNumber")({

function ChapterRoute() {
const { runId, chapterNumber } = Route.useParams();
const parsed = Number.parseInt(chapterNumber, 10);
const valid = Number.isFinite(parsed) && parsed > 0 ? parsed : null;
return <ChapterDetailPage runId={runId} chapterNumber={valid} />;
return <ChapterDetailPage runId={runId} chapterNumber={parseChapterNumber(chapterNumber)} />;
}
41 changes: 35 additions & 6 deletions packages/web/src/app/runs.$runId.chapters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import {
useRouterState,
} from "@tanstack/react-router";
import { useState } from "react";
import { parseChapterNumber } from "@/lib/chapter-number";
import { useContinuousChapterReader } from "@/lib/chapter-view-state-context";
import { CHAPTER_VIEW_MODE, useChapterSettings } from "@/lib/use-chapter-settings";
import { ContinuousChaptersPage } from "@/routes/continuous-chapters-page";

Expand Down Expand Up @@ -33,11 +35,8 @@ function ChaptersLayout() {
select: (state) => state.matches.some((match) => match.routeId === CHAPTER_DETAIL_ROUTE_ID),
});

// Same integer semantics as the chapter detail route, so paged and
// continuous deep links agree on what `/chapters/1e2` or `/chapters/1.5` mean.
const parsed =
params.chapterNumber === undefined ? Number.NaN : Number.parseInt(params.chapterNumber, 10);
const deepLinkedChapterNumber = Number.isFinite(parsed) && parsed > 0 ? parsed : undefined;
const deepLinkedChapterNumber =
params.chapterNumber === undefined ? null : parseChapterNumber(params.chapterNumber);
const [initialChapterNumber, setInitialChapterNumber] = useState(deepLinkedChapterNumber);
// Render-time state sync ("adjusting state during render"): remember the
// latest deep-linked chapter so it survives the normalizing redirect below,
Expand All @@ -51,7 +50,26 @@ function ChaptersLayout() {
const [stateOwner, setStateOwner] = useState(runId);
if (stateOwner !== runId) {
setStateOwner(runId);
setInitialChapterNumber(isOnChapterDetailRoute ? deepLinkedChapterNumber : undefined);
setInitialChapterNumber(isOnChapterDetailRoute ? deepLinkedChapterNumber : null);
}

// Switching Scroll → Page while this layout is mounted resumes the reader's
// chapter. The reader is still mounted (and published) during the render
// that observes the switch, so capture its position now; a bare /chapters
// link opened in Page mode never sees a switch and goes to the overview.
const continuousReader = useContinuousChapterReader();
const [renderedViewMode, setRenderedViewMode] = useState(chapterViewMode);
const [pagedResumeChapterNumber, setPagedResumeChapterNumber] = useState<number | null>(null);
if (renderedViewMode !== chapterViewMode) {
setRenderedViewMode(chapterViewMode);
setPagedResumeChapterNumber(
chapterViewMode === CHAPTER_VIEW_MODE.PAGED && continuousReader
? continuousReader.activeChapterNumber
: null,
);
}
if (isOnChapterDetailRoute && pagedResumeChapterNumber !== null) {
setPagedResumeChapterNumber(null);
}

if (chapterViewMode === CHAPTER_VIEW_MODE.CONTINUOUS) {
Expand All @@ -61,6 +79,17 @@ function ChaptersLayout() {
return <ContinuousChaptersPage runId={runId} initialChapterNumber={initialChapterNumber} />;
}

if (pagedResumeChapterNumber !== null && !isOnChapterDetailRoute) {
return (
<Navigate
to="/runs/$runId/chapters/$chapterNumber"
params={{ runId, chapterNumber: String(pagedResumeChapterNumber) }}
replace
resetScroll={false}
/>
);
}

// In paged mode a bare /chapters URL always matches the index child route,
// which redirects to the run overview — the Outlet covers both children.
return <Outlet />;
Expand Down
124 changes: 124 additions & 0 deletions packages/web/src/components/chapter/chapter-progress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { Check, Circle, CircleDot } from "lucide-react";
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
import {
buildChapterProgress,
CHAPTER_PROGRESS_LABELS,
CHAPTER_PROGRESS_STATUS,
type ChapterProgressStatus,
type ChapterProgressViewState,
type ProgressChapter,
} from "@/lib/chapter-progress";
import { CHAPTER_PROGRESS_MODE, useChapterSettings } from "@/lib/use-chapter-settings";
import { cn } from "@/lib/utils";

const STATUS_STYLES = {
[CHAPTER_PROGRESS_STATUS.NOT_STARTED]: { bar: "bg-muted", icon: Circle },
[CHAPTER_PROGRESS_STATUS.VISITED]: { bar: "bg-muted-foreground/50", icon: CircleDot },
[CHAPTER_PROGRESS_STATUS.REVIEWED]: { bar: "bg-green-600 dark:bg-green-500", icon: Check },
} as const satisfies Record<ChapterProgressStatus, { bar: string; icon: typeof Circle }>;
// Without saved review marks a chapter's status is unknown, not "not started".
const UNKNOWN_STATUS_STYLE = { bar: "bg-muted", icon: Circle } as const;

interface ChapterProgressProps {
chapters: readonly ProgressChapter[];
viewState: ChapterProgressViewState;
activeChapterNumber: number | null;
/** Null while chapters can't be navigated to yet; the strip renders disabled. */
onNavigateToChapter: ((chapterNumber: number) => void) | null;
isLoading: boolean;
error: unknown;
}

export function ChapterProgress({
chapters,
viewState,
activeChapterNumber,
onNavigateToChapter,
isLoading,
error,
}: ChapterProgressProps) {
const { chapterProgressMode } = useChapterSettings();
if (chapterProgressMode === CHAPTER_PROGRESS_MODE.HIDDEN) return null;
const { items, reviewedCount } = buildChapterProgress(chapters, viewState);
if (items.length === 0) return null;
const activeItem = items.find(({ chapter }) => chapter.order + 1 === activeChapterNumber);
const withTitles = chapterProgressMode === CHAPTER_PROGRESS_MODE.WITH_TITLES;
const isReviewStatusKnown = !error && !isLoading;

return (
<section aria-label="Chapter progress" className="w-full min-w-0 py-2">
<div className="mb-1 flex flex-wrap items-center justify-between gap-x-4 gap-y-1 text-xs">
<span aria-live="polite" aria-atomic="true" className="tabular-nums">
{error
? "Review progress unavailable"
: isLoading
? "Loading review progress…"
: `Reviewed ${reviewedCount} of ${items.length}`}
</span>
{activeItem && (
<span className="text-muted-foreground tabular-nums">
Chapter {activeItem.chapter.order + 1} of {items.length}
</span>
)}
</div>
<nav aria-label="Chapter navigation" className="-m-1 flex gap-2 overflow-x-auto p-1">
{items.map(({ chapter, status }) => {
const chapterNumber = chapter.order + 1;
const isActive = chapterNumber === activeChapterNumber;
const { bar, icon: StatusIcon } = isReviewStatusKnown
? STATUS_STYLES[status]
: UNKNOWN_STATUS_STYLE;
const statusLabel = isReviewStatusKnown
? CHAPTER_PROGRESS_LABELS[status]
: "Review status unavailable";
return (
<Tooltip key={chapter.id} delayDuration={200}>
<TooltipTrigger asChild>
<button
type="button"
disabled={onNavigateToChapter === null}
onClick={
onNavigateToChapter ? () => onNavigateToChapter(chapterNumber) : undefined
}
aria-current={isActive ? "step" : undefined}
aria-label={`Chapter ${chapterNumber}: ${chapter.title}. ${statusLabel}`}
className="group/progress min-w-10 max-w-full flex-1 basis-0 cursor-pointer rounded-sm disabled:cursor-default py-2 text-left outline-offset-2 focus-visible:outline-2 focus-visible:outline-ring [@media(pointer:coarse)]:min-h-11"
>
<span
aria-hidden="true"
className={cn(
"mb-1.5 block h-1.5 rounded-full transition-opacity group-hover/progress:opacity-80",
bar,
)}
/>
<span className="flex items-center gap-1 text-xs">
<StatusIcon aria-hidden="true" className="size-3 shrink-0" />
<span className="tabular-nums">{chapterNumber}</span>
{isActive && (
<span
aria-hidden="true"
className="size-1.5 shrink-0 rounded-full bg-primary"
/>
)}
{withTitles && (
<span className="hidden truncate text-muted-foreground sm:inline">
{chapter.title}
</span>
)}
</span>
</button>
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p className="font-medium">{chapter.title}</p>
<p className="mt-1 text-muted-foreground">
Chapter {chapterNumber} · {statusLabel}
{isActive && " · Current"}
</p>
</TooltipContent>
</Tooltip>
);
})}
</nav>
</section>
);
}
60 changes: 60 additions & 0 deletions packages/web/src/components/chapter/run-chapter-progress.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { useNavigate, useParams } from "@tanstack/react-router";
import { useEffect } from "react";
import { parseChapterNumber } from "@/lib/chapter-number";
import type { ProgressChapter } from "@/lib/chapter-progress";
import { useChapterVisits, useContinuousChapterReader } from "@/lib/chapter-view-state-context";
import { CHAPTER_VIEW_MODE, useChapterSettings } from "@/lib/use-chapter-settings";
import type { UseViewStateDataResult } from "@/lib/use-view-state";
import { ChapterProgress } from "./chapter-progress";

interface RunChapterProgressProps {
runId: string;
chapters: readonly ProgressChapter[];
viewState: UseViewStateDataResult;
}

export function RunChapterProgress({ runId, chapters, viewState }: RunChapterProgressProps) {
const { visitedChapterIds, markChapterVisited } = useChapterVisits();
const { chapterViewMode } = useChapterSettings();
const continuousReader = useContinuousChapterReader();
const params = useParams({ strict: false });
const navigate = useNavigate();

const isContinuous = chapterViewMode === CHAPTER_VIEW_MODE.CONTINUOUS;
const activeChapterNumber = isContinuous
? (continuousReader?.activeChapterNumber ?? null)
: params.chapterNumber === undefined
? null
: parseChapterNumber(params.chapterNumber);
const activeExternalId = chapters.find(
(chapter) => chapter.order + 1 === activeChapterNumber,
)?.externalId;

useEffect(() => {
if (activeExternalId !== undefined) markChapterVisited(activeExternalId);
}, [activeExternalId, markChapterVisited]);

// Continuous mode steers the mounted stream in place; routing to
// /chapters/N there would remount the whole reader. Until the stream has
// loaded there is nothing to steer, so the strip is not navigable yet.
const navigateToChapter = isContinuous
? (continuousReader?.navigateToChapter ?? null)
: (chapterNumber: number) => {
void navigate({
to: "/runs/$runId/chapters/$chapterNumber",
params: { runId, chapterNumber: String(chapterNumber) },
resetScroll: false,
});
};

return (
<ChapterProgress
chapters={chapters}
viewState={{ reviewedChapterIds: viewState.chapterIdSet, visitedChapterIds }}
activeChapterNumber={activeChapterNumber}
onNavigateToChapter={navigateToChapter}
isLoading={viewState.isLoading}
error={viewState.error}
/>
);
}
Loading