|
15 | 15 | import { useMode } from "./game";
|
16 | 16 | import { registerShortcut, cancelShortcut } from "~/utils/keyboardShortcuts";
|
17 | 17 |
|
18 |
| -const { showAnswer } = useMode(); |
19 |
| -const { sound } = useCurrentStatementEnglishSound(); |
20 | 18 |
|
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 | + } |
24 | 37 |
|
25 |
| -function handlePlaySound() { |
26 |
| - sound.play(); |
| 38 | + return { |
| 39 | + handlePlaySound |
| 40 | + } |
27 | 41 | }
|
28 | 42 |
|
29 |
| -onMounted(() => { |
30 |
| - registerShortcut("ctrl+p", handlePlaySound); |
31 |
| - registerShortcut("ctrl+n", handleShowAnswer); |
32 |
| -}); |
| 43 | +function useShowAnswer() { |
| 44 | + const { showAnswer } = useMode(); |
33 | 45 |
|
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 | +} |
38 | 63 | </script>
|
0 commit comments