|
7 | 7 | /> |
8 | 8 |
|
9 | 9 | <UPageBody> |
10 | | - <template v-if="inconsistentHeadings.length"> |
| 10 | + <template v-if="translationStore.inconsistentTips.length"> |
11 | 11 | <UAlert |
12 | | - v-for="h in inconsistentHeadings" |
| 12 | + v-for="h in translationStore.inconsistentTips" |
13 | 13 | :key="h.heading" |
14 | 14 | variant="soft" |
15 | 15 | color="warning" |
|
19 | 19 | h.translations.map((t) => ({ |
20 | 20 | label: t, |
21 | 21 | onClick: () => { |
22 | | - fixInconsistentHeading(t, h.tips); |
| 22 | + fixInconsistentTips(t, h.tips); |
23 | 23 | }, |
24 | 24 | })) |
25 | 25 | " |
|
35 | 35 | <template v-else> |
36 | 36 | <TipForm |
37 | 37 | v-for="(tip, i) in translationStore.originals.tips" |
| 38 | + :id="`tip-${i}`" |
38 | 39 | :key="i" |
39 | 40 | :index="i" |
40 | 41 | :tip="tip" |
|
46 | 47 | <script setup lang="ts"> |
47 | 48 | const translationStore = useTranslationStore(); |
48 | 49 |
|
49 | | -const inconsistentHeadings = computed(() => { |
50 | | - if (!translationStore.originals.tips?.length) return []; |
51 | | - const headings: Record<string, { index: number; translation: string }[]> = {}; |
52 | | -
|
53 | | - translationStore.originals.tips.forEach((tip, index) => { |
54 | | - if (headings[tip.heading]) { |
55 | | - headings[tip.heading]!.push({ |
56 | | - index, |
57 | | - translation: translationStore.translations.tips?.[index]?.heading ?? "", |
58 | | - }); |
59 | | - } else { |
60 | | - headings[tip.heading] = [ |
61 | | - { |
62 | | - index, |
63 | | - translation: |
64 | | - translationStore.translations.tips?.[index]?.heading ?? "", |
65 | | - }, |
66 | | - ]; |
67 | | - } |
68 | | - }); |
69 | | - return Object.entries(headings) |
70 | | - .filter( |
71 | | - ([, tips]) => |
72 | | - tips.length > 1 && |
73 | | - tips.some((t) => t.translation !== tips[0]?.translation), |
74 | | - ) |
75 | | - .map(([heading, tips]) => ({ |
76 | | - heading, |
77 | | - tips: tips, |
78 | | - translations: [...new Set(tips.map((t) => t.translation))], |
79 | | - })); |
80 | | -}); |
81 | | -
|
82 | 50 | const loading = ref(false); |
83 | 51 |
|
84 | | -const fixInconsistentHeading = async ( |
| 52 | +const fixInconsistentTips = async ( |
85 | 53 | heading: string, |
86 | 54 | tips: { index: number }[], |
87 | 55 | ) => { |
88 | 56 | loading.value = true; |
89 | | - tips.forEach((t) => { |
90 | | - translationStore.translations.tips![t.index]!.heading = heading; |
91 | | - }); |
92 | | - await new Promise((resolve) => setTimeout(resolve, 100)); |
| 57 | + await translationStore.fixInconsistentTips(heading, tips); |
93 | 58 | loading.value = false; |
94 | 59 | }; |
95 | 60 |
|
|
0 commit comments