Merge pull request #11 from hamster1963/nation-flag

feat: add flag
This commit is contained in:
仓鼠 2024-08-09 16:53:00 +08:00 committed by GitHub
commit 83363bc4a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 107 additions and 20 deletions

View File

@ -1,3 +1,5 @@
NezhaBaseUrl=http://0.0.0.0:8008 NezhaBaseUrl=http://0.0.0.0:8008
NezhaAuth=5hAY3QX6Nl9B3UOQgB26KdsdS1dsdUdM NezhaAuth=5hAY3QX6Nl9B3UOQgB26KdsdS1dsdUdM
NEXT_PUBLIC_NezhaFetchInterval=5000 NEXT_PUBLIC_NezhaFetchInterval=5000
NEXT_PUBLIC_ShowFlag=true
NEXT_PUBLIC_DisableCartoon=true

View File

@ -11,11 +11,14 @@
#### 环境变量 #### 环境变量
变量名 | 含义 | 示例 | 变量名 | 含义 | 示例 |
--- | --- | --- | ------------------------------ | -------------------- | -------------------------------- |
NezhaBaseUrl | nezha 面板地址 | http://120.x.x.x:8008 | NezhaBaseUrl | nezha 面板地址 | http://120.x.x.x:8008 |
NezhaAuth | nezha 面板 API Token | 5hAY3QX6Nl9B3Uxxxx26KMvOMyXS1Udi | NezhaAuth | nezha 面板 API Token | 5hAY3QX6Nl9B3Uxxxx26KMvOMyXS1Udi |
NEXT_PUBLIC_NezhaFetchInterval | 获取数据间隔(毫秒)| **默认**2000 | NEXT_PUBLIC_NezhaFetchInterval | 获取数据间隔(毫秒) | **默认**2000 |
| NEXT_PUBLIC_ShowFlag | 是否显示旗帜 | **默认**false |
| NEXT_PUBLIC_DisableCartoon | 是否禁用卡通人物 | **默认**false |
<br> <br>
![screen-shot-one](/.github/shotOne.png) ![screen-shot-one](/.github/shotOne.png)

File diff suppressed because one or more lines are too long

View File

