mirror of
https://github.com/woodchen-ink/nezha-dash-v1.git
synced 2025-07-18 17:41:56 +08:00
refactor: improve CycleTransferStats and ServiceTracker UI components
This commit is contained in:
parent
0f81ef2f25
commit
48dbf85bca
@ -17,7 +17,7 @@ export const CycleTransferStatsCard: React.FC<CycleTransferStatsProps> = ({ serv
|
|||||||
const serverIdList = serverList.map((server) => server.id.toString())
|
const serverIdList = serverList.map((server) => server.id.toString())
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="grid grid-cols-1 md:grid-cols-2 gap-2 md:gap-4">
|
<section className="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||||||
{Object.entries(cycleStats).map(([cycleId, cycleData]) => {
|
{Object.entries(cycleStats).map(([cycleId, cycleData]) => {
|
||||||
if (!cycleData.server_name) {
|
if (!cycleData.server_name) {
|
||||||
return null
|
return null
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
import { formatBytes } from "@/lib/format"
|
import { formatBytes } from "@/lib/format"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import { CircleStackIcon } from "@heroicons/react/24/outline"
|
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
|
|
||||||
import AnimatedCircularProgressBar from "./ui/animated-circular-progress-bar"
|
|
||||||
|
|
||||||
interface CycleTransferStatsClientProps {
|
interface CycleTransferStatsClientProps {
|
||||||
name: string
|
name: string
|
||||||
from: string
|
from: string
|
||||||
@ -26,7 +23,7 @@ export const CycleTransferStatsClient: React.FC<CycleTransferStatsClientProps> =
|
|||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className={cn(
|
className={cn(
|
||||||
"w-full bg-white px-4 py-3 rounded-lg border bg-card text-card-foreground shadow-lg shadow-neutral-200/40 dark:shadow-none space-y-2",
|
"w-full bg-white px-4 py-3.5 rounded-lg border bg-card text-card-foreground hover:shadow-sm transition-all duration-200 dark:shadow-none",
|
||||||
className,
|
className,
|
||||||
{
|
{
|
||||||
"bg-card/70": customBackgroundImage,
|
"bg-card/70": customBackgroundImage,
|
||||||
@ -37,43 +34,41 @@ export const CycleTransferStatsClient: React.FC<CycleTransferStatsClientProps> =
|
|||||||
const progress = (transfer / max) * 100
|
const progress = (transfer / max) * 100
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div key={serverId}>
|
<div key={serverId} className="space-y-3">
|
||||||
<section className="flex justify-between items-center">
|
{/* Header */}
|
||||||
<div className="bg-green-600 w-fit text-white px-1.5 py-0.5 rounded-full text-[10px]">{name}</div>
|
<div className="flex items-center justify-between">
|
||||||
<span className="text-stone-600 dark:text-stone-400 text-xs">
|
<span className="text-sm font-medium text-neutral-800 dark:text-neutral-200">{serverName}</span>
|
||||||
{new Date(from).toLocaleDateString()} - {new Date(to).toLocaleDateString()}
|
<div className="bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 px-2 py-0.5 rounded text-xs font-medium">{name}</div>
|
||||||
</span>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section className="flex justify-between items-center mt-2">
|
|
||||||
<div className="flex gap-1 items-center">
|
|
||||||
<CircleStackIcon className="size-3 text-neutral-400 dark:text-neutral-600" />
|
|
||||||
<span className="text-sm font-semibold">{serverName}</span>
|
|
||||||
</div>
|
|
||||||
<div className="flex items-center gap-1">
|
|
||||||
<p className="text-xs text-end w-10 font-medium">{progress.toFixed(0)}%</p>
|
|
||||||
<AnimatedCircularProgressBar className="size-4 text-[0px]" max={100} min={0} value={progress} primaryColor="hsl(var(--chart-5))" />
|
|
||||||
</div>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<div className="w-full bg-neutral-100 dark:bg-neutral-800 rounded-full overflow-hidden h-2.5 mt-2">
|
|
||||||
<div className="bg-green-600 h-2.5 rounded-full" style={{ width: `${Math.min(progress, 100)}%` }} />
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<section className="flex justify-between items-center mt-2">
|
{/* Progress Section */}
|
||||||
<span className="text-[13px] text-stone-800 dark:text-stone-400 font-medium">
|
<div className="space-y-1.5">
|
||||||
{formatBytes(transfer)} {t("cycleTransfer.used")}
|
<div className="flex items-center justify-between">
|
||||||
</span>
|
<div className="flex items-baseline gap-1">
|
||||||
<span className="text-xs text-stone-500 dark:text-stone-400 font-normal">
|
<span className="text-sm font-medium text-neutral-800 dark:text-neutral-200">{formatBytes(transfer)}</span>
|
||||||
{formatBytes(max)} {t("cycleTransfer.total")}
|
<span className="text-xs text-neutral-500 dark:text-neutral-400">/ {formatBytes(max)}</span>
|
||||||
</span>
|
</div>
|
||||||
</section>
|
<span className="text-xs font-medium text-neutral-600 dark:text-neutral-300">{progress.toFixed(1)}%</span>
|
||||||
|
|
||||||
<section className="flex justify-between items-center mt-2">
|
|
||||||
<div className="text-xs text-stone-500 dark:text-stone-400">
|
|
||||||
{t("cycleTransfer.nextUpdate")}: {new Date(nextUpdate).toLocaleString()}
|
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
|
<div className="relative h-1.5">
|
||||||
|
<div className="absolute inset-0 bg-neutral-100 dark:bg-neutral-800 rounded-full" />
|
||||||
|
<div
|
||||||
|
className="absolute inset-0 bg-emerald-500 rounded-full transition-all duration-300"
|
||||||
|
style={{ width: `${Math.min(progress, 100)}%` }}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Footer */}
|
||||||
|
<div className="flex items-center justify-between text-[11px] text-neutral-500 dark:text-neutral-400">
|
||||||
|
<span>
|
||||||
|
{new Date(from).toLocaleDateString()} - {new Date(to).toLocaleDateString()}
|
||||||
|
</span>
|
||||||
|
<span>
|
||||||
|
{t("cycleTransfer.nextUpdate")}: {new Date(nextUpdate).toLocaleString()}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
})}
|
})}
|
||||||
|
@ -26,7 +26,7 @@ export function ServiceTracker({ serverList }: { serverList: NezhaServer[] }) {
|
|||||||
completed: up > serviceData.down[index],
|
completed: up > serviceData.down[index],
|
||||||
date: new Date(Date.now() - (29 - index) * 24 * 60 * 60 * 1000),
|
date: new Date(Date.now() - (29 - index) * 24 * 60 * 60 * 1000),
|
||||||
uptime: dailyUptime,
|
uptime: dailyUptime,
|
||||||
delay: serviceData.delay[index] || 0
|
delay: serviceData.delay[index] || 0,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,12 +1,8 @@
|
|||||||
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"
|
||||||
import { cn } from "@/lib/utils"
|
import { cn } from "@/lib/utils"
|
||||||
import React from "react"
|
import React from "react"
|
||||||
import { useTranslation } from "react-i18next"
|
import { useTranslation } from "react-i18next"
|
||||||
import {
|
|
||||||
Tooltip,
|
|
||||||
TooltipContent,
|
|
||||||
TooltipProvider,
|
|
||||||
TooltipTrigger,
|
|
||||||
} from "@/components/ui/tooltip"
|
|
||||||
import { Separator } from "./ui/separator"
|
import { Separator } from "./ui/separator"
|
||||||
|
|
||||||
interface ServiceTrackerProps {
|
interface ServiceTrackerProps {
|
||||||
@ -60,17 +56,9 @@ export const ServiceTrackerClient: React.FC<ServiceTrackerProps> = ({ days, clas
|
|||||||
<span className="font-medium text-sm">{title}</span>
|
<span className="font-medium text-sm">{title}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
<span className={cn(
|
<span className={cn("font-medium text-sm transition-colors", getDelayColor(avgDelay))}>{avgDelay.toFixed(0)}ms</span>
|
||||||
"font-medium text-sm transition-colors",
|
|
||||||
getDelayColor(avgDelay)
|
|
||||||
)}>
|
|
||||||
{avgDelay.toFixed(0)}ms
|
|
||||||
</span>
|
|
||||||
<Separator className="h-4" orientation="vertical" />
|
<Separator className="h-4" orientation="vertical" />
|
||||||
<span className={cn(
|
<span className={cn("font-medium text-sm transition-colors", getUptimeColor(uptime))}>
|
||||||
"font-medium text-sm transition-colors",
|
|
||||||
getUptimeColor(uptime)
|
|
||||||
)}>
|
|
||||||
{uptime.toFixed(1)}% {t("serviceTracker.uptime")}
|
{uptime.toFixed(1)}% {t("serviceTracker.uptime")}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
@ -88,7 +76,7 @@ export const ServiceTrackerClient: React.FC<ServiceTrackerProps> = ({ days, clas
|
|||||||
"after:absolute after:inset-0 after:rounded-[4px] after:shadow-[inset_0_1px_theme(colors.white/10%)]",
|
"after:absolute after:inset-0 after:rounded-[4px] after:shadow-[inset_0_1px_theme(colors.white/10%)]",
|
||||||
day.completed
|
day.completed
|
||||||
? "bg-gradient-to-b from-green-500/90 to-green-600 shadow-[0_1px_2px_theme(colors.green.600/30%)]"
|
? "bg-gradient-to-b from-green-500/90 to-green-600 shadow-[0_1px_2px_theme(colors.green.600/30%)]"
|
||||||
: "bg-gradient-to-b from-red-500/80 to-red-600/90 shadow-[0_1px_2px_theme(colors.red.600/30%)]"
|
: "bg-gradient-to-b from-red-500/80 to-red-600/90 shadow-[0_1px_2px_theme(colors.red.600/30%)]",
|
||||||
)}
|
)}
|
||||||
/>
|
/>
|
||||||
</TooltipTrigger>
|
</TooltipTrigger>
|
||||||
@ -98,13 +86,16 @@ export const ServiceTrackerClient: React.FC<ServiceTrackerProps> = ({ days, clas
|
|||||||
<div className="space-y-1.5">
|
<div className="space-y-1.5">
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex items-center justify-between gap-3">
|
||||||
<span className="text-xs text-muted-foreground">{t("serviceTracker.uptime")}:</span>
|
<span className="text-xs text-muted-foreground">{t("serviceTracker.uptime")}:</span>
|
||||||
<span className={cn("text-xs font-medium", day.uptime > 95 ? "text-green-500" : "text-red-500")}>
|
<span className={cn("text-xs font-medium", day.uptime > 95 ? "text-green-500" : "text-red-500")}>{day.uptime.toFixed(1)}%</span>
|
||||||
{day.uptime.toFixed(1)}%
|
|
||||||
</span>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center justify-between gap-3">
|
<div className="flex items-center justify-between gap-3">
|
||||||
<span className="text-xs text-muted-foreground">{t("serviceTracker.delay")}:</span>
|
<span className="text-xs text-muted-foreground">{t("serviceTracker.delay")}:</span>
|
||||||
<span className={cn("text-xs font-medium", day.delay < 100 ? "text-green-500" : day.delay < 300 ? "text-yellow-500" : "text-red-500")}>
|
<span
|
||||||
|
className={cn(
|
||||||
|
"text-xs font-medium",
|
||||||
|
day.delay < 100 ? "text-green-500" : day.delay < 300 ? "text-yellow-500" : "text-red-500",
|
||||||
|
)}
|
||||||
|
>
|
||||||
{day.delay.toFixed(0)}ms
|
{day.delay.toFixed(0)}ms
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user