diff --git a/.env.example b/.env.example index e2c860e..2ad804e 100644 --- a/.env.example +++ b/.env.example @@ -3,4 +3,5 @@ NezhaAuth=your-nezha-api-token DefaultLocale=zh NEXT_PUBLIC_NezhaFetchInterval=5000 NEXT_PUBLIC_ShowFlag=true -NEXT_PUBLIC_DisableCartoon=true \ No newline at end of file +NEXT_PUBLIC_DisableCartoon=true +NEXT_PUBLIC_ShowTag=true \ No newline at end of file diff --git a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx index 6d4b586..9a66b10 100644 --- a/app/[locale]/(main)/ClientComponents/ServerListClient.tsx +++ b/app/[locale]/(main)/ClientComponents/ServerListClient.tsx @@ -5,7 +5,14 @@ import ServerCard from "../../../../components/ServerCard"; import { nezhaFetcher } from "../../../../lib/utils"; import useSWR from "swr"; import getEnv from "../../../../lib/env-entry"; +import Switch from "@/components/Switch"; +import { useState } from "react"; + +const defaultTag = "All"; + export default function ServerListClient() { + const [tag, setTag] = useState(defaultTag); + const { data, error } = useSWR("/api/server", nezhaFetcher, { refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 2000, }); @@ -23,17 +30,31 @@ export default function ServerListClient() { const { result } = data; + const allTag = result.map((server) => server.tag).filter((tag) => tag); + const uniqueTags = [...new Set(allTag)]; + uniqueTags.unshift(defaultTag); + const sortedServers = result.sort((a, b) => { const displayIndexDiff = (b.display_index || 0) - (a.display_index || 0); if (displayIndexDiff !== 0) return displayIndexDiff; return a.id - b.id; }); + const filteredServers = + tag === defaultTag + ? sortedServers + : sortedServers.filter((server) => server.tag === tag); + return ( -
- {sortedServers.map((serverInfo) => ( - - ))} -
+ <> + {getEnv("NEXT_PUBLIC_ShowTag") === "true" && uniqueTags.length > 1 && ( + + )} +
+ {filteredServers.map((serverInfo) => ( + + ))} +
+ ); } diff --git a/bun.lockb b/bun.lockb index 6139404..f164099 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/Switch.tsx b/components/Switch.tsx new file mode 100644 index 0000000..f295397 --- /dev/null +++ b/components/Switch.tsx @@ -0,0 +1,48 @@ +"use client"; + +import React from "react"; +import { cn } from "@/lib/utils"; +import { motion } from "framer-motion"; + +export default function Switch({ + allTag, + nowTag, + setTag, +}: { + allTag: string[]; + nowTag: string; + setTag: (tag: string) => void; +}) { + return ( +
+
+ {allTag.map((tag) => ( +
setTag(tag)} + className={cn( + "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", + nowTag === tag + ? "text-black dark:text-white" + : "text-stone-400 dark:text-stone-500", + )} + > + {nowTag === tag && ( + + )} +
+

{tag}

+
+
+ ))} +
+
+ ); +} diff --git a/package.json b/package.json index 40ad458..815ce71 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "country-flag-icons": "^1.5.13", "eslint-plugin-simple-import-sort": "^12.1.1", "flag-icons": "^7.2.3", + "framer-motion": "^11.9.0", "lucide-react": "^0.414.0", "luxon": "^3.5.0", "next": "^14.2.13", diff --git a/tsconfig.json b/tsconfig.json index e7ff90f..763aaa3 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,6 @@ { "compilerOptions": { + "target": "ES6", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true,