Skip to content

Commit

Permalink
feat: show tips when 3 times wrong (cuixueshe#440)
Browse files Browse the repository at this point in the history
* fix: add dropdown background

* feat: show tips when 3 times wrong

* fix: hide AnswerTip after correctAnswer

* refactor: extraction function

---------

Co-authored-by: cuixiaorui <[email protected]>
  • Loading branch information
nullcache and cuixiaorui authored Mar 30, 2024
1 parent 8d8684f commit bc9f02b
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions apps/client/components/main/Question/Question.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const {
getInputCursorPosition,
inputChangedCallback,
});
const { hiddenAnswerTip } = useAnswerTip();
const { showAnswerTip, hiddenAnswerTip } = useAnswerTip();
watch(
() => inputValue.value,
Expand Down Expand Up @@ -175,18 +175,36 @@ function inputWidth(word: string) {
return width;
}
function answerError() {
let wrongTimes = 0;
function handleAnswerError() {
playErrorSound();
wrongTimes++;
if (wrongTimes >= 3) {
showAnswerTip();
}
}
return {
handleAnswerError,
};
}
const { handleAnswerError } = answerError();
function handleKeydown(e: KeyboardEvent) {
if (e.code === "Enter") {
e.stopPropagation();
submitAnswer(
() => {
playRightSound(); // 正确提示
showAnswer();
hiddenAnswerTip();
},
playErrorSound // 错误提示
handleAnswerError // 错误提示
);
hiddenAnswerTip();
return;
}
Expand All @@ -197,9 +215,7 @@ function handleKeydown(e: KeyboardEvent) {
playRightSound(); // 正确提示
showAnswer();
},
errorCallback: () => {
playErrorSound();
},
errorCallback: handleAnswerError, // 错误提示
},
});
}
Expand Down

0 comments on commit bc9f02b

Please sign in to comment.