fix: reset selected chapter after dict change (#401)

This commit is contained in:
Lv777
2023-04-17 17:04:34 +08:00
committed by GitHub
parent 059767dbb5
commit 78bb1b31e7

View File

@@ -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<ChapterGroupProps> = ({ totalWords }) => {
const [currentChapter, setCurrentChapter] = useAtom(currentChapterAtom)
const currentDictInfo = useAtomValue(currentDictInfoAtom)
useUpdateEffect(() => {
setCurrentChapter(0)
}, [currentDictInfo, setCurrentChapter])
return (
<main className="mr-4 grid gap-4 sm:grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4">
{range(currentDictInfo.chapterCount).map((index) =>