Skip to content

Commit

Permalink
refactor: extraction function
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Jan 25, 2024
1 parent 46f19d8 commit 7ce4079
Showing 1 changed file with 40 additions and 15 deletions.
55 changes: 40 additions & 15 deletions apps/client/components/main/Tips.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,49 @@
import { useMode } from "./game";
import { registerShortcut, cancelShortcut } from "~/utils/keyboardShortcuts";
const { showAnswer } = useMode();
const { sound } = useCurrentStatementEnglishSound();
function handleShowAnswer() {
showAnswer();
}
const { handlePlaySound } = usePlaySound()
const { handleShowAnswer } = useShowAnswer()
function usePlaySound() {
const { sound } = useCurrentStatementEnglishSound();
onMounted(() => {
registerShortcut("ctrl+p", handlePlaySound);
})
onUnmounted(() => {
cancelShortcut("ctrl+p", handlePlaySound);
});
function handlePlaySound() {
sound.play();
}
function handlePlaySound() {
sound.play();
return {
handlePlaySound
}
}
onMounted(() => {
registerShortcut("ctrl+p", handlePlaySound);
registerShortcut("ctrl+n", handleShowAnswer);
});
function useShowAnswer() {
const { showAnswer } = useMode();
onUnmounted(() => {
cancelShortcut("ctrl+p", handlePlaySound);
cancelShortcut("ctrl+n", handleShowAnswer);
});
onMounted(() => {
registerShortcut("ctrl+n", handleShowAnswer);
});
onUnmounted(() => {
cancelShortcut("ctrl+n", handleShowAnswer);
});
function handleShowAnswer() {
showAnswer();
}
return {
handleShowAnswer
}
}
</script>

0 comments on commit 7ce4079

Please sign in to comment.