forked from RealKai42/qwerty-learner
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
122 lines (97 loc) · 3.78 KB
/
index.ts
File metadata and controls
122 lines (97 loc) · 3.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import atomForConfig from './atomForConfig'
import { reviewInfoAtom } from './reviewInfoAtom'
import { DISMISS_START_CARD_DATE_KEY, defaultFontSizeConfig } from '@/constants'
import { idDictionaryMap } from '@/resources/dictionary'
import { correctSoundResources, keySoundResources, wrongSoundResources } from '@/resources/soundResource'
import type {
Dictionary,
InfoPanelState,
LoopWordTimesOption,
PhoneticType,
PronunciationType,
WordDictationOpenBy,
WordDictationType,
} from '@/typings'
import type { ReviewRecord } from '@/utils/db/record'
import { atom } from 'jotai'
import { atomWithStorage } from 'jotai/utils'
export const currentDictIdAtom = atomWithStorage('currentDict', 'cet4')
export const currentDictInfoAtom = atom<Dictionary>((get) => {
const id = get(currentDictIdAtom)
let dict = idDictionaryMap[id]
// 如果 dict 不存在,则返回 cet4. Typing 中会检查 DictId 是否存在,如果不存在则会重置为 cet4
if (!dict) {
dict = idDictionaryMap.cet4
}
return dict
})
export const currentChapterAtom = atomWithStorage('currentChapter', 0)
export const loopWordConfigAtom = atomForConfig<{ times: LoopWordTimesOption }>('loopWordConfig', {
times: 1,
})
export const keySoundsConfigAtom = atomForConfig('keySoundsConfig', {
isOpen: true,
isOpenClickSound: true,
volume: 1,
resource: keySoundResources[0],
})
export const hintSoundsConfigAtom = atomForConfig('hintSoundsConfig', {
isOpen: true,
volume: 1,
isOpenWrongSound: true,
isOpenCorrectSound: true,
wrongResource: wrongSoundResources[0],
correctResource: correctSoundResources[0],
})
export const pronunciationConfigAtom = atomForConfig('pronunciation', {
isOpen: true,
volume: 1,
type: 'us' as PronunciationType,
name: '美音',
isLoop: false,
isTransRead: false,
transVolume: 1,
rate: 1,
})
export const fontSizeConfigAtom = atomForConfig('fontsize', defaultFontSizeConfig)
export const pronunciationIsOpenAtom = atom((get) => get(pronunciationConfigAtom).isOpen)
export const pronunciationIsTransReadAtom = atom((get) => get(pronunciationConfigAtom).isTransRead)
export const randomConfigAtom = atomForConfig('randomConfig', {
isOpen: false,
})
export const isShowPrevAndNextWordAtom = atomWithStorage('isShowPrevAndNextWord', true)
export const isIgnoreCaseAtom = atomWithStorage('isIgnoreCase', true)
export const isShowAnswerOnHoverAtom = atomWithStorage('isShowAnswerOnHover', true)
export const isTextSelectableAtom = atomWithStorage('isTextSelectable', false)
export const reviewModeInfoAtom = reviewInfoAtom({
isReviewMode: false,
reviewRecord: undefined as ReviewRecord | undefined,
})
export const isReviewModeAtom = atom((get) => get(reviewModeInfoAtom).isReviewMode)
export const phoneticConfigAtom = atomForConfig('phoneticConfig', {
isOpen: true,
type: 'us' as PhoneticType,
})
export const isOpenDarkModeAtom = atomWithStorage('isOpenDarkModeAtom', window.matchMedia('(prefers-color-scheme: dark)').matches)
export const isShowSkipAtom = atom(false)
export const isInDevModeAtom = atom(false)
export const infoPanelStateAtom = atom<InfoPanelState>({
donate: false,
vsc: false,
community: false,
redBook: false,
})
export const wordDictationConfigAtom = atomForConfig('wordDictationConfig', {
isOpen: false,
type: 'hideAll' as WordDictationType,
openBy: 'auto' as WordDictationOpenBy,
})
// 例句练习功能开关 (默认开启)
export const exampleSentenceConfigAtom = atomForConfig('exampleSentenceConfig', {
isOpen: true,
})
export const dismissStartCardDateAtom = atomWithStorage<Date | null>(DISMISS_START_CARD_DATE_KEY, null)
// Enhanced version promotion popup state
export const hasSeenEnhancedPromotionAtom = atomWithStorage('hasSeenEnhancedPromotion', false)
// for dev test
// dismissStartCardDateAtom = atom<Date | null>(new Date())