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>
35 lines
957 B
TypeScript
35 lines
957 B
TypeScript
import { db } from '@/utils/db'
|
|
import { useEffect, useState } from 'react'
|
|
|
|
export function useRevisionWordCount(dictID: string) {
|
|
const [wordCount, setWordCount] = useState<number>(0)
|
|
|
|
useEffect(() => {
|
|
const fetchWordCount = async () => {
|
|
const count = await getRevisionWordCount(dictID)
|
|
setWordCount(count)
|
|
}
|
|
|
|
if (dictID) {
|
|
fetchWordCount()
|
|
}
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [dictID])
|
|
|
|
return wordCount
|
|
}
|
|
|
|
async function getRevisionWordCount(dict: string): Promise<number> {
|
|
const wordCount = await db.wordRecords
|
|
.where('dict')
|
|
.equals(dict)
|
|
.and((wordRecord) => wordRecord.wrongCount > 0)
|
|
.toArray()
|
|
.then((wordRecords) => {
|
|
const res = new Map()
|
|
const reducedRecords = wordRecords.filter((item) => !res.has(item['word'] + item['dict']) && res.set(item['word'] + item['dict'], 1))
|
|
return reducedRecords.length
|
|
})
|
|
return wordCount
|
|
}
|