diff --git a/Makefile b/Makefile index b8a78bb8..5010694c 100644 --- a/Makefile +++ b/Makefile @@ -30,6 +30,7 @@ build: swag @go build -ldflags "-linkmode external -w -s $(LDFLAGS)" -o ./build/$(BINARY) $(PACKAGE)/cmd/cloudsdale @echo Build finished. +run: export DEBUG = true run: swag @echo Running $(PACKAGE)... go run -ldflags "$(LDFLAGS)" $(PACKAGE)/cmd/cloudsdale diff --git a/main.go b/main.go new file mode 100644 index 00000000..e746d733 --- /dev/null +++ b/main.go @@ -0,0 +1 @@ +package Cloudsdale diff --git a/web/src/App.tsx b/web/src/App.tsx index b424db9a..474361d0 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -4,7 +4,7 @@ import routes from "~react-pages"; import { Box, LoadingOverlay, MantineProvider } from "@mantine/core"; import { emotionTransform, MantineEmotionProvider } from "@mantine/emotion"; import { Suspense, useEffect } from "react"; -import useTheme from "@/composables/useTheme"; +import { useTheme } from "@/utils/theme"; import { useCategoryApi } from "@/api/category"; import { useCategoryStore } from "@/stores/category"; import { useConfigApi } from "@/api/config"; diff --git a/web/src/pages/admin/challenges/[id]/index.tsx b/web/src/pages/admin/challenges/[id]/index.tsx index c95a217d..b4040aa5 100644 --- a/web/src/pages/admin/challenges/[id]/index.tsx +++ b/web/src/pages/admin/challenges/[id]/index.tsx @@ -56,7 +56,8 @@ function Page() { } function saveAttachment() { - const notificationID = showLoadingNotification({ + showLoadingNotification({ + id: "upload-attachment", message: "正在上传附件", }); const config: AxiosRequestConfig = {}; @@ -64,8 +65,9 @@ function Page() { .saveChallengeAttachment(Number(id), attachment!, config) .then((_) => { showSuccessNotification({ - id: notificationID, + id: "upload-attachment", message: "附件上传成功", + update: true, }); setRefresh((prev) => prev + 1); }); diff --git a/web/src/utils/axios.ts b/web/src/utils/axios.ts index 358341d2..34be0db5 100644 --- a/web/src/utils/axios.ts +++ b/web/src/utils/axios.ts @@ -38,6 +38,7 @@ export const useAuth = () => { authStore.setUser(undefined); navigate("/login"); showInfoNotification({ + id: "auth-expired", message: "登录凭据已过期,请重新登录", }); } diff --git a/web/src/utils/notification.tsx b/web/src/utils/notification.tsx index c01b13a0..84bf3579 100644 --- a/web/src/utils/notification.tsx +++ b/web/src/utils/notification.tsx @@ -1,134 +1,141 @@ -import { notifications, showNotification } from "@mantine/notifications"; +import { + NotificationData, + showNotification, + updateNotification, +} from "@mantine/notifications"; import MDIcon from "@/components/ui/MDIcon"; export function showErrNotification({ id, title, message, + update, }: { id?: string; title?: string; message?: string; + update?: boolean; }) { - if (id) { - notifications.update({ - id: id, - title: title || "发生了错误", - message: message, - color: "red", - icon: close, + const notificationData: NotificationData = { + id: id, + title: title || "错误", + message: message, + color: "red", + icon: exclamation, + }; + if (update) { + updateNotification({ + ...notificationData, autoClose: 2000, withCloseButton: true, loading: false, }); - return; + } else { + showNotification(notificationData); } - showNotification({ - title: title || "发生了错误", - message: message, - color: "red", - icon: close, - }); } export function showSuccessNotification({ id, title, message, + update, }: { id?: string; title?: string; message?: string; + update?: boolean; }) { - if (id) { - notifications.update({ - id: id, - title: title || "成功", - message: message, - color: "green", - icon: check, + const notificationData: NotificationData = { + id: id, + title: title || "成功", + message: message, + color: "green", + icon: check, + }; + if (update) { + updateNotification({ + ...notificationData, autoClose: 2000, withCloseButton: true, loading: false, }); - return; + } else { + showNotification(notificationData); } - showNotification({ - title: title || "成功", - message: message, - color: "green", - icon: check, - }); } export function showInfoNotification({ id, title, message, + update, }: { id?: string; title?: string; message?: string; + update?: boolean; }) { - if (id) { - notifications.update({ - id: id, - title: title || "信息", - message: message, - color: "blue", - icon: info_i, + const notificationData: NotificationData = { + id: id, + title: title || "信息", + message: message, + color: "blue", + icon: info_i, + }; + if (update) { + updateNotification({ + ...notificationData, autoClose: 2000, withCloseButton: true, loading: false, }); - return; + } else { + showNotification(notificationData); } - showNotification({ - title: title || "信息", - message: message, - color: "blue", - icon: info_i, - }); } export function showWarnNotification({ id, title, message, + update, }: { id?: string; title?: string; message?: string; + update?: boolean; }) { - if (id) { - notifications.update({ - id: id, - title: title || "警告", - message: message, - color: "orange", - icon: exclamation, + const notificationData: NotificationData = { + id: id, + title: title || "警告", + message: message, + color: "orange", + icon: exclamation, + }; + if (update) { + updateNotification({ + ...notificationData, autoClose: 2000, withCloseButton: true, loading: false, }); - return; + } else { + showNotification(notificationData); } - showNotification({ - title: title || "警告", - message: message, - color: "orange", - icon: exclamation, - }); } export function showLoadingNotification({ + id, title, message, }: { + id?: string; title?: string; message?: string; -}): string { - const id = notifications.show({ +}) { + showNotification({ + id: id, title: title || "请稍后", loading: true, message: message, @@ -136,5 +143,4 @@ export function showLoadingNotification({ autoClose: false, withCloseButton: false, }); - return id; } diff --git a/web/src/composables/useTheme.ts b/web/src/utils/theme.ts similarity index 96% rename from web/src/composables/useTheme.ts rename to web/src/utils/theme.ts index 5a46b165..3d2148c6 100644 --- a/web/src/composables/useTheme.ts +++ b/web/src/utils/theme.ts @@ -1,6 +1,6 @@ import { createTheme } from "@mantine/core"; -export default function useTheme() { +export function useTheme() { const theme = createTheme({ colors: { brand: [