diff --git a/.env.example b/.env.example index eebb9ee..8cc537f 100644 --- a/.env.example +++ b/.env.example @@ -12,7 +12,7 @@ NEXT_PUBLIC_FixedTopServerName=false NEXT_PUBLIC_CustomLogo=https://nezha-cf.buycoffee.top/apple-touch-icon.png NEXT_PUBLIC_CustomTitle=NezhaDash NEXT_PUBLIC_CustomDescription=NezhaDash is a dashboard for Nezha. -NEXT_PUBLIC_Links=[{"link":"https://baidu.com","name":"Baidu"},{"link":"https://google.com","name":"Google"}] +NEXT_PUBLIC_Links="[{"link":"https://github.com/hamster1963/nezha-dash","name":"GitHub"},{"link":"https://buycoffee.top/coffee","name":"Buycoffee☕️"}]" NEXT_PUBLIC_DisableIndex=false NEXT_PUBLIC_BASE_PATH=/ NEXT_PUBLIC_ShowTagCount=false diff --git a/app/(main)/ClientComponents/ServerListClient.tsx b/app/(main)/ClientComponents/ServerListClient.tsx index d907280..56e815a 100644 --- a/app/(main)/ClientComponents/ServerListClient.tsx +++ b/app/(main)/ClientComponents/ServerListClient.tsx @@ -4,12 +4,14 @@ import { ServerApi } from "@/app/types/nezha-api"; import ServerCard from "@/components/ServerCard"; import Switch from "@/components/Switch"; import getEnv from "@/lib/env-entry"; +import { useStatus } from "@/lib/status-context"; import { nezhaFetcher } from "@/lib/utils"; import { useTranslations } from "next-intl"; import { useEffect, useRef, useState } from "react"; import useSWR from "swr"; export default function ServerListClient() { + const { status } = useStatus(); const t = useTranslations("ServerListClient"); const containerRef = useRef(null); const defaultTag = "defaultTag"; @@ -73,17 +75,26 @@ export default function ServerListClient() { return a.id - b.id; }); - const allTag = sortedServers.map((server) => server.tag).filter(Boolean); + const filteredServersByStatus = + status === "all" + ? sortedServers + : sortedServers.filter((server) => + [status].includes(server.online_status ? "online" : "offline"), + ); + + const allTag = filteredServersByStatus + .map((server) => server.tag) + .filter(Boolean); const uniqueTags = [...new Set(allTag)]; uniqueTags.unshift(defaultTag); const filteredServers = tag === defaultTag - ? sortedServers - : sortedServers.filter((server) => server.tag === tag); + ? filteredServersByStatus + : filteredServersByStatus.filter((server) => server.tag === tag); const tagCountMap: Record = {}; - sortedServers.forEach((server) => { + filteredServersByStatus.forEach((server) => { if (server.tag) { tagCountMap[server.tag] = (tagCountMap[server.tag] || 0) + 1; } @@ -91,7 +102,7 @@ export default function ServerListClient() { return ( <> - {getEnv("NEXT_PUBLIC_ShowTag") === "true" && uniqueTags.length > 1 && ( + {getEnv("NEXT_PUBLIC_ShowTag") === "true" && ( ( "/api/server", @@ -32,7 +34,10 @@ export default function ServerOverviewClient() { return ( <>
- + setStatus("all")} + className="cursor-pointer hover:border-blue-500 transition-all" + >

