Skip to content

Commit

Permalink
feat: CycleTransferStats display by group
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 26, 2024
1 parent 38c9ac3 commit 81b94fc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
15 changes: 13 additions & 2 deletions src/components/CycleTransferStats.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
import { CycleTransferStats } from "@/types/nezha-api"
import { CycleTransferStats, NezhaServer } from "@/types/nezha-api"
import React from "react"

import { CycleTransferStatsClient } from "./CycleTransferStatsClient"

interface CycleTransferStatsProps {
serverList: NezhaServer[]
cycleStats: CycleTransferStats
className?: string
}

export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({ cycleStats, className }) => {
export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({ serverList, cycleStats, className }) => {
if (serverList.length === 0) {
return null
}

const serverIdList = serverList.map((server) => server.id.toString())

return (
<section className="grid grid-cols-1 md:grid-cols-2 gap-2 md:gap-4">
{Object.entries(cycleStats).map(([cycleId, cycleData]) => {
Expand All @@ -20,6 +27,10 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({ cycl
const transfer = cycleData.transfer?.[serverId] || 0
const nextUpdate = cycleData.next_update?.[serverId]

if (!serverIdList.includes(serverId)) {
return null
}

if (!transfer && !nextUpdate) {
return null
}
Expand Down
7 changes: 3 additions & 4 deletions src/components/ServiceTracker.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { fetchService } from "@/lib/nezha-api"
import { ServiceData } from "@/types/nezha-api"
import { NezhaServer, ServiceData } from "@/types/nezha-api"
import { ExclamationTriangleIcon } from "@heroicons/react/20/solid"
import { useQuery } from "@tanstack/react-query"
import React from "react"
import { useTranslation } from "react-i18next"

import { CycleTransferStatsCard } from "./CycleTransferStats"
import ServiceTrackerClient from "./ServiceTrackerClient"
import { Loader } from "./loading/Loader"

export const ServiceTracker: React.FC = () => {
export function ServiceTracker({ serverList }: { serverList: NezhaServer[] }) {
const { t } = useTranslation()
const { data: serviceData, isLoading } = useQuery({
queryKey: ["service"],
Expand Down Expand Up @@ -56,7 +55,7 @@ export const ServiceTracker: React.FC = () => {
<div className="mt-4 w-full mx-auto ">
{serviceData.data.cycle_transfer_stats && (
<div>
<CycleTransferStatsCard cycleStats={serviceData.data.cycle_transfer_stats} />
<CycleTransferStatsCard serverList={serverList} cycleStats={serviceData.data.cycle_transfer_stats} />
</div>
)}
{serviceData.data.services && Object.keys(serviceData.data.services).length > 0 && (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ export default function Servers() {
</Popover>
</div>
{showMap === "1" && <GlobalMap now={nezhaWsData.now} serverList={nezhaWsData?.servers || []} />}
{showServices === "1" && <ServiceTracker />}
{showServices === "1" && <ServiceTracker serverList={filteredServers} />}
{inline === "1" && (
<section className="flex flex-col gap-2 overflow-x-scroll scrollbar-hidden mt-6 server-inline-list">
{filteredServers.map((serverInfo) => (
Expand Down

0 comments on commit 81b94fc

Please sign in to comment.