diff --git a/app/(main)/ClientComponents/ServerListClient.tsx b/app/(main)/ClientComponents/ServerListClient.tsx index d9072805e..56e815ac8 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/layout.tsx b/app/layout.tsx index a93e882f1..489f589aa 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 b010c7234..e97d97d65 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/lib/status-context.tsx b/lib/status-context.tsx new file mode 100644 index 000000000..7132a05a7 --- /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 0354f1a4d..f61e8a0ae 100644 --- a/package.json +++ b/package.json @@ -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",