diff --git a/README.md b/README.md index d7364e8..e436d17 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ > V0 | V1 版本 issue 请在当前仓库发起 > [!TIP] -> 有关 V1 版本 pr 可移步 https://github.com/hamster1963/nezha-dash-react +> 有关 V1 版本 pr 可移步 https://github.com/hamster1963/nezha-dash-v1 ### 部署 diff --git a/app/(main)/ClientComponents/Global.tsx b/app/(main)/ClientComponents/Global.tsx index 5fe711f..cb58e6b 100644 --- a/app/(main)/ClientComponents/Global.tsx +++ b/app/(main)/ClientComponents/Global.tsx @@ -1,11 +1,30 @@ -import { GetNezhaData } from "@/lib/serverFetch"; +"use client"; + +import { ServerApi } from "@/app/types/nezha-api"; +import { nezhaFetcher } from "@/lib/utils"; +import useSWR from "swr"; import { geoJsonString } from "../../../lib/geo-json-string"; import GlobalInfo from "./GlobalInfo"; +import GlobalLoading from "./GlobalLoading"; import { InteractiveMap } from "./InteractiveMap"; -export default async function ServerGlobal() { - const nezhaServerList = await GetNezhaData(); +export default function ServerGlobal() { + const { data: nezhaServerList, error } = useSWR( + "/api/server", + nezhaFetcher, + ); + + if (error) + return ( +
+

{error.message}

