mirror of
https://github.com/RealKai42/qwerty-learner.git
synced 2026-04-04 22:09:04 +08:00
* feat: wrong words revision (#717) * fix: db error * feat: add shadon ui * feat: basic implement of review mode and new ui * feat: update default tab of dict detail * chore: add new line * chore: polish detail * feat: add dark mode --------- Co-authored-by: William Yu <52456186+WilliamYPY@users.noreply.github.com>
56 lines
2.5 KiB
TypeScript
56 lines
2.5 KiB
TypeScript
import Tooltip from '@/components/Tooltip'
|
|
import { currentChapterAtom, currentDictInfoAtom, isReviewModeAtom } from '@/store'
|
|
import range from '@/utils/range'
|
|
import { Listbox, Transition } from '@headlessui/react'
|
|
import { useAtom, useAtomValue } from 'jotai'
|
|
import { Fragment } from 'react'
|
|
import { NavLink } from 'react-router-dom'
|
|
import IconCheck from '~icons/tabler/check'
|
|
|
|
export const DictChapterButton = () => {
|
|
const currentDictInfo = useAtomValue(currentDictInfoAtom)
|
|
const [currentChapter, setCurrentChapter] = useAtom(currentChapterAtom)
|
|
const chapterCount = currentDictInfo.chapterCount
|
|
const isReviewMode = useAtomValue(isReviewModeAtom)
|
|
|
|
return (
|
|
<>
|
|
<Tooltip content="词典切换">
|
|
<NavLink
|
|
className="block rounded-lg px-3 py-1 text-lg transition-colors duration-300 ease-in-out hover:bg-indigo-400 hover:text-white focus:outline-none dark:text-white dark:text-opacity-60 dark:hover:text-opacity-100"
|
|
to="/gallery"
|
|
>
|
|
{currentDictInfo.name} {isReviewMode && '错题复习'}
|
|
</NavLink>
|
|
</Tooltip>
|
|
{!isReviewMode && (
|
|
<Tooltip content="章节切换">
|
|
<Listbox value={currentChapter} onChange={setCurrentChapter}>
|
|
<Listbox.Button className="rounded-lg px-3 py-1 text-lg transition-colors duration-300 ease-in-out hover:bg-indigo-400 hover:text-white focus:outline-none dark:text-white dark:text-opacity-60 dark:hover:text-opacity-100">
|
|
第 {currentChapter + 1} 章
|
|
</Listbox.Button>
|
|
<Transition as={Fragment} leave="transition ease-in duration-100" leaveFrom="opacity-100" leaveTo="opacity-0">
|
|
<Listbox.Options className="listbox-options z-10 w-32">
|
|
{range(0, chapterCount, 1).map((index) => (
|
|
<Listbox.Option key={index} value={index}>
|
|
{({ selected }) => (
|
|
<div className="group flex cursor-pointer items-center justify-between">
|
|
{selected ? (
|
|
<span className="listbox-options-icon">
|
|
<IconCheck className="focus:outline-none" />
|
|
</span>
|
|
) : null}
|
|
<span>第 {index + 1} 章</span>
|
|
</div>
|
|
)}
|
|
</Listbox.Option>
|
|
))}
|
|
</Listbox.Options>
|
|
</Transition>
|
|
</Listbox>
|
|
</Tooltip>
|
|
)}
|
|
</>
|
|
)
|
|
}
|