From bac8c9ee974ddba663fd933ac0446a8dd4dd7fc4 Mon Sep 17 00:00:00 2001 From: cuixiaorui Date: Fri, 16 Aug 2024 17:42:44 +0800 Subject: [PATCH] fix: re-timer the game pause while the user is typing --- apps/client/composables/main/useGamePause.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/apps/client/composables/main/useGamePause.ts b/apps/client/composables/main/useGamePause.ts index dad7fc84..6e765fce 100644 --- a/apps/client/composables/main/useGamePause.ts +++ b/apps/client/composables/main/useGamePause.ts @@ -1,6 +1,7 @@ +import { debounce } from "lodash-es"; import { ref, watch } from "vue"; -import { useQuestionInput } from "~/components/main/QuestionInput/questionInputHelper"; +import { useWrapperQuestionInput } from "~/components/main/QuestionInput/useWrapperQuestionInput"; import { useCourseStore } from "~/store/course"; import { useGameStore } from "~/store/game"; @@ -16,6 +17,7 @@ const showGamePauseModal = ref(false); export function useGamePause() { const courseStore = useCourseStore(); const gameStore = useGameStore(); + const { inputValue } = useWrapperQuestionInput(); function resumeGame() { showGamePauseModal.value = false; @@ -42,15 +44,26 @@ export function useGamePause() { } function enableAutoPauseCheck() { + const debouncedResetInactivityTimer = debounce(resetInactivityTimer, 500); + + // 用户切换题目的时候重置计时器 watch( () => courseStore.statementIndex, () => { - resetInactivityTimer(); + debouncedResetInactivityTimer(); }, { immediate: true, }, ); + + // 用户输入内容的时候重置计时器 + watch( + () => inputValue.value, + () => { + debouncedResetInactivityTimer(); + }, + ); } function disableAutoPauseCheck() {