Skip to content

Commit fe785eb

Browse files
committed
refactor: use vue-sonner replace Message
1 parent 8e9c3e8 commit fe785eb

File tree

17 files changed

+64
-179
lines changed

17 files changed

+64
-179
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ docker images
262262
263263
2. Avoid including UI logic in composables.
264264
265-
- Such as `useMessage`
265+
- Such as `toast.info()`
266266
- We categorize the router as UI logic, and for ease of testing, avoid including routerrelated logic in there
267267
268268
## 🚀 Star History

README.zh-CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ docker images
262262
263263
2. composables 里面不要包含 UI 逻辑
264264
265-
- useMessage 之类的
265+
- Such as `toast.info()`
266266
- router 相关的也不要放进去(不便于测试 我们把 router 划分为 UI 逻辑)
267267
268268
## 🚀 星路历程

apps/client/app.vue

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,29 @@
1212
</NuxtLayout>
1313
</template>
1414
<UModals />
15+
<Toaster
16+
:theme="darkMode === Theme.DARK ? 'dark' : 'light'"
17+
position="top-center"
18+
:toastOptions="{
19+
style: {
20+
background: darkMode === Theme.DARK ? '#c084fc' : '#f3e8ff',
21+
color: darkMode === Theme.DARK ? '#000' : '#6b21a8',
22+
},
23+
}"
24+
/>
1525
</HttpErrorProvider>
1626
</template>
1727

1828
<script setup lang="ts">
1929
import { useAsyncData } from "#imports";
30+
import { Toaster } from "vue-sonner";
2031
2132
import { fetchCurrentUser } from "~/api/user";
22-
import { useDarkMode } from "~/composables/darkMode";
33+
import { Theme, useDarkMode } from "~/composables/darkMode";
2334
import { isAuthenticated } from "~/services/auth";
2435
import { useUserStore } from "./store/user";
2536
26-
const { initDarkMode } = useDarkMode();
37+
const { initDarkMode, darkMode } = useDarkMode();
2738
initDarkMode();
2839
2940
const userStore = useUserStore();

apps/client/components/HttpErrorProvider.vue

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
</template>
44

55
<script setup lang="ts">
6+
import { toast } from "vue-sonner";
7+
68
import { injectHttpStatusErrorHandler } from "~/api/http.js";
7-
import Message from "~/components/main/Message/useMessage";
89
import { signIn } from "~/services/auth";
910
1011
useHttpStatusError();
@@ -13,14 +14,15 @@ function useHttpStatusError() {
1314
injectHttpStatusErrorHandler(async (errMessage, statusCode) => {
1415
switch (statusCode) {
1516
case 401:
16-
Message.error(errMessage, {
17+
toast.error(errMessage, {
1718
duration: 2000,
18-
onLeave() {
19+
onAutoClose() {
1920
signIn(window.location.pathname);
2021
},
2122
});
23+
break;
2224
default:
23-
Message.error(errMessage);
25+
toast.error(errMessage);
2426
break;
2527
}
2628
});

apps/client/components/Landing/PayCard.vue

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,6 @@
108108
</template>
109109

110110
<script setup>
111-
import { useRouter } from "vue-router";
112-
113-
import Message from "~/components/main/Message/useMessage";
114-
115111
const features = [
116112
{
117113
type: "免费",
@@ -138,8 +134,6 @@ const features = [
138134
async function handleUpgrade(type) {
139135
if (type === "免费") {
140136
} else {
141-
// Upgrade now
142-
Message.warning("Function is not open!");
143137
}
144138
}
145139
</script>

apps/client/components/main/Message/Message.vue

Lines changed: 0 additions & 82 deletions
This file was deleted.

apps/client/components/main/Message/useMessage.ts

Lines changed: 0 additions & 61 deletions
This file was deleted.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@
6969

7070
<script setup lang="ts">
7171
import { onMounted, onUnmounted, ref, watch } from "vue";
72+
import { toast } from "vue-sonner";
7273
73-
import Message from "~/components/main/Message/useMessage";
7474
import { courseTimer } from "~/composables/courses/courseTimer";
7575
import { useAnswerTip } from "~/composables/main/answerTip";
7676
import { useCurrentStatementEnglishSound } from "~/composables/main/englishSound";
@@ -142,7 +142,7 @@ function useMasteredShortcut() {
142142
143143
function handleMastered() {
144144
if (!isAuthenticated()) {
145-
Message.warning("需要登录哦");
145+
toast.warning("需要登录哦");
146146
return;
147147
}
148148

apps/client/components/main/Summary.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,9 @@
8484
</template>
8585

8686
<script setup lang="ts">
87-
import delay from "lodash-es/delay";
8887
import { computed, ref, watch } from "vue";
88+
import { toast } from "vue-sonner";
8989
90-
import Message from "~/components/main/Message/useMessage";
9190
import { useActiveCourseMap } from "~/composables/courses/activeCourse";
9291
import { courseTimer } from "~/composables/courses/courseTimer";
9392
import { useAuthRequire } from "~/composables/main/authRequire";
@@ -165,8 +164,12 @@ function useDoAgain() {
165164
// 看看是不是没有全部掌握了
166165
// 如果是全部掌握了 那么给个提示 然后挑战到课程列表
167166
if (courseStore.isAllMastered()) {
168-
Message.warning("你已经全部都掌握 自动帮你跳转到课程列表啦");
169-
await delay(handleGoToCourseList, 1500);
167+
toast.info("你已经全部都掌握 自动帮你跳转到课程列表啦", {
168+
duration: 1500,
169+
onAutoClose: () => {
170+
handleGoToCourseList();
171+
},
172+
});
170173
return;
171174
}
172175
courseStore.doAgain();
@@ -205,8 +208,12 @@ function useCourse() {
205208
hideSummary();
206209
207210
if (!haveNextCourse.value) {
208-
Message.warning("已经是最后一课 自动帮你跳转到课程列表啦");
209-
await delay(handleGoToCourseList, 1500);
211+
toast.info("已经是最后一课 自动帮你跳转到课程列表啦", {
212+
duration: 1500,
213+
onAutoClose: () => {
214+
handleGoToCourseList();
215+
},
216+
});
210217
return;
211218
}
212219

apps/client/components/main/Tips.vue

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
</template>
2424

2525
<script setup lang="ts">
26-
import { computed, onMounted, onUnmounted, ref } from "vue";
26+
import { computed, onMounted, onUnmounted } from "vue";
27+
import { toast } from "vue-sonner";
2728
28-
import Message from "~/components/main/Message/useMessage";
2929
import { useAnswerTip } from "~/composables/main/answerTip";
3030
import { useCurrentStatementEnglishSound } from "~/composables/main/englishSound";
3131
import { useGameMode } from "~/composables/main/game";
@@ -110,7 +110,7 @@ function useMasteredShortcut() {
110110
111111
function handleMastered() {
112112
if (!isAuthenticated()) {
113-
Message.warning("需要登录哦");
113+
toast.warning("需要登录哦");
114114
return;
115115
}
116116

0 commit comments

Comments
 (0)