|
1 | 1 | export type TranslationKey = keyof State; |
2 | 2 |
|
3 | 3 | type State = { |
4 | | - literature: { originals?: Literature; translations?: Literature }; |
5 | | - outlines: { originals?: Outlines; translations?: Outlines }; |
6 | | - songs: { originals?: Songs; translations?: Songs }; |
7 | | - tips: { originals?: Tips; translations?: Tips }; |
| 4 | + literature: { |
| 5 | + input?: Literature; |
| 6 | + originals?: Literature; |
| 7 | + translations?: Literature; |
| 8 | + }; |
| 9 | + outlines: { input?: Outlines; originals?: Outlines; translations?: Outlines }; |
| 10 | + songs: { input?: Songs; originals?: Songs; translations?: Songs }; |
| 11 | + tips: { input?: Tips; originals?: Tips; translations?: Tips }; |
8 | 12 | }; |
9 | 13 |
|
10 | 14 | export const useTranslationStore = defineStore("translation", { |
11 | 15 | actions: { |
12 | | - encodeOriginals() { |
13 | | - return { |
14 | | - literature: this.literature.originals |
15 | | - ? JSON.stringify(this.literature.originals, null, 2) |
16 | | - : undefined, |
17 | | - outlines: this.outlines.originals |
18 | | - ? JSON.stringify(this.outlines.originals, null, 2) |
19 | | - : undefined, |
20 | | - songs: this.songs.originals |
21 | | - ? JSON.stringify(this.songs.originals, null, 2) |
22 | | - : undefined, |
23 | | - tips: this.tips.originals |
24 | | - ? JSON.stringify(this.tips.originals, null, 2) |
25 | | - : undefined, |
26 | | - }; |
27 | | - }, |
28 | | - encodeTranslations() { |
29 | | - return { |
30 | | - literature: this.literature.translations |
31 | | - ? JSON.stringify(this.literature.translations, null, 2) |
32 | | - : undefined, |
33 | | - outlines: this.outlines.translations |
34 | | - ? JSON.stringify(this.outlines.translations, null, 2) |
35 | | - : undefined, |
36 | | - songs: this.songs.translations |
37 | | - ? JSON.stringify(this.songs.translations, null, 2) |
38 | | - : undefined, |
39 | | - tips: this.tips.translations |
40 | | - ? JSON.stringify(this.tips.translations, null, 2) |
41 | | - : undefined, |
42 | | - }; |
43 | | - }, |
44 | 16 | async fixInconsistentTips(heading: string, tips: { index: number }[]) { |
45 | 17 | tips.forEach((t) => { |
46 | 18 | if (!this.tips.translations?.[t.index]) return; |
47 | 19 | this.tips.translations![t.index]!.heading = heading; |
48 | 20 | }); |
49 | 21 | await new Promise((resolve) => setTimeout(resolve, 100)); |
50 | 22 | }, |
| 23 | + setInput({ |
| 24 | + literature, |
| 25 | + outlines, |
| 26 | + songs, |
| 27 | + tips, |
| 28 | + }: { |
| 29 | + literature?: Literature; |
| 30 | + outlines?: Outlines; |
| 31 | + songs?: Songs; |
| 32 | + tips?: Tips; |
| 33 | + }) { |
| 34 | + this.literature = { ...this.literature, input: literature }; |
| 35 | + this.outlines = { ...this.outlines, input: outlines }; |
| 36 | + this.songs = { ...this.songs, input: songs }; |
| 37 | + this.tips = { ...this.tips, input: tips }; |
| 38 | + }, |
51 | 39 | setOriginals({ |
52 | 40 | literature, |
53 | 41 | outlines, |
@@ -93,6 +81,19 @@ export const useTranslationStore = defineStore("translation", { |
93 | 81 | }, |
94 | 82 | }, |
95 | 83 | getters: { |
| 84 | + changedGroups(state) { |
| 85 | + const groups: (keyof State)[] = []; |
| 86 | + typedKeys(state).forEach((group) => { |
| 87 | + if ( |
| 88 | + state[group] && |
| 89 | + JSON.stringify(state[group].input) !== |
| 90 | + JSON.stringify(state[group].translations) |
| 91 | + ) { |
| 92 | + groups.push(group); |
| 93 | + } |
| 94 | + }); |
| 95 | + return groups; |
| 96 | + }, |
96 | 97 | inconsistentTips(state) { |
97 | 98 | if (!state.tips.originals?.length) return []; |
98 | 99 | const headings: Record<string, { index: number; translation: string }[]> = |
@@ -129,6 +130,14 @@ export const useTranslationStore = defineStore("translation", { |
129 | 130 | translations: [...new Set(tips.map((t) => t.translation))], |
130 | 131 | })); |
131 | 132 | }, |
| 133 | + input(state) { |
| 134 | + return { |
| 135 | + literature: state.literature.input, |
| 136 | + outlines: state.outlines.input, |
| 137 | + songs: state.songs.input, |
| 138 | + tips: state.tips.input, |
| 139 | + }; |
| 140 | + }, |
132 | 141 | missingLiterature(state) { |
133 | 142 | return ( |
134 | 143 | state.literature.originals?.filter( |
@@ -180,9 +189,17 @@ export const useTranslationStore = defineStore("translation", { |
180 | 189 | }, |
181 | 190 | persist: true, |
182 | 191 | state: (): State => ({ |
183 | | - literature: { originals: undefined, translations: undefined }, |
184 | | - outlines: { originals: undefined, translations: undefined }, |
185 | | - songs: { originals: undefined, translations: undefined }, |
186 | | - tips: { originals: undefined, translations: undefined }, |
| 192 | + literature: { |
| 193 | + input: undefined, |
| 194 | + originals: undefined, |
| 195 | + translations: undefined, |
| 196 | + }, |
| 197 | + outlines: { |
| 198 | + input: undefined, |
| 199 | + originals: undefined, |
| 200 | + translations: undefined, |
| 201 | + }, |
| 202 | + songs: { input: undefined, originals: undefined, translations: undefined }, |
| 203 | + tips: { input: undefined, originals: undefined, translations: undefined }, |
187 | 204 | }), |
188 | 205 | }); |
0 commit comments