From 6cf7e3aa191f7a565a8f9646b30ad408c562a9ba Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sun, 1 Mar 2026 23:51:56 +0800 Subject: [PATCH] Add support to scroll to current chapter in volume list --- src/manage/qd/BookChapter.tsx | 2 +- src/manage/qd/VolumesList.module.css | 23 ++++++++++++ src/manage/qd/VolumesList.tsx | 53 ++++++++++++++++++++++++---- 3 files changed, 70 insertions(+), 8 deletions(-) diff --git a/src/manage/qd/BookChapter.tsx b/src/manage/qd/BookChapter.tsx index af311ce..fa214bf 100644 --- a/src/manage/qd/BookChapter.tsx +++ b/src/manage/qd/BookChapter.tsx @@ -132,7 +132,7 @@ export default function BookChapter() { {bookStatus.chapterShowMode != ChapterShowMode.All && listErr && 重试} />} {bookStatus.chapterShowMode != ChapterShowMode.All && !bookStatus.chapterLists && !listErr && } - {vols.length > 0 && } + {vols.length > 0 && } {err && { + if (!current) return null; + return volumes.find(v => v.chapters.some(ch => ch.id === current))?.id ?? null; + }, [volumes, current]); + + const [activeKeys, setActiveKeys] = useState([]); + + const scrollToCurrent = () => { + if (!current || !currentVolumeId) return; + + if (!activeKeys.includes(currentVolumeId)) { + setActiveKeys(prev => [...prev, currentVolumeId]); + function checkChapterInView() { + const el = document.getElementById(`chapter-${current}`); + if (el && el.offsetParent) { + // Wait for the collapse animation to finish before scrolling + setTimeout(() => { + el.scrollIntoView({ behavior: 'smooth', block: 'start' }); + }, 300); + } else { + setTimeout(checkChapterInView, 100); + } + } + setTimeout(checkChapterInView, 20); + } else { + const el = document.getElementById(`chapter-${current}`); + if (el) { + el.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } + } + }; + const items = useMemo(() => volumes.map(v => { const children = v.chapters.map(chapter => ( - + {chapter.name} {chapter.isSaved && } @@ -53,8 +87,13 @@ export default function VolumesList({ volumes, bookId, oneLine }: VolumesListPro } }), [volumes, bookId, oneLine]); - return (); + return (
+
setActiveKeys(keys as string[])} + items={items} + />
+ {current && } +
); }