diff --git a/components/ServerCard.tsx b/components/ServerCard.tsx index 5ad964b..ede838e 100644 --- a/components/ServerCard.tsx +++ b/components/ServerCard.tsx @@ -14,6 +14,7 @@ import { cn, formatBytes, formatNezhaInfo } from "@/lib/utils"; import { useTranslations } from "next-intl"; import Link from "next/link"; import { useRouter } from "next/navigation"; +import { useEffect, useRef, useState } from "react"; export default function ServerCard({ serverInfo, @@ -26,9 +27,19 @@ export default function ServerCard({ formatNezhaInfo(serverInfo); const showFlag = getEnv("NEXT_PUBLIC_ShowFlag") === "true"; - const showNetTransfer = getEnv("NEXT_PUBLIC_ShowNetTransfer") === "true"; + const nameRef = useRef(null); + const [isNameOverflow, setIsNameOverflow] = useState(false); + + useEffect(() => { + if (nameRef.current) { + setIsNameOverflow( + nameRef.current.scrollWidth > nameRef.current.clientWidth, + ); + } + }, [name]); + return online ? (

{name}

-
+ {isNameOverflow && ( +
+ )}
@@ -169,7 +183,9 @@ export default function ServerCard({ > {name}

-
+ {isNameOverflow && ( +
+ )}