feat: add motion-number

This commit is contained in:
hamster1963 2024-08-21 11:20:56 +08:00
parent b724f109f3
commit adda17f20c
4 changed files with 66 additions and 10 deletions

View File

@ -7,6 +7,7 @@ import useSWR from "swr";
import { formatBytes, nezhaFetcher } from "@/lib/utils"; import { formatBytes, nezhaFetcher } from "@/lib/utils";
import { Loader } from "@/components/loading/Loader"; import { Loader } from "@/components/loading/Loader";
import { ServerApi } from "@/app/types/nezha-api"; import { ServerApi } from "@/app/types/nezha-api";
import MotionNumber from "motion-number";
export default function ServerOverviewClient() { export default function ServerOverviewClient() {
const { data } = useSWR<ServerApi>("/api/server", nezhaFetcher); const { data } = useSWR<ServerApi>("/api/server", nezhaFetcher);
@ -24,7 +25,13 @@ export default function ServerOverviewClient() {
<span className="relative inline-flex h-2 w-2 rounded-full bg-blue-500"></span> <span className="relative inline-flex h-2 w-2 rounded-full bg-blue-500"></span>
</span> </span>
{data ? ( {data ? (
<p className="text-lg font-semibold">{data?.result.length}</p> <div className="text-lg font-semibold">
<MotionNumber
value={data?.result.length}
format={{ notation: "compact" }}
locales="en-US"
/>
</div>
) : ( ) : (
<div className="flex h-7 items-center"> <div className="flex h-7 items-center">
<Loader visible={true} /> <Loader visible={true} />
@ -44,7 +51,13 @@ export default function ServerOverviewClient() {
<span className="relative inline-flex h-2 w-2 rounded-full bg-green-500"></span> <span className="relative inline-flex h-2 w-2 rounded-full bg-green-500"></span>
</span> </span>
{data ? ( {data ? (
<p className="text-lg font-semibold">{data?.live_servers}</p> <div className="text-lg font-semibold">
<MotionNumber
value={data?.live_servers}
format={{ notation: "compact" }}
locales="en-US"
/>
</div>
) : ( ) : (
<div className="flex h-7 items-center"> <div className="flex h-7 items-center">
<Loader visible={true} /> <Loader visible={true} />
@ -64,7 +77,13 @@ export default function ServerOverviewClient() {
<span className="relative inline-flex h-2 w-2 rounded-full bg-red-500"></span> <span className="relative inline-flex h-2 w-2 rounded-full bg-red-500"></span>
</span> </span>
{data ? ( {data ? (
<p className="text-lg font-semibold">{data?.offline_servers}</p> <div className="text-lg font-semibold">
<MotionNumber
value={data?.offline_servers}
format={{ notation: "compact" }}
locales="en-US"
/>
</div>
) : ( ) : (
<div className="flex h-7 items-center"> <div className="flex h-7 items-center">
<Loader visible={true} /> <Loader visible={true} />

BIN
bun.lockb

Binary file not shown.

View File

@ -9,6 +9,7 @@ import {
import { cn, formatNezhaInfo } from "@/lib/utils"; import { cn, formatNezhaInfo } from "@/lib/utils";
import ServerCardPopover from "./ServerCardPopover"; import ServerCardPopover from "./ServerCardPopover";
import getUnicodeFlagIcon from "country-flag-icons/unicode"; import getUnicodeFlagIcon from "country-flag-icons/unicode";
import MotionNumber from "motion-number";
export default function ServerCard({ export default function ServerCard({
serverInfo, serverInfo,
@ -56,26 +57,61 @@ export default function ServerCard({
<section className={"grid grid-cols-5 items-center gap-3"}> <section className={"grid grid-cols-5 items-center gap-3"}>
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
<p className="text-xs text-muted-foreground">CPU</p> <p className="text-xs text-muted-foreground">CPU</p>
<div className="text-xs font-semibold">{cpu.toFixed(2)}%</div> <div className="text-xs font-semibold flex items-center">
<MotionNumber
value={cpu.toFixed(2)}
format={{ notation: "compact" }}
locales="en-US"
/>
%
</div>
<ServerUsageBar value={cpu} /> <ServerUsageBar value={cpu} />
</div> </div>
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
<p className="text-xs text-muted-foreground">Mem</p> <p className="text-xs text-muted-foreground">Mem</p>
<div className="text-xs font-semibold">{mem.toFixed(2)}%</div> <div className="text-xs font-semibold flex items-center">
<MotionNumber
value={mem.toFixed(2)}
format={{ notation: "compact" }}
locales="en-US"
/>
%
</div>
<ServerUsageBar value={mem} /> <ServerUsageBar value={mem} />
</div> </div>
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
<p className="text-xs text-muted-foreground">STG</p> <p className="text-xs text-muted-foreground">STG</p>
<div className="text-xs font-semibold">{stg.toFixed(2)}%</div> <div className="text-xs font-semibold flex items-center">
<MotionNumber
value={stg.toFixed(2)}
format={{ notation: "compact" }}
locales="en-US"
/>
%
</div>
<ServerUsageBar value={stg} /> <ServerUsageBar value={stg} />
</div> </div>
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
<p className="text-xs text-muted-foreground">Upload</p> <p className="text-xs text-muted-foreground">Upload</p>
<div className="text-xs font-semibold">{up.toFixed(2)}Mb/s</div> <div className="text-xs font-semibold flex items-center">
<MotionNumber
value={up.toFixed(2)}
format={{ notation: "compact" }}
locales="en-US"
/>
Mb/s
</div>
</div> </div>
<div className={"flex flex-col"}> <div className={"flex flex-col"}>
<p className="text-xs text-muted-foreground">Download</p> <p className="text-xs text-muted-foreground">Download</p>
<div className="text-xs font-semibold">{down.toFixed(2)}Mb/s</div> <div className="text-xs font-semibold flex items-center">
<MotionNumber
value={down.toFixed(2)}
format={{ notation: "compact" }}
locales="en-US"
/>
Mb/s
</div>
</div> </div>
</section> </section>
</Card> </Card>

View File

@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "next dev -p 3020", "dev": "next dev -p 3020 --turbo",
"start": "node .next/standalone/server.js", "start": "node .next/standalone/server.js",
"lint": "next lint", "lint": "next lint",
"build": "next build && cp -r .next/static .next/standalone/.next/ && cp -r public .next/standalone/" "build": "next build && cp -r .next/static .next/standalone/.next/ && cp -r public .next/standalone/"
@ -26,6 +26,7 @@
"eslint-plugin-simple-import-sort": "^12.0.0", "eslint-plugin-simple-import-sort": "^12.0.0",
"lucide-react": "^0.414.0", "lucide-react": "^0.414.0",
"luxon": "^3.4.4", "luxon": "^3.4.4",
"motion-number": "^0.1.6",
"next": "^14.2.3", "next": "^14.2.3",
"next-themes": "^0.3.0", "next-themes": "^0.3.0",
"react": "^18.2.0", "react": "^18.2.0",