diff --git a/src/pages/Gallery/ChapterGroup.tsx b/src/pages/Gallery/ChapterGroup.tsx index ef1816d7..de976b4e 100644 --- a/src/pages/Gallery/ChapterGroup.tsx +++ b/src/pages/Gallery/ChapterGroup.tsx @@ -1,14 +1,19 @@ -import React from 'react' -import { range } from 'lodash' -import ChapterButton from './ChapterButton' -import { useAtom, useAtomValue } from 'jotai' -import { currentChapterAtom, currentDictInfoAtom } from '@/store' import { CHAPTER_LENGTH } from '@/constants' +import { currentChapterAtom, currentDictInfoAtom } from '@/store' +import { useAtom, useAtomValue } from 'jotai' +import { range } from 'lodash' +import React from 'react' +import { useUpdateEffect } from 'react-use' +import ChapterButton from './ChapterButton' const ChapterGroup: React.FC = ({ totalWords }) => { const [currentChapter, setCurrentChapter] = useAtom(currentChapterAtom) const currentDictInfo = useAtomValue(currentDictInfoAtom) + useUpdateEffect(() => { + setCurrentChapter(0) + }, [currentDictInfo, setCurrentChapter]) + return (
{range(currentDictInfo.chapterCount).map((index) =>