From 46958194a434eae763612c3f74d8eec5e44577c7 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Sun, 20 Oct 2024 00:36:22 +0800 Subject: [PATCH] fix: error message --- .../ClientComponents/ServerListClient.tsx | 2 +- .../ClientComponents/ServerOverviewClient.tsx | 217 +++++++++--------- 2 files changed, 111 insertions(+), 108 deletions(-) diff --git a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx index eea8010e6..2f163baaf 100644 --- a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx @@ -24,7 +24,7 @@ export default function ServerListClient() {

{t("error_message")}

); - if (!data) return null; + if (!data?.result) return null; const { result } = data; diff --git a/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx b/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx index c8582eb7d..ebfa63cf3 100644 --- a/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerOverviewClient.tsx @@ -12,7 +12,10 @@ import useSWR from "swr"; export default function ServerOverviewClient() { const t = useTranslations("ServerOverviewClient"); - const { data, error } = useSWR("/api/server", nezhaFetcher); + const { data, error, isLoading } = useSWR( + "/api/server", + nezhaFetcher, + ); const disableCartoon = getEnv("NEXT_PUBLIC_DisableCartoon") === "true"; if (error) @@ -23,118 +26,118 @@ export default function ServerOverviewClient() { ); - if (!data?.result) - return ( -
-

{t("no_data_message")}

-
- ); - return ( -
- - -
-

- {t("p_816-881_Totalservers")} -

-
- - - - {data ? ( -
- {data?.result.length} -
- ) : ( -
- -
- )} -
-
-
-
- - -
-

- {t("p_1610-1676_Onlineservers")} -

-
- - - - - {data ? ( -
- {data?.live_servers} -
- ) : ( -
- -
- )} -
-
-
-
- - -
-

- {t("p_2532-2599_Offlineservers")} -

-
- - - - - {data ? ( -
- {data?.offline_servers} -
+ <> +
+ + +
+

+ {t("p_816-881_Totalservers")} +

+
+ + + + {data?.result ? ( +
+ {data?.result.length} +
+ ) : ( +
+ +
+ )} +
+
+
+
+ + +
+

+ {t("p_1610-1676_Onlineservers")} +

+
+ + + + + {data?.result ? ( +
+ {data?.live_servers} +
+ ) : ( +
+ +
+ )} +
+
+
+
+ + +
+

+ {t("p_2532-2599_Offlineservers")} +

+
+ + + + + {data?.result ? ( +
+ {data?.offline_servers} +
+ ) : ( +
+ +
+ )} +
+
+
+
+ + +
+

+ {t("p_3463-3530_Totalbandwidth")} +

+ {data?.result ? ( +
+

+ ↑{formatBytes(data?.total_out_bandwidth)} +

+

+ ↓{formatBytes(data?.total_in_bandwidth)} +

+
) : (
)} -
-
-
-
- - -
-

- {t("p_3463-3530_Totalbandwidth")} -

- {data ? ( -
-

- ↑{formatBytes(data?.total_out_bandwidth)} -

-

- ↓{formatBytes(data?.total_in_bandwidth)} -

-
- ) : ( -
- -
+
+ {!disableCartoon && ( + {"Hamster1963"} )} -
- {!disableCartoon && ( - {"Hamster1963"} - )} - - - + + + + {data?.result === undefined && !isLoading && ( +
+

{t("error_message")}

+
+ )} + ); }