Skip to content

Commit eb45842

Browse files
committed
feat: add mastered button on mobile
1 parent 030e934 commit eb45842

File tree

3 files changed

+80
-37
lines changed

3 files changed

+80
-37
lines changed

apps/client/components/main/QuestionInput/QuestionInput.vue

+27
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,27 @@
5757
播放声音
5858
</button>
5959
</div>
60+
<button
61+
class="btn btn-outline btn-sm"
62+
@click="handleMastered"
63+
>
64+
掌握
65+
</button>
6066
</div>
6167
</div>
6268
</template>
6369

6470
<script setup lang="ts">
6571
import { onMounted, onUnmounted, ref, watch } from "vue";
6672
73+
import Message from "~/components/main/Message/useMessage";
6774
import { courseTimer } from "~/composables/courses/courseTimer";
6875
import { useAnswerTip } from "~/composables/main/answerTip";
6976
import { useCurrentStatementEnglishSound } from "~/composables/main/englishSound";
7077
import { isWord } from "~/composables/main/question";
78+
import { useMastered } from "~/composables/main/useMastered";
7179
import { useShowWordsWidth } from "~/composables/user/words";
80+
import { isAuthenticated } from "~/services/auth";
7281
import { useCourseStore } from "~/store/course";
7382
import { isWindows } from "~/utils/platform";
7483
import { getWordWidth, useQuestionInput } from "./questionInputHelper";
@@ -89,6 +98,7 @@ const {
8998
const { isShowWordsWidth } = useShowWordsWidth();
9099
const { toggleAnswerTip, isAnswerTip } = useAnswerTip();
91100
const { resetCloseTip } = useAnswerError();
101+
const { handleMastered } = useMasteredShortcut();
92102
initializeQuestionInput();
93103
focusInputWhenWIndowFocus();
94104
@@ -127,6 +137,23 @@ function focusInputWhenWIndowFocus() {
127137
});
128138
}
129139
140+
function useMasteredShortcut() {
141+
const { markStatementAsMastered } = useMastered();
142+
143+
function handleMastered() {
144+
if (!isAuthenticated()) {
145+
Message.warning("需要登录哦");
146+
return;
147+
}
148+
149+
markStatementAsMastered();
150+
}
151+
152+
return {
153+
handleMastered,
154+
};
155+
}
156+
130157
const { playSound } = useCurrentStatementEnglishSound();
131158
function handlePlaySound(e: MouseEvent) {
132159
e.preventDefault();

apps/client/components/main/Tips.vue

+7-37
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,20 @@ import { useAnswerTip } from "~/composables/main/answerTip";
3030
import { useCurrentStatementEnglishSound } from "~/composables/main/englishSound";
3131
import { useGameMode } from "~/composables/main/game";
3232
import { useSummary } from "~/composables/main/summary";
33+
import { useMastered } from "~/composables/main/useMastered";
3334
import { useShortcutKeyMode } from "~/composables/user/shortcutKey";
3435
import { isAuthenticated } from "~/services/auth";
35-
import { useCourseStore } from "~/store/course";
36-
import { useMasteredElementsStore } from "~/store/masteredElements";
3736
import { cancelShortcut, parseShortcutKeys, registerShortcut } from "~/utils/keyboardShortcuts";
3837
import { useAnswer } from "./QuestionInput/useAnswer";
3938
import { useWrapperQuestionInput } from "./QuestionInput/useWrapperQuestionInput";
4039
4140
const { toggleAnswerTip, isAnswerTip } = useAnswerTip();
4241
const { shortcutKeys } = useShortcutKeyMode();
4342
const { playSound } = usePlaySound(shortcutKeys.value.sound);
44-
const { handleMastered } = useMastered();
4543
const { goToNextQuestion } = useAnswer();
4644
const { showQuestion, isQuestion } = useGameMode();
4745
const { submitAnswer } = useWrapperQuestionInput();
46+
const { handleMastered } = useMasteredShortcut();
4847
useShowAnswer(shortcutKeys.value.answer);
4948
5049
const keybindings = computed(() => {
@@ -90,7 +89,7 @@ const keybindings = computed(() => {
9089
},
9190
{
9291
keys: shortcutKeys.value.mastered,
93-
text: "掌握啦",
92+
text: "掌握",
9493
eventFn: handleMastered,
9594
},
9695
];
@@ -106,45 +105,16 @@ const keybindings = computed(() => {
106105
return resultItems;
107106
});
108107
109-
function useMastered() {
110-
const { shortcutKeys } = useShortcutKeyMode();
111-
const courseStore = useCourseStore();
112-
const masteredElements = useMasteredElementsStore();
113-
const { showQuestion } = useGameMode();
114-
const { showSummary } = useSummary();
108+
function useMasteredShortcut() {
109+
const { markStatementAsMastered } = useMastered();
115110
116-
const addLoading = ref(false);
117-
async function handleMastered() {
111+
function handleMastered() {
118112
if (!isAuthenticated()) {
119113
Message.warning("需要登录哦");
120114
return;
121115
}
122116
123-
// updateMarketedStatements 会影响 isLastStatement 返回的结果
124-
// 所以我们提前调用 isLastStatement 来记录好值
125-
if (addLoading.value) return;
126-
const isLastStatement = courseStore.isLastStatement();
127-
addLoading.value = true;
128-
await masteredElements.addElement({
129-
english: courseStore.currentStatement?.english!,
130-
});
131-
addLoading.value = false;
132-
133-
courseStore.updateMarketedStatements();
134-
135-
if (isLastStatement) {
136-
showSummary();
137-
} else {
138-
// 看看消完之后 是否全部都没有了
139-
// 这个是在 updatemarketedStatements 之后
140-
// 处理的 case 比如只剩下2个 good ,那么消除一个 good 之后 那么列表就应该为0了
141-
if (courseStore.isAllMastered()) {
142-
showSummary();
143-
return;
144-
}
145-
courseStore.toNextStatement();
146-
showQuestion();
147-
}
117+
markStatementAsMastered();
148118
}
149119
150120
onMounted(() => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { ref } from "vue";
2+
3+
import { useGameMode } from "~/composables/main/game";
4+
import { useSummary } from "~/composables/main/summary";
5+
import { useCourseStore } from "~/store/course";
6+
import { useMasteredElementsStore } from "~/store/masteredElements";
7+
8+
export function useMastered() {
9+
const courseStore = useCourseStore();
10+
const masteredElements = useMasteredElementsStore();
11+
const { showQuestion } = useGameMode();
12+
const { showSummary } = useSummary();
13+
14+
const addLoading = ref(false);
15+
async function markStatementAsMastered() {
16+
// updateMarketedStatements 会影响 isLastStatement 返回的结果
17+
// 所以我们提前调用 isLastStatement 来记录好值
18+
if (addLoading.value) return;
19+
const isLastStatement = courseStore.isLastStatement();
20+
addLoading.value = true;
21+
await masteredElements.addElement({
22+
english: courseStore.currentStatement?.english!,
23+
});
24+
addLoading.value = false;
25+
26+
courseStore.updateMarketedStatements();
27+
28+
if (isLastStatement) {
29+
showSummary();
30+
} else {
31+
// 看看消完之后 是否全部都没有了
32+
// 这个是在 updatemarketedStatements 之后
33+
// 处理的 case 比如只剩下2个 good ,那么消除一个 good 之后 那么列表就应该为0了
34+
if (courseStore.isAllMastered()) {
35+
showSummary();
36+
return;
37+
}
38+
courseStore.toNextStatement();
39+
showQuestion();
40+
}
41+
}
42+
43+
return {
44+
markStatementAsMastered,
45+
};
46+
}

0 commit comments

Comments
 (0)