From a2aaacb34884d2a63c6e7be9c36bdddf462011c6 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 1 Dec 2024 16:35:15 +0800 Subject: [PATCH] fix(toast): only once --- src/components/Header.tsx | 2 +- src/pages/Server.tsx | 4 +++- src/types/nezha-api.ts | 3 +-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/components/Header.tsx b/src/components/Header.tsx index e82a5ec..d5cfa94 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -13,7 +13,7 @@ function Header() { const { t } = useTranslation(); const navigate = useNavigate(); - const { data: settingData,isLoading } = useQuery({ + const { data: settingData, isLoading } = useQuery({ queryKey: ["setting"], queryFn: () => fetchSetting(), refetchOnMount: true, diff --git a/src/pages/Server.tsx b/src/pages/Server.tsx index 30f9ddc..50b18c2 100644 --- a/src/pages/Server.tsx +++ b/src/pages/Server.tsx @@ -46,8 +46,10 @@ export default function Servers() { ]; useEffect(() => { - if (readyState == 1) { + const hasShownToast = sessionStorage.getItem("websocket-connected-toast"); + if (readyState == 1 && !hasShownToast) { toast.success(t("info.websocketConnected")); + sessionStorage.setItem("websocket-connected-toast", "true"); } }, [readyState]); diff --git a/src/types/nezha-api.ts b/src/types/nezha-api.ts index d529610..5f15971 100644 --- a/src/types/nezha-api.ts +++ b/src/types/nezha-api.ts @@ -150,7 +150,6 @@ export interface CycleTransferData { }; } - export interface SettingResponse { success: boolean; data: { @@ -158,4 +157,4 @@ export interface SettingResponse { site_name: string; custom_code: string; }; -} \ No newline at end of file +}