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 && } + ); }