Skip to content

Commit

Permalink
fix: re-timer the game pause while the user is typing
Browse files Browse the repository at this point in the history
  • Loading branch information
cuixiaorui committed Aug 16, 2024
1 parent 5385777 commit bac8c9e
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions apps/client/composables/main/useGamePause.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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;
Expand All @@ -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() {
Expand Down

0 comments on commit bac8c9e

Please sign in to comment.