@ -4,6 +4,7 @@ import React, { useEffect, useRef, useState } from "react";
import Image from "next/image"; import Image from "next/image";
import { Separator } from "@/components/ui/separator"; import { Separator } from "@/components/ui/separator";
import { DateTime } from "luxon"; import { DateTime } from "luxon";
import { ModeToggle } from "@/components/ThemeSwitcher";
function Header() { function Header() {
return ( return (
@ -20,7 +21,7 @@ function Header() {
className="relative !m-0 h-6 w-6 border-2 border-white object-cover object-top !p-0 transition duration-500 group-hover:z-30 group-hover:scale-105" className="relative !m-0 h-6 w-6 border-2 border-white object-cover object-top !p-0 transition duration-500 group-hover:z-30 group-hover:scale-105"
/> />
</div> </div>
HomeDash NezhaDash
<Separator <Separator
orientation="vertical" orientation="vertical"
className="mx-2 hidden h-4 w-[1px] md:block" className="mx-2 hidden h-4 w-[1px] md:block"
@ -29,7 +30,7 @@ function Header() {
Simple and beautiful dashboard Simple and beautiful dashboard
</p> </p>
</section> </section>
{/* <LiveTag /> */} <ModeToggle />
</section> </section>
<Overview /> <Overview />
</div> </div>

View File

@ -14,11 +14,11 @@ const fontSans = FontSans({
export const metadata: Metadata = { export const metadata: Metadata = {
manifest: "/manifest.json", manifest: "/manifest.json",
title: "HomeDash", title: "NezhaDash",
description: "A dashboard for nezha", description: "A dashboard for nezha",
appleWebApp: { appleWebApp: {
capable: true, capable: true,
title: "HomeDash", title: "NezhaDash",
statusBarStyle: "black-translucent", statusBarStyle: "black-translucent",
}, },
}; };

BIN
bun.lockb

Binary file not shown.

View File

@ -6,17 +6,20 @@ import {
PopoverContent, PopoverContent,
PopoverTrigger, PopoverTrigger,
} from "@/components/ui/popover"; } from "@/components/ui/popover";
import { 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";
export default function ServerCard({ export default function ServerCard({
serverInfo, serverInfo,
}: { }: {
serverInfo: NezhaAPISafe; serverInfo: NezhaAPISafe;
}) { }) {
const { name, online, cpu, up, down, mem, stg, ...props } = const { name, country_code, online, cpu, up, down, mem, stg, ...props } =
formatNezhaInfo(serverInfo); formatNezhaInfo(serverInfo);
const showFlag = process.env.NEXT_PUBLIC_ShowFlag === "true";
return online ? ( return online ? (
<Card <Card
className={ className={
@ -26,8 +29,24 @@ export default function ServerCard({
<Popover> <Popover>
<PopoverTrigger asChild> <PopoverTrigger asChild>
<section className={"flex items-center justify-start gap-2 lg:w-28"}> <section className={"flex items-center justify-start gap-2 lg:w-28"}>
{showFlag ? (
country_code ? (
<span className="text-[12px] text-muted-foreground">
{getUnicodeFlagIcon(country_code)}
</span>
) : (
<span className="text-[12px] text-muted-foreground">🏴</span>
)
) : null}
<span className="h-2 w-2 shrink-0 rounded-full bg-green-500"></span> <span className="h-2 w-2 shrink-0 rounded-full bg-green-500"></span>
<p className="break-all text-sm font-bold tracking-tight">{name}</p> <p
className={cn(
"break-all font-bold tracking-tight",
showFlag ? "text-xs" : "text-sm",
)}
>
{name}
</p>
</section> </section>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent side="top"> <PopoverContent side="top">
@ -69,8 +88,24 @@ export default function ServerCard({
<Popover> <Popover>
<PopoverTrigger asChild> <PopoverTrigger asChild>
<section className={"flex items-center justify-start gap-2 lg:w-28"}> <section className={"flex items-center justify-start gap-2 lg:w-28"}>
{showFlag ? (
country_code ? (
<span className="text-[12px] text-muted-foreground">
{getUnicodeFlagIcon(country_code)}
</span>
) : (
<span className="text-[12px] text-muted-foreground">🏴</span>
)
) : null}
<span className="h-2 w-2 shrink-0 rounded-full bg-red-500"></span> <span className="h-2 w-2 shrink-0 rounded-full bg-red-500"></span>
<p className="text-sm font-bold tracking-tight">{name}</p> <p
className={cn(
"break-all font-bold tracking-tight",
showFlag ? "text-xs" : "text-sm",
)}
>
{name}
</p>
</section> </section>
</PopoverTrigger> </PopoverTrigger>
<PopoverContent className="w-fit p-2" side="top"> <PopoverContent className="w-fit p-2" side="top">

View File

@ -0,0 +1,40 @@
"use client";
import { Moon, Sun } from "lucide-react";
import { useTheme } from "next-themes";
import * as React from "react";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
export function ModeToggle() {
const { setTheme } = useTheme();
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="sm" className="rounded-full px-[9px]">
<Sun className="h-4 w-4 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
<Moon className="absolute h-4 w-4 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={() => setTheme("light")}>
Light
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("dark")}>
Dark
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme("system")}>
System
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}

View File

@ -15,6 +15,7 @@ export function formatNezhaInfo(serverInfo: NezhaAPISafe) {
online: serverInfo.online_status, online: serverInfo.online_status,
mem: (serverInfo.status.MemUsed / serverInfo.host.MemTotal) * 100, mem: (serverInfo.status.MemUsed / serverInfo.host.MemTotal) * 100,
stg: (serverInfo.status.DiskUsed / serverInfo.host.DiskTotal) * 100, stg: (serverInfo.status.DiskUsed / serverInfo.host.DiskTotal) * 100,
country_code: serverInfo.host.CountryCode,
}; };
} }

View File

@ -22,6 +22,7 @@
"@typescript-eslint/eslint-plugin": "^7.5.0", "@typescript-eslint/eslint-plugin": "^7.5.0",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"clsx": "^2.1.0", "clsx": "^2.1.0",
"country-flag-icons": "^1.5.13",
"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",