From 78bb1b31e75b279cf00215002f1aa1790bddf543 Mon Sep 17 00:00:00 2001 From: Lv777 <39904184+OBQun@users.noreply.github.com> Date: Mon, 17 Apr 2023 17:04:34 +0800 Subject: [PATCH] fix: reset selected chapter after dict change (#401) --- src/pages/Gallery/ChapterGroup.tsx | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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) =>