Skip to content

Commit 7ce4079

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

File tree

1 file changed

+40
-15
lines changed

1 file changed

+40
-15
lines changed

apps/client/components/main/Tips.vue

+40-15
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,49 @@
1515
import { useMode } from "./game";
1616
import { registerShortcut, cancelShortcut } from "~/utils/keyboardShortcuts";
1717
18-
const { showAnswer } = useMode();
19-
const { sound } = useCurrentStatementEnglishSound();
2018
21-
function handleShowAnswer() {
22-
showAnswer();
23-
}
19+
const { handlePlaySound } = usePlaySound()
20+
const { handleShowAnswer } = useShowAnswer()
21+
22+
23+
function usePlaySound() {
24+
const { sound } = useCurrentStatementEnglishSound();
25+
26+
onMounted(() => {
27+
registerShortcut("ctrl+p", handlePlaySound);
28+
})
29+
30+
onUnmounted(() => {
31+
cancelShortcut("ctrl+p", handlePlaySound);
32+
});
33+
34+
function handlePlaySound() {
35+
sound.play();
36+
}
2437
25-
function handlePlaySound() {
26-
sound.play();
38+
return {
39+
handlePlaySound
40+
}
2741
}
2842
29-
onMounted(() => {
30-
registerShortcut("ctrl+p", handlePlaySound);
31-
registerShortcut("ctrl+n", handleShowAnswer);
32-
});
43+
function useShowAnswer() {
44+
const { showAnswer } = useMode();
3345
34-
onUnmounted(() => {
35-
cancelShortcut("ctrl+p", handlePlaySound);
36-
cancelShortcut("ctrl+n", handleShowAnswer);
37-
});
46+
onMounted(() => {
47+
registerShortcut("ctrl+n", handleShowAnswer);
48+
});
49+
50+
onUnmounted(() => {
51+
cancelShortcut("ctrl+n", handleShowAnswer);
52+
});
53+
54+
function handleShowAnswer() {
55+
showAnswer();
56+
}
57+
58+
return {
59+
handleShowAnswer
60+
}
61+
62+
}
3863
</script>

0 commit comments

Comments
 (0)