Skip to content

Commit 46f19d8

Browse files
committed
refactor: extraction function
1 parent 1a7769c commit 46f19d8

File tree

1 file changed

+32
-40
lines changed

1 file changed

+32
-40
lines changed
+32-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div class="text-center mb-20 mt-10">
33
<div class="text-5xl mb-3 text-fuchsia-500 dark:text-gray-50">
4-
{{ word }}
4+
{{ courseStore.currentStatement?.english }}
55
<svg
66
class="w-7 h-7 inline-block ml-1 cursor-pointer"
77
viewBox="0 0 1024 1024"
@@ -15,10 +15,12 @@
1515
></path>
1616
</svg>
1717
</div>
18-
<div class="text-2xl text-slate-600">{{ soundmark }}</div>
18+
<div class="text-2xl text-slate-600">
19+
{{ courseStore.currentStatement?.soundmark }}
20+
</div>
1921
<button
2022
class="border-solid border-2 border-slate-400 bg-slate-100 dark:bg-fuchsia-500 rounded-lg mt-8 mb-11 indent-1 h-10 text-2xl pl-10 pr-10 hover:bg-slate-200"
21-
@click="handleToNextStatement"
23+
@click="goToNextQuestion"
2224
>
2325
next
2426
</button>
@@ -31,53 +33,29 @@ import { registerShortcut, cancelShortcut } from "~/utils/keyboardShortcuts";
3133
import { useMode } from "./game";
3234
import { useSummary } from "./summary";
3335
34-
const { showQuestion } = useMode();
35-
const { showSummary } = useSummary();
36-
const { sound } = useCurrentStatementEnglishSound();
37-
const coursesStore = useCourseStore();
38-
39-
const { soundmark, word } = useShowInfo();
40-
useShortcutToNext();
41-
autoPlayEnglishSound();
36+
const courseStore = useCourseStore();
37+
registerShortcutKeyForNextQuestion();
38+
const { handlePlaySound } = usePlayEnglishSound();
4239
43-
function useShowInfo() {
44-
const soundmark = ref("");
45-
const word = ref("");
46-
47-
watchEffect(() => {
48-
soundmark.value = coursesStore.currentStatement?.soundmark;
49-
word.value = coursesStore.currentStatement?.english;
50-
});
40+
function usePlayEnglishSound() {
41+
const { sound } = useCurrentStatementEnglishSound();
5142
52-
return {
53-
soundmark,
54-
word,
55-
};
56-
}
57-
58-
function autoPlayEnglishSound() {
5943
onMounted(() => {
6044
sound.play();
6145
});
62-
}
6346
64-
function handleToNextStatement() {
65-
if (coursesStore.isAllDone()) {
66-
showSummary();
67-
return;
47+
function handlePlaySound() {
48+
sound.play();
6849
}
6950
70-
coursesStore.toNextStatement();
71-
showQuestion();
72-
}
73-
74-
function handlePlaySound() {
75-
sound.play();
51+
return {
52+
handlePlaySound,
53+
};
7654
}
7755
78-
function useShortcutToNext() {
56+
function registerShortcutKeyForNextQuestion() {
7957
function handleKeydown() {
80-
handleToNextStatement();
58+
goToNextQuestion();
8159
}
8260
onMounted(() => {
8361
registerShortcut("enter", handleKeydown);
@@ -87,4 +65,18 @@ function useShortcutToNext() {
8765
cancelShortcut("enter", handleKeydown);
8866
});
8967
}
90-
</script>~/store/course-new
68+
69+
function goToNextQuestion() {
70+
const { showQuestion } = useMode();
71+
const { showSummary } = useSummary();
72+
73+
if (courseStore.isAllDone()) {
74+
showSummary();
75+
return;
76+
}
77+
78+
courseStore.toNextStatement();
79+
showQuestion();
80+
}
81+
</script>
82+
~/store/course-new

0 commit comments

Comments
 (0)