From ace9c2ee8c4026ea8f394bb18bb31f67b5b455ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BB=93=E9=BC=A0?= <71394853+hamster1963@users.noreply.github.com> Date: Thu, 5 Dec 2024 11:23:57 +0800 Subject: [PATCH 1/6] docs: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ### 部署 From ec1c72e4cb73a9272a41985cd8ac1d5c8f824722 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 14:29:31 +0800 Subject: [PATCH 2/6] fix(overview): refreshInterval --- app/(main)/ClientComponents/ServerOverviewClient.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/(main)/ClientComponents/ServerOverviewClient.tsx b/app/(main)/ClientComponents/ServerOverviewClient.tsx index 7df36ae..235fecf 100644 --- a/app/(main)/ClientComponents/ServerOverviewClient.tsx +++ b/app/(main)/ClientComponents/ServerOverviewClient.tsx @@ -24,6 +24,9 @@ export default function ServerOverviewClient() { const { data, error, isLoading } = useSWR( "/api/server", nezhaFetcher, + { + refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 2000, + }, ); const disableCartoon = getEnv("NEXT_PUBLIC_DisableCartoon") === "true"; From 07f02f5da86300c2f7d6d393c73f03c5e9bf8ffc Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 14:31:02 +0800 Subject: [PATCH 3/6] chore: deps --- bun.lockb | Bin 613720 -> 613720 bytes package.json | 10 +++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/bun.lockb b/bun.lockb index 912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json b/package.json index b471cd6..4950f09 100644 --- a/package.json +++ b/package.json @@ -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" }, From f8bfbde9b58beb09299c2f0ad4a2f15df20b326a Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 14:45:58 +0800 Subject: [PATCH 4/6] perf: refactor global map as client side render --- app/(main)/ClientComponents/Global.tsx | 25 ++++++++++++++++--- .../ClientComponents/ServerOverviewClient.tsx | 4 +-- app/(main)/page.tsx | 13 +++++----- 3 files changed, 29 insertions(+), 13 deletions(-) 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/ServerOverviewClient.tsx b/app/(main)/ClientComponents/ServerOverviewClient.tsx index 235fecf..9a49d37 100644 --- a/app/(main)/ClientComponents/ServerOverviewClient.tsx +++ b/app/(main)/ClientComponents/ServerOverviewClient.tsx @@ -202,9 +202,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 680118f..871fe51 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -1,10 +1,13 @@ import ServerList from "@/components/ServerList"; import ServerOverview from "@/components/ServerOverview"; -import { Suspense } from "react"; +import dynamic from "next/dynamic"; -import ServerGlobal from "./ClientComponents/Global"; import GlobalLoading from "./ClientComponents/GlobalLoading"; +const ServerGlobal = dynamic(() => import("./ClientComponents/Global"), { + loading: () => , +}); + export default async function Home({ searchParams, }: { @@ -15,11 +18,7 @@ export default async function Home({
{!global && } - {global && ( - }> - - - )} + {global && }
); } From 0b93cf7af82387278c3f0defa92e50e310fcba07 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 15:07:20 +0800 Subject: [PATCH 5/6] feat: show map in main page --- app/(main)/ClientComponents/GlobalInfo.tsx | 2 - app/(main)/ClientComponents/GlobalLoading.tsx | 2 - .../ClientComponents/ServerListClient.tsx | 20 +++++++-- .../ClientComponents/ServerOverviewClient.tsx | 42 ++++--------------- app/(main)/page.tsx | 17 +------- 5 files changed, 27 insertions(+), 56 deletions(-) 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, - }, )} > diff --git a/app/(main)/page.tsx b/app/(main)/page.tsx index 871fe51..f7cafe8 100644 --- a/app/(main)/page.tsx +++ b/app/(main)/page.tsx @@ -1,24 +1,11 @@ import ServerList from "@/components/ServerList"; import ServerOverview from "@/components/ServerOverview"; -import dynamic from "next/dynamic"; -import GlobalLoading from "./ClientComponents/GlobalLoading"; - -const ServerGlobal = dynamic(() => import("./ClientComponents/Global"), { - loading: () => , -}); - -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 && } +
); } From 017a82859109398bbbb8ad6cd4398b4b00df951b Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Thu, 5 Dec 2024 15:08:14 +0800 Subject: [PATCH 6/6] v1.7.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4950f09..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",