-
Notifications
You must be signed in to change notification settings - Fork 829
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7ce2415
commit d7f36ce
Showing
7 changed files
with
369 additions
and
86 deletions.
There are no files selected for viewing
287 changes: 234 additions & 53 deletions
287
app/[locale]/(main)/ClientComponents/ServerDetailClient.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,243 @@ | ||
"use client"; | ||
|
||
import useSWR from "swr"; | ||
import { NezhaAPISafe } from "@/app/[locale]/types/nezha-api"; | ||
import { nezhaFetcher } from "@/lib/utils"; | ||
import getEnv from "@/lib/env-entry"; | ||
import { useRouter } from "next/navigation"; | ||
import { useLocale } from "next-intl"; | ||
import { BackIcon } from "@/components/Icon"; | ||
import { Card, CardContent } from "@/components/ui/card"; | ||
import AnimatedCircularProgressBar from "@/components/ui/animated-circular-progress-bar"; | ||
import { Badge } from "@/components/ui/badge"; | ||
import { Card, CardContent } from "@/components/ui/card"; | ||
import getEnv from "@/lib/env-entry"; | ||
import { cn, nezhaFetcher } from "@/lib/utils"; | ||
import { useLocale } from "next-intl"; | ||
import { useRouter } from "next/navigation"; | ||
import useSWR from "swr"; | ||
|
||
export default function ServerDetailClient({ server_id }: { server_id: number }) { | ||
const router = useRouter(); | ||
const locale = useLocale(); | ||
const { data, error } = useSWR<NezhaAPISafe>( | ||
`/api/detail?server_id=${server_id}`, | ||
nezhaFetcher, | ||
{ | ||
refreshInterval: | ||
Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 5000, | ||
}, | ||
); | ||
export default function ServerDetailClient({ | ||
server_id, | ||
}: { | ||
server_id: number; | ||
}) { | ||
const router = useRouter(); | ||
const locale = useLocale(); | ||
const { data, error } = useSWR<NezhaAPISafe>( | ||
`/api/detail?server_id=${server_id}`, | ||
nezhaFetcher, | ||
{ | ||
refreshInterval: Number(getEnv("NEXT_PUBLIC_NezhaFetchInterval")) || 5000, | ||
}, | ||
); | ||
if (error) { | ||
return ( | ||
<div className="mx-auto grid w-full max-w-5xl gap-1"> | ||
<div | ||
onClick={() => { | ||
router.push(`/${locale}/`); | ||
}} | ||
className="flex flex-none cursor-pointer font-semibold leading-none items-center break-all tracking-tight gap-0.5 text-xl" | ||
> | ||
<BackIcon /> | ||
HomeDash | ||
</div> | ||
<section className="flex flex-wrap gap-4 mt-2"> | ||
<Card className="rounded-[10px] flex flex-col justify-center"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold"> | ||
ID | ||
</p> | ||
<div className="text-xs w-fit"> {server_id} </div> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold"> | ||
Tag | ||
</p> | ||
<Badge className="text-xs rounded-[6px] w-fit px-1 py-0" variant="secondary"> {data?.tag} </Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
</section> | ||
<> | ||
<div className="flex flex-col items-center justify-center"> | ||
<p className="text-sm font-medium opacity-40">{error.message}</p> | ||
<p className="text-sm font-medium opacity-40"> | ||
{/* {t("chart_fetch_error_message")} */} | ||
fetch_error_message | ||
</p> | ||
</div> | ||
) | ||
|
||
|
||
</> | ||
); | ||
} | ||
if (!data) return null; | ||
return ( | ||
<div className="mx-auto grid w-full max-w-5xl gap-1"> | ||
<div | ||
onClick={() => { | ||
router.push(`/${locale}/`); | ||
}} | ||
className="flex flex-none cursor-pointer font-semibold leading-none items-center break-all tracking-tight gap-0.5 text-xl" | ||
> | ||
<BackIcon /> | ||
{data?.name} | ||
</div> | ||
<section className="flex flex-wrap gap-2 mt-2"> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Status</p> | ||
<Badge | ||
className={cn( | ||
"text-xs rounded-[6px] w-fit px-1 py-0 dark:text-white", | ||
{ | ||
" bg-green-800": data?.online_status, | ||
" bg-red-600": !data?.online_status, | ||
}, | ||
)} | ||
> | ||
{data?.online_status ? "Online" : "Offline"} | ||
</Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Uptime</p> | ||
<Badge | ||
className="text-xs rounded-[6px] w-fit px-1 py-0" | ||
variant="secondary" | ||
> | ||
{" "} | ||
{(data?.status.Uptime / 86400).toFixed(0)} Days{" "} | ||
</Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
|
||
} | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Tag</p> | ||
<Badge | ||
className="text-xs rounded-[6px] w-fit px-1 py-0" | ||
variant="secondary" | ||
> | ||
{" "} | ||
{data?.tag || "Unknown"}{" "} | ||
</Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Arch</p> | ||
<Badge | ||
className="text-xs rounded-[6px] w-fit px-1 py-0" | ||
variant="secondary" | ||
> | ||
{" "} | ||
{data?.host.Arch || "Unknown"}{" "} | ||
</Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Version</p> | ||
<Badge | ||
className="text-xs rounded-[6px] w-fit px-1 py-0" | ||
variant="secondary" | ||
> | ||
{" "} | ||
{data?.host.Version || "Unknown"}{" "} | ||
</Badge> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
</section> | ||
<section className="flex flex-wrap gap-2 mt-1"> | ||
<Card className="rounded-[10px] flex flex-col justify-center"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">System</p> | ||
{data?.host.Platform ? ( | ||
<div className="text-xs w-fit"> | ||
{" "} | ||
{data?.host.Platform || "Unknown"} -{" "} | ||
{data?.host.PlatformVersion}{" "} | ||
</div> | ||
) : ( | ||
<div className="text-xs w-fit"> Unknown </div> | ||
)} | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px] flex flex-col justify-center"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">CPU</p> | ||
{data?.host.CPU ? ( | ||
<div className="text-xs w-fit"> | ||
{" "} | ||
{data?.host.CPU || "Unknown"} | ||
</div> | ||
) : ( | ||
<div className="text-xs w-fit"> Unknown </div> | ||
)} | ||
</section> | ||
</CardContent> | ||
</Card> | ||
</section> | ||
<section className="flex flex-wrap gap-2 mt-1"> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">CPU</p> | ||
<p className="text-xs text-end w-10 font-medium"> | ||
{data?.status.CPU.toFixed(0)}% | ||
</p> | ||
<AnimatedCircularProgressBar | ||
className="size-3 text-[0px]" | ||
max={100} | ||
min={0} | ||
value={data?.status.CPU} | ||
/> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Mem</p> | ||
<p className="text-xs w-10 text-end font-medium"> | ||
{((data?.status.MemUsed / data?.host.MemTotal) * 100).toFixed( | ||
0, | ||
)} | ||
% | ||
</p> | ||
<AnimatedCircularProgressBar | ||
className="size-3 text-[0px]" | ||
max={100} | ||
min={0} | ||
value={(data?.status.MemUsed / data?.host.MemTotal) * 100} | ||
/> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Swap</p> | ||
<p className="text-xs w-10 text-end font-medium"> | ||
{data?.status.SwapUsed | ||
? ( | ||
(data?.status.SwapUsed / data?.host.SwapTotal) * | ||
100 | ||
).toFixed(0) | ||
: 0} | ||
% | ||
</p> | ||
<AnimatedCircularProgressBar | ||
className="size-3 text-[0px]" | ||
max={100} | ||
min={0} | ||
value={(data?.status.SwapUsed / data?.host.SwapTotal) * 100} | ||
/> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
<Card className="rounded-[10px]"> | ||
<CardContent className="px-1.5 py-1"> | ||
<section className="flex items-center gap-2"> | ||
<p className="text-xs font-semibold">Disk</p> | ||
<p className="text-xs w-10 text-end font-medium"> | ||
{((data?.status.DiskUsed / data?.host.DiskTotal) * 100).toFixed( | ||
0, | ||
)} | ||
% | ||
</p> | ||
<AnimatedCircularProgressBar | ||
className="size-3 text-[0px]" | ||
max={100} | ||
min={0} | ||
value={(data?.status.DiskUsed / data?.host.DiskTotal) * 100} | ||
/> | ||
</section> | ||
</CardContent> | ||
</Card> | ||
</section> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
import ServerDetailClient from "@/app/[locale]/(main)/ClientComponents/ServerDetailClient"; | ||
|
||
export default function Page({ params }: { params: { id: string } }) { | ||
return ( | ||
<ServerDetailClient server_id={Number(params.id)} /> | ||
); | ||
return <ServerDetailClient server_id={Number(params.id)} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.