From b65ebd1d51ad3d366ef762cae750f1aa37893d84 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 11 Jan 2026 05:16:57 +0000 Subject: [PATCH] feat(ui): add table of contents for chapter navigation Added table of contents modal for documents with multiple chapters: New Features: - TableOfContents component with modal dialog - List icon button in chapter navigation bar - Click any chapter to jump directly to it - Current chapter highlighted in the list - Scrollable list for books with many chapters - Clean modal UI with transitions Benefits: - Quick navigation for large documents with many chapters - Better UX for series/textbooks with 10+ chapters - No need to click Previous/Next repeatedly - Shows all chapter titles at a glance Technical Details: - Uses Headless UI Dialog for accessibility - Integrates with existing goToChapter function - Matches existing design system and styling - Added to HTMLViewer chapter navigation bar --- src/components/HTMLViewer.tsx | 23 ++++-- src/components/TableOfContents.tsx | 122 +++++++++++++++++++++++++++++ 2 files changed, 138 insertions(+), 7 deletions(-) create mode 100644 src/components/TableOfContents.tsx diff --git a/src/components/HTMLViewer.tsx b/src/components/HTMLViewer.tsx index 7d96236..e1d00c9 100644 --- a/src/components/HTMLViewer.tsx +++ b/src/components/HTMLViewer.tsx @@ -5,6 +5,7 @@ import ReactMarkdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { useHTML } from '@/contexts/HTMLContext'; import { DocumentSkeleton } from '@/components/DocumentSkeleton'; +import { TableOfContents } from '@/components/TableOfContents'; interface HTMLViewerProps { className?: string; @@ -19,6 +20,7 @@ export function HTMLViewer({ className = '' }: HTMLViewerProps) { totalChapters, goToNextChapter, goToPreviousChapter, + goToChapter, } = useHTML(); const containerRef = useRef(null); @@ -48,13 +50,20 @@ export function HTMLViewer({ className = '' }: HTMLViewerProps) { Previous -
- - {currentChapter?.title || `Chapter ${currentChapterIndex + 1}`} - - - ({currentChapterIndex + 1} of {totalChapters}) - +
+
+ + {currentChapter?.title || `Chapter ${currentChapterIndex + 1}`} + + + ({currentChapterIndex + 1} of {totalChapters}) + +
+
+ + {/* Table of Contents Modal */} + + setIsOpen(false)} + > + +
+ + +
+
+ + + + Table of Contents + + + {/* Chapters List */} +
+
+ {chapters.map((chapter, index) => ( + + ))} +
+
+ + {/* Close Button */} +
+ +
+
+
+
+
+
+
+ + ); +}