Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add next button #413

Merged
merged 3 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions apps/client/components/main/Tips.vue
Original file line number Diff line number Diff line change
@@ -1,20 +1,39 @@
<template>
<div class="absolute left-0 right-0 bottom-[16vh] flex flex-col items-center">
<div class="absolute left-0 right-0 bottom-[12vh] flex flex-col items-center">
<div class="w-[210px] mb-4">
<button class="tip-btn" @click="playSound">
<button
class="tip-btn"
@click="playSound"
>
⌃ {{ shortcutKeys.sound }}
</button>
<span class="ml-2">play sound</span>
</div>
<div class="w-[210px] mb-4">
<button class="tip-btn" @click="toggleGameMode">
<button
class="tip-btn"
@click="toggleGameMode"
>
⌃ {{ shortcutKeys.answer }}
</button>
<span class="ml-2">{{ toggleTipText }}</span>
</div>

<div class="w-[210px] mb-4">
<button
class="tip-btn mr-1"
@click="goToNextQuestion"
>
⌃ {{ shortcutKeys.skip }}
</button>
<span class="ml-2">{{ "skip" }}</span>
</div>
<div class="w-[210px]">
<button class="tip-btn" @click="toggleGameMode">Space</button>
<button
class="tip-btn"
@click="toggleGameMode"
>
Space
</button>
<span class="ml-2">fix incorrect word</span>
</div>
</div>
Expand All @@ -26,11 +45,16 @@ import { useCurrentStatementEnglishSound } from "~/composables/main/englishSound
import { useGameMode } from "~/composables/main/game";
import { useSummary } from "~/composables/main/summary";
import { useShortcutKeyMode } from "~/composables/user/shortcutKey";
import { useCourseStore } from "~/store/course";
import { cancelShortcut, registerShortcut } from "~/utils/keyboardShortcuts";

const { shortcutKeys } = useShortcutKeyMode();
const { playSound } = usePlaySound(shortcutKeys.value.sound);
const { toggleGameMode } = useShowAnswer(shortcutKeys.value.answer);
const { goToNextQuestion } = useSkipThisQuestion(shortcutKeys.value.skip);
const { showQuestion } = useGameMode();
const { showSummary } = useSummary();
const courseStore = useCourseStore();

const toggleTipText = computed(() => {
const { isAnswer } = useGameMode();
Expand Down Expand Up @@ -93,6 +117,33 @@ function useShowAnswer(key: string) {
toggleGameMode,
};
}
function useSkipThisQuestion(key: string) {
function goToNextQuestion() {
if (courseStore.isAllDone()) {
showSummary();
return;
}

courseStore.toNextStatement();
showQuestion();
}

function handleShortcut() {
onMounted(() => {
registerShortcut(key, goToNextQuestion);
});

onUnmounted(() => {
cancelShortcut(key, goToNextQuestion);
});
}

handleShortcut()

return {
goToNextQuestion,
};
}
</script>

<style scoped>
Expand Down
12 changes: 12 additions & 0 deletions apps/client/components/user/Setting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
</button>
</td>
</tr>
<tr class="hover">
<td class="label-text">跳过当前问题</td>
<td class="text-center">{{ shortcutKeys.skip }}</td>
<td class="text-center">
<button
class="btn btn-sm btn-outline btn-secondary"
@click="handleEdit('skip')"
>
编辑
</button>
</td>
</tr>
</tbody>
</table>
</section>
Expand Down
1 change: 1 addition & 0 deletions apps/client/composables/user/shortcutKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const SHORTCUT_KEYS = "shortcutKeys";
export const DEFAULT_SHORTCUT_KEYS = {
sound: "Ctrl+'",
answer: "Ctrl+;",
next: "Ctrl+.",
};
export const KEYBOARD = {
ESC: "Esc",
Expand Down
Loading