+
+ ); + + if (!nezhaServerList) { + return ; + } const countryList: string[] = []; const serverCounts: { [key: string]: number } = {}; diff --git a/app/(main)/ClientComponents/GlobalInfo.tsx b/app/(main)/ClientComponents/GlobalInfo.tsx index ff777c6..f407480 100644 --- a/app/(main)/ClientComponents/GlobalInfo.tsx +++ b/app/(main)/ClientComponents/GlobalInfo.tsx @@ -1,6 +1,5 @@ "use client"; -import GlobalBackButton from "@/components/GlobalBackButton"; import { useTranslations } from "next-intl"; type GlobalInfoProps = { @@ -11,7 +10,6 @@ export default function GlobalInfo({ countries }: GlobalInfoProps) { const t = useTranslations("Global"); return (
-

{t("Distributions")} {countries.length} {t("Regions")}

diff --git a/app/(main)/ClientComponents/GlobalLoading.tsx b/app/(main)/ClientComponents/GlobalLoading.tsx index a87fb4a..c6141c6 100644 --- a/app/(main)/ClientComponents/GlobalLoading.tsx +++ b/app/(main)/ClientComponents/GlobalLoading.tsx @@ -1,6 +1,5 @@ "use client"; -import GlobalBackButton from "@/components/GlobalBackButton"; import { Loader } from "@/components/loading/Loader"; import { useTranslations } from "next-intl"; @@ -8,7 +7,6 @@ export default function GlobalLoading() { const t = useTranslations("Global"); return (
-
{t("Loading")} diff --git a/app/(main)/ClientComponents/ServerListClient.tsx b/app/(main)/ClientComponents/ServerListClient.tsx index 1d68c95..8d10961 100644 --- a/app/(main)/ClientComponents/ServerListClient.tsx +++ b/app/(main)/ClientComponents/ServerListClient.tsx @@ -10,19 +10,25 @@ import { useStatus } from "@/lib/status-context"; import { cn, nezhaFetcher } from "@/lib/utils"; import { MapIcon, ViewColumnsIcon } from "@heroicons/react/20/solid"; import { useTranslations } from "next-intl"; -import { useRouter } from "next/navigation"; +import dynamic from "next/dynamic"; import { useEffect, useRef, useState } from "react"; import useSWR from "swr"; +import GlobalLoading from "./GlobalLoading"; + +const ServerGlobal = dynamic(() => import("./Global"), { + loading: () => , +}); + export default function ServerListClient() { const { status } = useStatus(); const { filter } = useFilter(); const t = useTranslations("ServerListClient"); const containerRef = useRef(null); const defaultTag = "defaultTag"; - const router = useRouter(); const [tag, setTag] = useState(defaultTag); + const [showMap, setShowMap] = useState(false); const [inline, setInline] = useState("0"); useEffect(() => { @@ -131,9 +137,14 @@ export default function ServerListClient() {
@@ -161,6 +172,7 @@ export default function ServerListClient() { /> )}
+ {showMap && } {inline === "1" && (
@@ -50,14 +45,10 @@ export default function ServerOverviewClient() {
{ - if (!global) { - setFilter(false); - setStatus("all"); - } + setFilter(false); + setStatus("all"); }} - className={cn("cursor-pointer hover:border-blue-500 transition-all", { - "pointer-events-none": global, - })} + className={cn("cursor-pointer hover:border-blue-500 transition-all")} >
@@ -83,19 +74,14 @@ export default function ServerOverviewClient() { { - if (!global) { - setFilter(false); - setStatus("online"); - } + setFilter(false); + setStatus("online"); }} className={cn( "cursor-pointer hover:ring-green-500 ring-1 ring-transparent transition-all", { "ring-green-500 ring-2 border-transparent": status === "online", }, - { - "pointer-events-none": global, - }, )} > @@ -123,19 +109,14 @@ export default function ServerOverviewClient() { { - if (!global) { - setFilter(false); - setStatus("offline"); - } + setFilter(false); + setStatus("offline"); }} className={cn( "cursor-pointer hover:ring-red-500 ring-1 ring-transparent transition-all", { "ring-red-500 ring-2 border-transparent": status === "offline", }, - { - "pointer-events-none": global, - }, )} > @@ -163,19 +144,14 @@ export default function ServerOverviewClient() { { - if (!global) { - setStatus("all"); - setFilter(true); - } + setStatus("all"); + setFilter(true); }} className={cn( "cursor-pointer hover:ring-purple-500 ring-1 ring-transparent transition-all", { "ring-purple-500 ring-2 border-transparent": filter === true, }, - { - "pointer-events-none": global, - }, )} > @@ -202,9 +178,7 @@ export default function ServerOverviewClient() {

- {formatBytes( - data?.total_in_speed, - )}/s + {formatBytes(data?.total_in_speed)}/s

diff --git a/app/(main)/page.tsx b/app/(main)/page.tsx index 51f769b..4f753ca 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -1,27 +1,13 @@ import ServerList from "@/components/ServerList"; import ServerOverview from "@/components/ServerOverview"; -import { Suspense } from "react"; - -import ServerGlobal from "./ClientComponents/Global"; -import GlobalLoading from "./ClientComponents/GlobalLoading"; export const runtime = "edge"; -export default async function Home({ - searchParams, -}: { - searchParams: Promise<{ [key: string]: string | string[] | undefined }>; -}) { - const global = (await searchParams).global; +export default async function Home() { return (
- {!global && } - {global && ( - }> - - - )} +
); } diff --git a/bun.lockb b/bun.lockb index 912fe81..cdc2370 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index b471cd6..8be1269 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nezha-dash", - "version": "1.6.11", + "version": "1.7.0", "private": true, "scripts": { "dev": "next dev -p 3040", @@ -26,7 +26,7 @@ "@types/d3-geo": "^3.1.0", "@types/luxon": "^3.4.2", "@typescript-eslint/eslint-plugin": "^8.17.0", - "caniuse-lite": "^1.0.30001685", + "caniuse-lite": "^1.0.30001686", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", "country-flag-icons": "^1.5.13", @@ -47,7 +47,7 @@ "react-dom": "19.0.0-rc-02c0e824-20241028", "react-intersection-observer": "^9.13.1", "react-wrap-balancer": "^1.1.1", - "recharts": "^2.14.0", + "recharts": "^2.14.1", "sharp": "^0.33.5", "swr": "^2.2.6-beta.4", "tailwind-merge": "^2.5.5", @@ -56,7 +56,7 @@ }, "devDependencies": { "@next/bundle-analyzer": "^15.0.3", - "@tailwindcss/postcss": "^4.0.0-beta.4", + "@tailwindcss/postcss": "^4.0.0-beta.5", "@types/node": "^22.10.1", "@types/react": "npm:types-react@19.0.0-rc.1", "@types/react-dom": "npm:types-react-dom@19.0.0-rc.1", @@ -65,9 +65,9 @@ "eslint-plugin-turbo": "^2.3.3", "eslint-plugin-unused-imports": "^4.1.4", "postcss": "^8.4.49", - "prettier": "^3.4.1", + "prettier": "^3.4.2", "prettier-plugin-tailwindcss": "^0.6.9", - "tailwindcss": "^4.0.0-beta.4", + "tailwindcss": "^4.0.0-beta.5", "typescript": "^5.7.2", "vercel": "39.1.1" },