feat: show number within subgroups

This commit is contained in:
hamster1963 2024-11-14 16:54:10 +08:00
parent f931a9c487
commit 7e1a74c6f0
3 changed files with 18 additions and 3 deletions

View File

@ -82,12 +82,20 @@ export default function ServerListClient() {
? sortedServers ? sortedServers
: sortedServers.filter((server) => server.tag === tag); : sortedServers.filter((server) => server.tag === tag);
const tagCountMap: Record<string, number> = {};
sortedServers.forEach((server) => {
if (server.tag) {
tagCountMap[server.tag] = (tagCountMap[server.tag] || 0) + 1;
}
});
return ( return (
<> <>
{getEnv("NEXT_PUBLIC_ShowTag") === "true" && uniqueTags.length > 1 && ( {getEnv("NEXT_PUBLIC_ShowTag") === "true" && uniqueTags.length > 1 && (
<Switch <Switch
allTag={uniqueTags} allTag={uniqueTags}
nowTag={tag} nowTag={tag}
tagCountMap={tagCountMap}
onTagChange={handleTagChange} onTagChange={handleTagChange}
/> />
)} )}

BIN
bun.lockb

Binary file not shown.

View File

@ -8,10 +8,12 @@ import React, { createRef, useEffect, useRef } from "react";
export default function Switch({ export default function Switch({
allTag, allTag,
nowTag, nowTag,
tagCountMap,
onTagChange, onTagChange,
}: { }: {
allTag: string[]; allTag: string[];
nowTag: string; nowTag: string;
tagCountMap: Record<string, number>;
onTagChange: (tag: string) => void; onTagChange: (tag: string) => void;
}) { }) {
const scrollRef = useRef<HTMLDivElement>(null); const scrollRef = useRef<HTMLDivElement>(null);
@ -84,9 +86,14 @@ export default function Switch({
/> />
)} )}
<div className="relative z-20 flex items-center gap-1"> <div className="relative z-20 flex items-center gap-1">
<p className="whitespace-nowrap"> <div className="whitespace-nowrap flex items-center gap-2">
{tag === "defaultTag" ? t("defaultTag") : tag} {tag === "defaultTag" ? t("defaultTag") : tag}{" "}
</p> {tag !== "defaultTag" && (
<div className="w-fit px-1.5 rounded-full bg-muted">
{tagCountMap[tag]}
</div>
)}
</div>
</div> </div>
</div> </div>
))} ))}