@@ -55,7 +60,15 @@ export default function ServerOverviewClient() {

- + 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", + }, + )} + >

@@ -79,7 +92,15 @@ export default function ServerOverviewClient() {

- + 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", + }, + )} + >

diff --git a/app/(main)/header.tsx b/app/(main)/header.tsx index 989c30d..79ffafc 100644 --- a/app/(main)/header.tsx +++ b/app/(main)/header.tsx @@ -71,8 +71,6 @@ function Links() { const links: links[] | null = linksEnv ? JSON.parse(linksEnv) : null; - console.log(links); - if (!links) return null; return ( @@ -96,7 +94,7 @@ function Links() { // https://github.com/streamich/react-use/blob/master/src/useInterval.ts const useInterval = (callback: () => void, delay: number | null) => { - const savedCallback = useRef<() => void>(() => {}); + const savedCallback = useRef<() => void>(() => { }); useEffect(() => { savedCallback.current = callback; }); diff --git a/app/layout.tsx b/app/layout.tsx index a93e882..489f589 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -1,6 +1,7 @@ // @auto-i18n-check. Please do not delete the line. import { MotionProvider } from "@/components/motion/motion-provider"; import getEnv from "@/lib/env-entry"; +import { StatusProvider } from "@/lib/status-context"; import { cn } from "@/lib/utils"; import "@/styles/globals.css"; import type { Metadata } from "next"; @@ -78,7 +79,7 @@ export default async function LocaleLayout({ disableTransitionOnChange > - {children} + {children} diff --git a/bun.lockb b/bun.lockb index b010c72..e97d97d 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docker/.env.example b/docker/.env.example index 244fd71..f597931 100644 --- a/docker/.env.example +++ b/docker/.env.example @@ -12,5 +12,6 @@ NEXT_PUBLIC_FixedTopServerName=false NEXT_PUBLIC_CustomLogo=https://nezha-cf.buycoffee.top/apple-touch-icon.png NEXT_PUBLIC_CustomTitle=NezhaDash NEXT_PUBLIC_CustomDescription=NezhaDash is a dashboard for Nezha. +NEXT_PUBLIC_Links="[{"link":"https://github.com/hamster1963/nezha-dash","name":"GitHub"},{"link":"https://buycoffee.top/coffee","name":"Buycoffee☕️"}]" NEXT_PUBLIC_DisableIndex=false NEXT_PUBLIC_ShowTagCount=false \ No newline at end of file diff --git a/lib/status-context.tsx b/lib/status-context.tsx new file mode 100644 index 0000000..7132a05 --- /dev/null +++ b/lib/status-context.tsx @@ -0,0 +1,30 @@ +"use client"; + +import React, { ReactNode, createContext, useContext, useState } from "react"; + +type Status = "all" | "online" | "offline"; + +interface StatusContextType { + status: Status; + setStatus: (status: Status) => void; +} + +const StatusContext = createContext(undefined); + +export function StatusProvider({ children }: { children: ReactNode }) { + const [status, setStatus] = useState("all"); + + return ( + + {children} + + ); +} + +export function useStatus() { + const context = useContext(StatusContext); + if (context === undefined) { + throw new Error("useStatus must be used within a StatusProvider"); + } + return context; +} diff --git a/package.json b/package.json index 0354f1a..a9555b8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nezha-dash", - "version": "1.3.1", + "version": "1.3.2", "private": true, "scripts": { "dev": "next dev -p 3020", @@ -12,7 +12,7 @@ }, "dependencies": { "@ducanh2912/next-pwa": "^10.2.9", - "@heroicons/react": "^2.1.5", + "@heroicons/react": "^2.2.0", "@radix-ui/react-dialog": "^1.1.2", "@radix-ui/react-dropdown-menu": "^2.1.2", "@radix-ui/react-navigation-menu": "^1.2.1", @@ -23,7 +23,7 @@ "@radix-ui/react-tooltip": "^1.1.4", "@trivago/prettier-plugin-sort-imports": "^4.3.0", "@types/luxon": "^3.4.2", - "@typescript-eslint/eslint-plugin": "^8.14.0", + "@typescript-eslint/eslint-plugin": "^8.15.0", "caniuse-lite": "^1.0.30001680", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", @@ -48,7 +48,7 @@ "swr": "^2.2.6-beta.4", "tailwind-merge": "^2.5.4", "tailwindcss-animate": "^1.0.7", - "typescript-eslint": "^8.14.0" + "typescript-eslint": "^8.15.0" }, "devDependencies": { "eslint-plugin-turbo": "^2.3.0",