fix: add server ID to tooltip data and update MapTooltip component for navigation

This commit is contained in:
hamster1963
2025-12-28 15:01:27 +08:00
parent 4f9db466a3
commit 4d4c3f1639
3 changed files with 18 additions and 5 deletions
+2
View File
@@ -117,6 +117,7 @@ export function InteractiveMap({ countries, serverCounts, width, height, filtere
const countryServers = nezhaServerList const countryServers = nezhaServerList
.filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode) .filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode)
.map((server: NezhaServer) => ({ .map((server: NezhaServer) => ({
id: server.id,
name: server.name, name: server.name,
status: formatNezhaInfo(now, server).online, status: formatNezhaInfo(now, server).online,
})) }))
@@ -155,6 +156,7 @@ export function InteractiveMap({ countries, serverCounts, width, height, filtere
const countryServers = nezhaServerList const countryServers = nezhaServerList
.filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode.toUpperCase()) .filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode.toUpperCase())
.map((server: NezhaServer) => ({ .map((server: NezhaServer) => ({
id: server.id,
name: server.name, name: server.name,
status: formatNezhaInfo(now, server).online, status: formatNezhaInfo(now, server).online,
})) }))
+15 -5
View File
@@ -2,9 +2,11 @@ import useTooltip from "@/hooks/use-tooltip"
import { AnimatePresence, m } from "framer-motion" import { AnimatePresence, m } from "framer-motion"
import { memo } from "react" import { memo } from "react"
import { useTranslation } from "react-i18next" import { useTranslation } from "react-i18next"
import { useNavigate } from "react-router-dom"
const MapTooltip = memo(function MapTooltip() { const MapTooltip = memo(function MapTooltip() {
const { t } = useTranslation() const { t } = useTranslation()
const navigate = useNavigate()
const { tooltipData } = useTooltip() const { tooltipData } = useTooltip()
if (!tooltipData) return null if (!tooltipData) return null
@@ -28,7 +30,7 @@ const MapTooltip = memo(function MapTooltip() {
> >
<div> <div>
<p className="font-medium">{tooltipData.country === "China" ? "Mainland China" : tooltipData.country}</p> <p className="font-medium">{tooltipData.country === "China" ? "Mainland China" : tooltipData.country}</p>
<p className="text-neutral-600 dark:text-neutral-400 mb-1"> <p className="text-neutral-600 dark:text-neutral-400 text-xs font-light mb-1">
{tooltipData.count} {t("map.Servers")} {tooltipData.count} {t("map.Servers")}
</p> </p>
</div> </div>
@@ -39,11 +41,19 @@ const MapTooltip = memo(function MapTooltip() {
overflowY: "auto", overflowY: "auto",
}} }}
> >
{tooltipData.servers.map((server, index: number) => ( {tooltipData.servers.map((server) => (
<div key={index} className="flex items-center gap-1.5 py-0.5"> <button
<span className={`w-1.5 h-1.5 shrink-0 rounded-full ${server.status ? "bg-green-500" : "bg-red-500"}`}></span> key={server.id}
type="button"
className="flex items-center gap-1.5 py-0.5 text-neutral-500 transition-colors hover:text-black dark:text-neutral-400 dark:hover:text-white"
onClick={() => {
sessionStorage.setItem("fromMainPage", "true")
navigate(`/server/${server.id}`)
}}
>
<span className={`h-1.5 w-1.5 shrink-0 rounded-full ${server.status ? "bg-green-500" : "bg-red-500"}`} />
<span className="text-xs">{server.name}</span> <span className="text-xs">{server.name}</span>
</div> </button>
))} ))}
</div> </div>
</m.div> </m.div>
+1
View File
@@ -5,6 +5,7 @@ export interface TooltipData {
country: string country: string
count: number count: number
servers: Array<{ servers: Array<{
id: number
name: string name: string
status: boolean status: boolean
}> }>