diff --git a/.prettierrc.json b/.prettierrc.json index 55490b2..afdf6ef 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,7 +1,7 @@ { "semi": false, "singleQuote": false, - "printWidth": 100, + "printWidth": 150, "tabWidth": 2, "trailingComma": "all", "importOrder": ["^@core/(.*)$", "^@server/(.*)$", "^@ui/(.*)$", "^[./]"], diff --git a/index.html b/index.html index cd0b344..f2114e7 100644 --- a/index.html +++ b/index.html @@ -80,9 +80,7 @@ } if (theme === "system") { - const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches - ? "dark" - : "light" + const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" setTheme(systemTheme) window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", (e) => { @@ -110,14 +108,8 @@ 哪吒监控 Nezha Monitoring - - + +
diff --git a/src/App.tsx b/src/App.tsx index 836a40e..ceee40e 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -41,18 +41,30 @@ const App: React.FC = () => { } const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined + const customMobileBackgroundImage = + // @ts-expect-error CustomMobileBackgroundImage is a global variable + (window.CustomMobileBackgroundImage as string) !== "" ? window.CustomMobileBackgroundImage : undefined + return ( {/* 固定定位的背景层 */} {customBackgroundImage && (
)} + {customMobileBackgroundImage && ( +
+ )}
= ({ - cycleStats, - className, -}) => { +export const CycleTransferStatsCard: React.FC = ({ cycleStats, className }) => { return (
{Object.entries(cycleStats).map(([cycleId, cycleData]) => { diff --git a/src/components/CycleTransferStatsClient.tsx b/src/components/CycleTransferStatsClient.tsx index aa4f66a..6b0ab39 100644 --- a/src/components/CycleTransferStatsClient.tsx +++ b/src/components/CycleTransferStatsClient.tsx @@ -20,17 +20,10 @@ interface CycleTransferStatsClientProps { className?: string } -export const CycleTransferStatsClient: React.FC = ({ - name, - from, - to, - max, - serverStats, - className, -}) => { +export const CycleTransferStatsClient: React.FC = ({ name, from, to, max, serverStats, className }) => { const { t } = useTranslation() const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined return (
= return (
-
- {name} -
+
{name}
{new Date(from).toLocaleDateString()} - {new Date(to).toLocaleDateString()} @@ -63,21 +54,12 @@ export const CycleTransferStatsClient: React.FC =

{progress.toFixed(0)}%

- +
-
+
diff --git a/src/components/Footer.tsx b/src/components/Footer.tsx index ebbbebf..47d0844 100644 --- a/src/components/Footer.tsx +++ b/src/components/Footer.tsx @@ -29,9 +29,7 @@ const Footer: React.FC = () => { nezha-dash - {import.meta.env.VITE_GIT_HASH && ( - ({import.meta.env.VITE_GIT_HASH}) - )} + {import.meta.env.VITE_GIT_HASH && ({import.meta.env.VITE_GIT_HASH})}

diff --git a/src/components/GlobalMap.tsx b/src/components/GlobalMap.tsx index fa4bf02..8b02150 100644 --- a/src/components/GlobalMap.tsx +++ b/src/components/GlobalMap.tsx @@ -27,9 +27,7 @@ export default function GlobalMap({ serverList, now }: { serverList: NezhaServer const height = 500 const geoJson = JSON.parse(geoJsonString) - const filteredFeatures = geoJson.features.filter( - (feature: { properties: { iso_a3_eh: string } }) => feature.properties.iso_a3_eh !== "", - ) + const filteredFeatures = geoJson.features.filter((feature: { properties: { iso_a3_eh: string } }) => feature.properties.iso_a3_eh !== "") return (
@@ -68,15 +66,7 @@ interface InteractiveMapProps { now: number } -export function InteractiveMap({ - countries, - serverCounts, - width, - height, - filteredFeatures, - nezhaServerList, - now, -}: InteractiveMapProps) { +export function InteractiveMap({ countries, serverCounts, width, height, filteredFeatures, nezhaServerList, now }: InteractiveMapProps) { const { setTooltipData } = useTooltip() const projection = geoEquirectangular() @@ -88,13 +78,7 @@ export function InteractiveMap({ return (
setTooltipData(null)}> - + @@ -102,14 +86,7 @@ export function InteractiveMap({ {/* Background rect to handle mouse events in empty areas */} - setTooltipData(null)} - /> + setTooltipData(null)} /> {filteredFeatures.map((feature, index) => { const isHighlighted = countries.includes(feature.properties.iso_a2_eh) @@ -132,9 +109,7 @@ export function InteractiveMap({ if (path.centroid(feature)) { const countryCode = feature.properties.iso_a2_eh const countryServers = nezhaServerList - .filter( - (server: NezhaServer) => server.country_code?.toUpperCase() === countryCode, - ) + .filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode) .map((server: NezhaServer) => ({ name: server.name, status: formatNezhaInfo(now, server).online, @@ -154,9 +129,7 @@ export function InteractiveMap({ {/* 渲染不在 filteredFeatures 中的国家标记点 */} {countries.map((countryCode) => { // 检查该国家是否已经在 filteredFeatures 中 - const isInFilteredFeatures = filteredFeatures.some( - (feature) => feature.properties.iso_a2_eh === countryCode, - ) + const isInFilteredFeatures = filteredFeatures.some((feature) => feature.properties.iso_a2_eh === countryCode) // 如果已经在 filteredFeatures 中,跳过 if (isInFilteredFeatures) return null @@ -174,10 +147,7 @@ export function InteractiveMap({ key={countryCode} onMouseEnter={() => { const countryServers = nezhaServerList - .filter( - (server: NezhaServer) => - server.country_code?.toUpperCase() === countryCode.toUpperCase(), - ) + .filter((server: NezhaServer) => server.country_code?.toUpperCase() === countryCode.toUpperCase()) .map((server: NezhaServer) => ({ name: server.name, status: formatNezhaInfo(now, server).online, diff --git a/src/components/GroupSwitch.tsx b/src/components/GroupSwitch.tsx index 1a10c40..54c8dec 100644 --- a/src/components/GroupSwitch.tsx +++ b/src/components/GroupSwitch.tsx @@ -11,17 +11,14 @@ export default function GroupSwitch({ setCurrentTab: (tab: string) => void }) { const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined return (
{tabs.map((tab: string) => (
setCurrentTab(tab)} className={cn( "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", - currentTab === tab - ? "text-black dark:text-white" - : "text-stone-400 dark:text-stone-500", + currentTab === tab ? "text-black dark:text-white" : "text-stone-400 dark:text-stone-500", )} > {currentTab === tab && ( diff --git a/src/components/Header.tsx b/src/components/Header.tsx index 62f10f0..0482abf 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -47,10 +47,7 @@ function Header() { return (
-
navigate("/")} - className="cursor-pointer flex items-center text-base font-medium" - > +
navigate("/")} className="cursor-pointer flex items-center text-base font-medium">
- {isLoading ? ( - - ) : ( - siteName || "NEZHA" - )} + {isLoading ? : siteName || "NEZHA"}

{customDesc}

@@ -125,9 +118,7 @@ function Overview() { }, []) const timeOption = DateTime.TIME_SIMPLE timeOption.hour12 = true - const [timeString, setTimeString] = useState( - DateTime.now().setLocale("en-US").toLocaleString(timeOption), - ) + const [timeString, setTimeString] = useState(DateTime.now().setLocale("en-US").toLocaleString(timeOption)) useInterval(() => { setTimeString(DateTime.now().setLocale("en-US").toLocaleString(timeOption)) }, 1000) diff --git a/src/components/LanguageSwitcher.tsx b/src/components/LanguageSwitcher.tsx index ceef459..4fabe9c 100644 --- a/src/components/LanguageSwitcher.tsx +++ b/src/components/LanguageSwitcher.tsx @@ -1,12 +1,7 @@ "use client" import { Button } from "@/components/ui/button" -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu" +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { cn } from "@/lib/utils" import { CheckCircleIcon } from "@heroicons/react/20/solid" import { useTranslation } from "react-i18next" @@ -15,7 +10,7 @@ export function LanguageSwitcher() { const { t, i18n } = useTranslation() const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined const locale = i18n.languages[0] @@ -47,11 +42,7 @@ export function LanguageSwitcher() { {localeItems.map((item) => ( - handleSelect(e, item.code)} - className={locale === item.code ? "bg-muted gap-3" : ""} - > + handleSelect(e, item.code)} className={locale === item.code ? "bg-muted gap-3" : ""}> {item.name} {locale === item.code && } ))} diff --git a/src/components/MapTooltip.tsx b/src/components/MapTooltip.tsx index 58dfa0e..c390f19 100644 --- a/src/components/MapTooltip.tsx +++ b/src/components/MapTooltip.tsx @@ -27,9 +27,7 @@ const MapTooltip = memo(function MapTooltip() { }} >
-

- {tooltipData.country === "China" ? "Mainland China" : tooltipData.country} -

+

{tooltipData.country === "China" ? "Mainland China" : tooltipData.country}

{tooltipData.count} {t("map.Servers")}

@@ -43,11 +41,7 @@ const MapTooltip = memo(function MapTooltip() { > {tooltipData.servers.map((server, index: number) => (
- + {server.name}
))} diff --git a/src/components/NetworkChart.tsx b/src/components/NetworkChart.tsx index 3067fdf..59cc3bb 100644 --- a/src/components/NetworkChart.tsx +++ b/src/components/NetworkChart.tsx @@ -1,14 +1,7 @@ "use client" import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card" -import { - ChartConfig, - ChartContainer, - ChartLegend, - ChartLegendContent, - ChartTooltip, - ChartTooltipContent, -} from "@/components/ui/chart" +import { ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent } from "@/components/ui/chart" import { fetchMonitor } from "@/lib/nezha-api" import { formatTime } from "@/lib/utils" import { formatRelativeTime } from "@/lib/utils" @@ -128,9 +121,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ onClick={() => handleButtonClick(key)} > {key} - - {chartData[key][chartData[key].length - 1].avg_delay.toFixed(2)}ms - + {chartData[key][chartData[key].length - 1].avg_delay.toFixed(2)}ms )), [chartDataKey, activeChart, chartData, handleButtonClick], @@ -138,16 +129,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ const chartLines = useMemo(() => { if (activeChart !== defaultChart) { - return ( - - ) + return } return chartDataKey.map((key) => ( { - const values = window - .map((w) => w[key]) - .filter((v) => v !== undefined && v !== null) as number[] + const values = window.map((w) => w[key]).filter((v) => v !== undefined && v !== null) as number[] if (values.length > 0) { const processed = processValues(values) @@ -237,9 +215,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ } }) } else { - const values = window - .map((w) => w.avg_delay) - .filter((v) => v !== undefined && v !== null) as number[] + const values = window.map((w) => w.avg_delay).filter((v) => v !== undefined && v !== null) as number[] if (values.length > 0) { const processed = processValues(values) @@ -263,9 +239,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({
- - {serverName} - + {serverName} {chartDataKey.length} {t("monitor.monitorCount")} @@ -291,13 +265,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({ interval={"preserveStartEnd"} tickFormatter={(value) => formatRelativeTime(value)} /> - `${value}ms`} - /> + `${value}ms`} /> {parsedData.planDataMod.bandwidth !== "" && ( -

+

{parsedData.planDataMod.bandwidth}

)} {parsedData.planDataMod.trafficVol !== "" && ( -

+

{parsedData.planDataMod.trafficVol}

)} {parsedData.planDataMod.IPv4 === "1" && (

IPv4

)} {parsedData.planDataMod.IPv6 === "1" && ( -

+

IPv6

)} {parsedData.planDataMod.networkRoute && ( -

+

{parsedData.planDataMod.networkRoute.split(",").map((route, index) => { - return ( - route + - (index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "|") - ) + return route + (index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "|") })}

)} @@ -68,9 +47,7 @@ export default function PlanInfo({ parsedData }: { parsedData: PublicNoteData }) return (

{extra}

diff --git a/src/components/RemainPercentBar.tsx b/src/components/RemainPercentBar.tsx index 0cb4d93..cd95674 100644 --- a/src/components/RemainPercentBar.tsx +++ b/src/components/RemainPercentBar.tsx @@ -2,13 +2,7 @@ import { cn } from "@/lib/utils" import { Progress } from "./ui/progress" -export default function RemainPercentBar({ - value, - className, -}: { - value: number - className?: string -}) { +export default function RemainPercentBar({ value, className }: { value: number; className?: string }) { return ( navigate(`/server/${serverInfo.id}`)} > -
+
-
+
{showFlag ? : null}
-

- {name} -

+

{name}

{parsedData?.billingDataMod && }
@@ -88,21 +64,13 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf

{t("serverCard.upload")}

- {up >= 1024 - ? `${(up / 1024).toFixed(2)}G/s` - : up >= 1 - ? `${up.toFixed(2)}M/s` - : `${(up * 1024).toFixed(2)}K/s`} + {up >= 1024 ? `${(up / 1024).toFixed(2)}G/s` : up >= 1 ? `${up.toFixed(2)}M/s` : `${(up * 1024).toFixed(2)}K/s`}

{t("serverCard.download")}

- {down >= 1024 - ? `${(down / 1024).toFixed(2)}G/s` - : down >= 1 - ? `${down.toFixed(2)}M/s` - : `${(down * 1024).toFixed(2)}K/s`} + {down >= 1024 ? `${(down / 1024).toFixed(2)}G/s` : down >= 1 ? `${down.toFixed(2)}M/s` : `${(down * 1024).toFixed(2)}K/s`}
@@ -136,25 +104,13 @@ export default function ServerCard({ now, serverInfo }: { now: number; serverInf )} onClick={() => navigate(`/server/${serverInfo.id}`, { replace: true })} > -
+
-
+
{showFlag ? : null}
-

- {name} -

+

{name}

{parsedData?.billingDataMod && }
diff --git a/src/components/ServerCardInline.tsx b/src/components/ServerCardInline.tsx index 3a2a8cc..e3751f5 100644 --- a/src/components/ServerCardInline.tsx +++ b/src/components/ServerCardInline.tsx @@ -12,35 +12,18 @@ import BillingInfo from "./billingInfo" import { Card } from "./ui/card" import { Separator } from "./ui/separator" -export default function ServerCardInline({ - now, - serverInfo, -}: { - now: number - serverInfo: NezhaServer -}) { +export default function ServerCardInline({ now, serverInfo }: { now: number; serverInfo: NezhaServer }) { const { t } = useTranslation() const navigate = useNavigate() - const { - name, - country_code, - online, - cpu, - up, - down, - mem, - stg, - platform, - uptime, - net_in_transfer, - net_out_transfer, - public_note, - } = formatNezhaInfo(now, serverInfo) + const { name, country_code, online, cpu, up, down, mem, stg, platform, uptime, net_in_transfer, net_out_transfer, public_note } = formatNezhaInfo( + now, + serverInfo, + ) const showFlag = true const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined const parsedData = parsePublicNote(public_note) @@ -56,28 +39,13 @@ export default function ServerCardInline({ )} onClick={() => navigate(`/server/${serverInfo.id}`)} > -
+
-
+
{showFlag ? : null}
-

- {name} -

+

{name}

{parsedData?.billingDataMod && }
@@ -94,9 +62,7 @@ export default function ServerCardInline({

{t("serverCard.system")}

-
- {platform.includes("Windows") ? "Windows" : GetOsName(platform)} -
+
{platform.includes("Windows") ? "Windows" : GetOsName(platform)}
@@ -125,34 +91,22 @@ export default function ServerCardInline({

{t("serverCard.upload")}

- {up >= 1024 - ? `${(up / 1024).toFixed(2)}G/s` - : up >= 1 - ? `${up.toFixed(2)}M/s` - : `${(up * 1024).toFixed(2)}K/s`} + {up >= 1024 ? `${(up / 1024).toFixed(2)}G/s` : up >= 1 ? `${up.toFixed(2)}M/s` : `${(up * 1024).toFixed(2)}K/s`}

{t("serverCard.download")}

- {down >= 1024 - ? `${(down / 1024).toFixed(2)}G/s` - : up >= 1 - ? `${down.toFixed(2)}M/s` - : `${(down * 1024).toFixed(2)}K/s`} + {down >= 1024 ? `${(down / 1024).toFixed(2)}G/s` : up >= 1 ? `${down.toFixed(2)}M/s` : `${(down * 1024).toFixed(2)}K/s`}

{t("serverCard.totalUpload")}

-
- {formatBytes(net_out_transfer)} -
+
{formatBytes(net_out_transfer)}

{t("serverCard.totalDownload")}

-
- {formatBytes(net_in_transfer)} -
+
{formatBytes(net_in_transfer)}
{parsedData?.planDataMod && } @@ -169,25 +123,13 @@ export default function ServerCardInline({ )} onClick={() => navigate(`/server/${serverInfo.id}`)} > -
+
-
+
{showFlag ? : null}
-

- {name} -

+

{name}

{parsedData?.billingDataMod && }
diff --git a/src/components/ServerDetailChart.tsx b/src/components/ServerDetailChart.tsx index 98496e2..4dca62a 100644 --- a/src/components/ServerDetailChart.tsx +++ b/src/components/ServerDetailChart.tsx @@ -81,13 +81,9 @@ export default function ServerDetailChart({ server_id }: { server_id: string })
{gpuStats.length >= 1 && gpuList.length === gpuStats.length ? ( - gpuList.map((gpu, index) => ( - - )) + gpuList.map((gpu, index) => ) ) : gpuStats.length > 0 ? ( - gpuStats.map((gpu, index) => ( - - )) + gpuStats.map((gpu, index) => ) ) : ( <> )} @@ -139,13 +135,7 @@ function GpuChart({ now, gpuStat, gpuName }: { now: number; gpuStat: number; gpu

{gpuStat.toFixed(2)}%

- +
@@ -168,22 +158,8 @@ function GpuChart({ now, gpuStat, gpuName }: { now: number; gpuStat: number; gpu interval="preserveStartEnd" tickFormatter={(value) => formatRelativeTime(value)} /> - `${value}%`} - /> - + `${value}%`} /> +
@@ -230,13 +206,7 @@ function CpuChart({ now, data }: { now: number; data: NezhaServer }) {

CPU

{cpu.toFixed(2)}%

- +
@@ -259,22 +229,8 @@ function CpuChart({ now, data }: { now: number; data: NezhaServer }) { interval="preserveStartEnd" tickFormatter={(value) => formatRelativeTime(value)} /> - `${value}%`} - /> - + `${value}%`} /> + @@ -404,26 +360,14 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) {

{t("serverDetailChart.mem")}

- +

{mem.toFixed(0)}%

{t("serverDetailChart.swap")}

- +

{swap.toFixed(0)}%

@@ -463,22 +407,8 @@ function MemChart({ now, data }: { now: number; data: NezhaServer }) { interval="preserveStartEnd" tickFormatter={(value) => formatRelativeTime(value)} /> - `${value}%`} - /> - + `${value}%`} /> +

{disk.toFixed(0)}%

- +
{formatBytes(data.state.disk_used)} / {formatBytes(data.host.disk_total)} @@ -568,22 +492,8 @@ function DiskChart({ now, data }: { now: number; data: NezhaServer }) { interval="preserveStartEnd" tickFormatter={(value) => formatRelativeTime(value)} /> - `${value}%`} - /> - + `${value}%`} /> + @@ -643,11 +553,7 @@ function NetworkChart({ now, data }: { now: number; data: NezhaServer }) {

- {up >= 1024 - ? `${(up / 1024).toFixed(2)}G/s` - : up >= 1 - ? `${up.toFixed(2)}M/s` - : `${(up * 1024).toFixed(2)}K/s`} + {up >= 1024 ? `${(up / 1024).toFixed(2)}G/s` : up >= 1 ? `${up.toFixed(2)}M/s` : `${(up * 1024).toFixed(2)}K/s`}

@@ -656,11 +562,7 @@ function NetworkChart({ now, data }: { now: number; data: NezhaServer }) {

- {down >= 1024 - ? `${(down / 1024).toFixed(2)}G/s` - : down >= 1 - ? `${down.toFixed(2)}M/s` - : `${(down * 1024).toFixed(2)}K/s`} + {down >= 1024 ? `${(down / 1024).toFixed(2)}G/s` : down >= 1 ? `${down.toFixed(2)}M/s` : `${(down * 1024).toFixed(2)}K/s`}

@@ -697,22 +599,8 @@ function NetworkChart({ now, data }: { now: number; data: NezhaServer }) { domain={[1, maxDownload]} tickFormatter={(value) => `${value.toFixed(0)}M/s`} /> - - + + @@ -796,30 +684,9 @@ function ConnectChart({ now, data }: { now: number; data: NezhaServer }) { interval="preserveStartEnd" tickFormatter={(value) => formatRelativeTime(value)} /> - - - + + + diff --git a/src/components/ServerDetailOverview.tsx b/src/components/ServerDetailOverview.tsx index b89e179..ca9c6b3 100644 --- a/src/components/ServerDetailOverview.tsx +++ b/src/components/ServerDetailOverview.tsx @@ -70,13 +70,10 @@ export default function ServerDetailOverview({ server_id }: { server_id: string

{t("serverDetail.status")}

{online ? t("serverDetail.online") : t("serverDetail.offline")} @@ -146,9 +143,7 @@ export default function ServerDetailOverview({ server_id }: { server_id: string

{t("serverDetail.region")}

{country_code?.toUpperCase()}
- {country_code && ( - - )} + {country_code && }
@@ -235,15 +230,12 @@ export default function ServerDetailOverview({ server_id }: { server_id: string
- - {t("serverDetail.temperature")} - + {t("serverDetail.temperature")}
{server?.state.temperatures.map((item, index) => (
-

{item.Name}

: {item.Temperature.toFixed(2)}{" "} - °C +

{item.Name}

: {item.Temperature.toFixed(2)} °C
))}
@@ -259,9 +251,7 @@ export default function ServerDetailOverview({ server_id }: { server_id: string

{t("serverDetail.lastActive")}

-
- {last_active_time_string ? last_active_time_string : "N/A"} -
+
{last_active_time_string ? last_active_time_string : "N/A"}
diff --git a/src/components/ServerFlag.tsx b/src/components/ServerFlag.tsx index 8a2d786..d40e7ff 100644 --- a/src/components/ServerFlag.tsx +++ b/src/components/ServerFlag.tsx @@ -2,13 +2,7 @@ import { cn } from "@/lib/utils" import getUnicodeFlagIcon from "country-flag-icons/unicode" import { useEffect, useState } from "react" -export default function ServerFlag({ - country_code, - className, -}: { - country_code: string - className?: string -}) { +export default function ServerFlag({ country_code, className }: { country_code: string; className?: string }) { const [supportsEmojiFlags, setSupportsEmojiFlags] = useState(false) useEffect(() => { @@ -37,11 +31,7 @@ export default function ServerFlag({ return ( - {!supportsEmojiFlags ? ( - - ) : ( - getUnicodeFlagIcon(country_code) - )} + {!supportsEmojiFlags ? : getUnicodeFlagIcon(country_code)} ) } diff --git a/src/components/ServerOverview.tsx b/src/components/ServerOverview.tsx index 86f688d..f6e5e9d 100644 --- a/src/components/ServerOverview.tsx +++ b/src/components/ServerOverview.tsx @@ -15,15 +15,7 @@ type ServerOverviewProps = { downSpeed: number } -export default function ServerOverview({ - online, - offline, - total, - up, - down, - upSpeed, - downSpeed, -}: ServerOverviewProps) { +export default function ServerOverview({ online, offline, total, up, down, upSpeed, downSpeed }: ServerOverviewProps) { const { t } = useTranslation() const { status, setStatus } = useStatus() @@ -34,7 +26,7 @@ export default function ServerOverview({ const customIllustration = window.CustomIllustration || "/animated-man.webp" const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined return ( @@ -76,9 +68,7 @@ export default function ServerOverview({ >
-

- {t("serverOverview.onlineServers")} -

+

{t("serverOverview.onlineServers")}

@@ -106,9 +96,7 @@ export default function ServerOverview({ >
-

- {t("serverOverview.offlineServers")} -

+

{t("serverOverview.offlineServers")}

@@ -130,12 +118,8 @@ export default function ServerOverview({

{t("serverOverview.network")}

-

- ↑{formatBytes(up)} -

-

- ↓{formatBytes(down)} -

+

↑{formatBytes(up)}

+

↓{formatBytes(down)}

diff --git a/src/components/ServiceTracker.tsx b/src/components/ServiceTracker.tsx index 6784c89..16ccc42 100644 --- a/src/components/ServiceTracker.tsx +++ b/src/components/ServiceTracker.tsx @@ -26,14 +26,10 @@ export const ServiceTracker: React.FC = () => { })) const totalUp = serviceData.up.reduce((a, b) => a + b, 0) - const totalChecks = - serviceData.up.reduce((a, b) => a + b, 0) + serviceData.down.reduce((a, b) => a + b, 0) + const totalChecks = serviceData.up.reduce((a, b) => a + b, 0) + serviceData.down.reduce((a, b) => a + b, 0) const uptime = (totalUp / totalChecks) * 100 - const avgDelay = - serviceData.delay.length > 0 - ? serviceData.delay.reduce((a, b) => a + b, 0) / serviceData.delay.length - : 0 + const avgDelay = serviceData.delay.length > 0 ? serviceData.delay.reduce((a, b) => a + b, 0) / serviceData.delay.length : 0 return { days, uptime, avgDelay } } @@ -67,15 +63,7 @@ export const ServiceTracker: React.FC = () => {

{Object.entries(serviceData.data.services).map(([name, data]) => { const { days, uptime, avgDelay } = processServiceData(data) - return ( - - ) + return })}
)} diff --git a/src/components/ServiceTrackerClient.tsx b/src/components/ServiceTrackerClient.tsx index 47ef5e5..44eb1d9 100644 --- a/src/components/ServiceTrackerClient.tsx +++ b/src/components/ServiceTrackerClient.tsx @@ -15,16 +15,10 @@ interface ServiceTrackerProps { avgDelay?: number } -export const ServiceTrackerClient: React.FC = ({ - days, - className, - title, - uptime = 100, - avgDelay = 0, -}) => { +export const ServiceTrackerClient: React.FC = ({ days, className, title, uptime = 100, avgDelay = 0 }) => { const { t } = useTranslation() const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined return (
= ({ {title}
- - {avgDelay.toFixed(0)}ms - + {avgDelay.toFixed(0)}ms {uptime.toFixed(1)}% {t("serviceTracker.uptime")} @@ -58,10 +50,7 @@ export const ServiceTrackerClient: React.FC = ({ {days.map((day, index) => (
))} diff --git a/src/components/TabSwitch.tsx b/src/components/TabSwitch.tsx index 1438413..8308e33 100644 --- a/src/components/TabSwitch.tsx +++ b/src/components/TabSwitch.tsx @@ -2,28 +2,17 @@ import { cn } from "@/lib/utils" import { m } from "framer-motion" import { useTranslation } from "react-i18next" -export default function TabSwitch({ - tabs, - currentTab, - setCurrentTab, -}: { - tabs: string[] - currentTab: string - setCurrentTab: (tab: string) => void -}) { +export default function TabSwitch({ tabs, currentTab, setCurrentTab }: { tabs: string[]; currentTab: string; setCurrentTab: (tab: string) => void }) { const { t } = useTranslation() const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined return (
{tabs.map((tab: string) => (
setCurrentTab(tab)} className={cn( "relative cursor-pointer rounded-3xl px-2.5 py-[8px] text-[13px] font-[600] transition-all duration-500", - currentTab === tab - ? "text-black dark:text-white" - : "text-stone-400 dark:text-stone-500", + currentTab === tab ? "text-black dark:text-white" : "text-stone-400 dark:text-stone-500", )} > {currentTab === tab && ( diff --git a/src/components/ThemeProvider.tsx b/src/components/ThemeProvider.tsx index 44b1c70..000d8f6 100644 --- a/src/components/ThemeProvider.tsx +++ b/src/components/ThemeProvider.tsx @@ -21,9 +21,7 @@ const initialState: ThemeProviderState = { const ThemeProviderContext = createContext(initialState) export function ThemeProvider({ children, storageKey = "vite-ui-theme" }: ThemeProviderProps) { - const [theme, setTheme] = useState( - () => (localStorage.getItem(storageKey) as Theme) || "system", - ) + const [theme, setTheme] = useState(() => (localStorage.getItem(storageKey) as Theme) || "system") useEffect(() => { const root = window.document.documentElement @@ -31,9 +29,7 @@ export function ThemeProvider({ children, storageKey = "vite-ui-theme" }: ThemeP root.classList.remove("light", "dark") if (theme === "system") { - const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches - ? "dark" - : "light" + const systemTheme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light" root.classList.add(systemTheme) const themeColor = systemTheme === "dark" ? "hsl(30 15% 8%)" : "hsl(0 0% 98%)" diff --git a/src/components/ThemeSwitcher.tsx b/src/components/ThemeSwitcher.tsx index 14e7fd6..76c32e2 100644 --- a/src/components/ThemeSwitcher.tsx +++ b/src/components/ThemeSwitcher.tsx @@ -1,11 +1,6 @@ import { Theme } from "@/components/ThemeProvider" import { Button } from "@/components/ui/button" -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu" +import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu" import { cn } from "@/lib/utils" import { CheckCircleIcon } from "@heroicons/react/20/solid" import { Moon, Sun } from "lucide-react" @@ -18,7 +13,7 @@ export function ModeToggle() { const { setTheme, theme } = useTheme() const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined const handleSelect = (e: Event, newTheme: Theme) => { @@ -42,24 +37,15 @@ export function ModeToggle() { - handleSelect(e, "light")} - > + handleSelect(e, "light")}> {t("theme.light")} {theme === "light" && } - handleSelect(e, "dark")} - > + handleSelect(e, "dark")}> {t("theme.dark")} {theme === "dark" && } - handleSelect(e, "system")} - > + handleSelect(e, "system")}> {t("theme.system")} {theme === "system" && } diff --git a/src/components/billingInfo.tsx b/src/components/billingInfo.tsx index 9a0affa..7836cba 100644 --- a/src/components/billingInfo.tsx +++ b/src/components/billingInfo.tsx @@ -24,12 +24,8 @@ export default function BillingInfo({ parsedData }: { parsedData: PublicNoteData return daysLeftObject.days >= 0 ? ( <> -
- 剩余时间: {isNeverExpire ? "永久" : daysLeftObject.days + "天"} -
- {parsedData.billingDataMod.amount && - parsedData.billingDataMod.amount !== "0" && - parsedData.billingDataMod.amount !== "-1" ? ( +
剩余时间: {isNeverExpire ? "永久" : daysLeftObject.days + "天"}
+ {parsedData.billingDataMod.amount && parsedData.billingDataMod.amount !== "0" && parsedData.billingDataMod.amount !== "-1" ? (

价格: {parsedData.billingDataMod.amount}/{parsedData.billingDataMod.cycle}

@@ -42,12 +38,8 @@ export default function BillingInfo({ parsedData }: { parsedData: PublicNoteData ) : ( <> -

- 已过期: {daysLeftObject.days * -1} 天 -

- {parsedData.billingDataMod.amount && - parsedData.billingDataMod.amount !== "0" && - parsedData.billingDataMod.amount !== "-1" ? ( +

已过期: {daysLeftObject.days * -1} 天

+ {parsedData.billingDataMod.amount && parsedData.billingDataMod.amount !== "0" && parsedData.billingDataMod.amount !== "-1" ? (

价格: {parsedData.billingDataMod.amount}/{parsedData.billingDataMod.cycle}

diff --git a/src/components/ui/accordion.tsx b/src/components/ui/accordion.tsx index ee72507..df64af7 100644 --- a/src/components/ui/accordion.tsx +++ b/src/components/ui/accordion.tsx @@ -8,9 +8,7 @@ const Accordion = AccordionPrimitive.Root const AccordionItem = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) +>(({ className, ...props }, ref) => ) AccordionItem.displayName = "AccordionItem" const AccordionTrigger = React.forwardRef< diff --git a/src/components/ui/animated-circular-progress-bar.tsx b/src/components/ui/animated-circular-progress-bar.tsx index a98f992..0df5380 100644 --- a/src/components/ui/animated-circular-progress-bar.tsx +++ b/src/components/ui/animated-circular-progress-bar.tsx @@ -8,13 +8,7 @@ interface Props { primaryColor?: string } -export default function AnimatedCircularProgressBar({ - max = 100, - min = 0, - value = 0, - primaryColor, - className, -}: Props) { +export default function AnimatedCircularProgressBar({ max = 100, min = 0, value = 0, primaryColor, className }: Props) { const circumference = 2 * Math.PI * 45 const percentPx = circumference / 100 const currentPercent = ((value - min) / (max - min)) * 100 @@ -52,10 +46,8 @@ export default function AnimatedCircularProgressBar({ { "--stroke-percent": 90 - currentPercent, "--offset-factor-secondary": "calc(1 - var(--offset-factor))", - strokeDasharray: - "calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference)", - transform: - "rotate(calc(1turn - 90deg - (var(--gap-percent) * var(--percent-to-deg) * var(--offset-factor-secondary)))) scaleY(-1)", + strokeDasharray: "calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference)", + transform: "rotate(calc(1turn - 90deg - (var(--gap-percent) * var(--percent-to-deg) * var(--offset-factor-secondary)))) scaleY(-1)", transition: "all var(--transition-length) ease var(--delay)", transformOrigin: "calc(var(--circle-size) / 2) calc(var(--circle-size) / 2)", } as React.CSSProperties @@ -77,13 +69,10 @@ export default function AnimatedCircularProgressBar({ { "--stroke-primary-color": primaryColor, "--stroke-percent": currentPercent, - strokeDasharray: - "calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference)", - transition: - "var(--transition-length) ease var(--delay),stroke var(--transition-length) ease var(--delay)", + strokeDasharray: "calc(var(--stroke-percent) * var(--percent-to-px)) var(--circumference)", + transition: "var(--transition-length) ease var(--delay),stroke var(--transition-length) ease var(--delay)", transitionProperty: "stroke-dasharray,transform", - transform: - "rotate(calc(-90deg + var(--gap-percent) * var(--offset-factor) * var(--percent-to-deg)))", + transform: "rotate(calc(-90deg + var(--gap-percent) * var(--offset-factor) * var(--percent-to-deg)))", transformOrigin: "calc(var(--circle-size) / 2) calc(var(--circle-size) / 2)", } as React.CSSProperties } diff --git a/src/components/ui/badge.tsx b/src/components/ui/badge.tsx index 020ed14..cf62176 100644 --- a/src/components/ui/badge.tsx +++ b/src/components/ui/badge.tsx @@ -8,10 +8,8 @@ const badgeVariants = cva( variants: { variant: { default: "border-transparent bg-primary text-primary-foreground hover:bg-primary/80", - secondary: - "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", - destructive: - "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", + secondary: "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80", + destructive: "border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80", outline: "text-foreground", }, }, @@ -21,9 +19,7 @@ const badgeVariants = cva( }, ) -export interface BadgeProps - extends React.HTMLAttributes, - VariantProps {} +export interface BadgeProps extends React.HTMLAttributes, VariantProps {} function Badge({ className, variant, ...props }: BadgeProps) { return
diff --git a/src/components/ui/button.tsx b/src/components/ui/button.tsx index 94c642a..17248c8 100644 --- a/src/components/ui/button.tsx +++ b/src/components/ui/button.tsx @@ -29,20 +29,14 @@ const buttonVariants = cva( }, ) -export interface ButtonProps - extends React.ButtonHTMLAttributes, - VariantProps { +export interface ButtonProps extends React.ButtonHTMLAttributes, VariantProps { asChild?: boolean } -const Button = React.forwardRef( - ({ className, variant, size, asChild = false, ...props }, ref) => { - const Comp = asChild ? Slot : "button" - return ( - - ) - }, -) +const Button = React.forwardRef(({ className, variant, size, asChild = false, ...props }, ref) => { + const Comp = asChild ? Slot : "button" + return +}) Button.displayName = "Button" export { Button, buttonVariants } diff --git a/src/components/ui/card.tsx b/src/components/ui/card.tsx index cda8e0a..1baf02f 100644 --- a/src/components/ui/card.tsx +++ b/src/components/ui/card.tsx @@ -1,58 +1,38 @@ import { cn } from "@/lib/utils" import * as React from "react" -const Card = React.forwardRef>( - ({ className, ...props }, ref) => ( -
- ), -) +const Card = React.forwardRef>(({ className, ...props }, ref) => ( +
+)) Card.displayName = "Card" -const CardHeader = React.forwardRef>( - ({ className, ...props }, ref) => ( -
- ), -) +const CardHeader = React.forwardRef>(({ className, ...props }, ref) => ( +
+)) CardHeader.displayName = "CardHeader" -const CardTitle = React.forwardRef>( - ({ className, ...props }, ref) => ( -

- ), -) +const CardTitle = React.forwardRef>(({ className, ...props }, ref) => ( +

+)) CardTitle.displayName = "CardTitle" -const CardDescription = React.forwardRef< - HTMLParagraphElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( +const CardDescription = React.forwardRef>(({ className, ...props }, ref) => (

)) CardDescription.displayName = "CardDescription" -const CardContent = React.forwardRef>( - ({ className, ...props }, ref) => ( -

- ), -) +const CardContent = React.forwardRef>(({ className, ...props }, ref) => ( +
+)) CardContent.displayName = "CardContent" -const CardFooter = React.forwardRef>( - ({ className, ...props }, ref) => ( -
- ), -) +const CardFooter = React.forwardRef>(({ className, ...props }, ref) => ( +
+)) CardFooter.displayName = "CardFooter" export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } diff --git a/src/components/ui/chart.tsx b/src/components/ui/chart.tsx index 787b312..17c44ab 100644 --- a/src/components/ui/chart.tsx +++ b/src/components/ui/chart.tsx @@ -9,10 +9,7 @@ export type ChartConfig = { [k in string]: { label?: React.ReactNode icon?: React.ComponentType - } & ( - | { color?: string; theme?: never } - | { color?: never; theme: Record } - ) + } & ({ color?: string; theme?: never } | { color?: never; theme: Record }) } type ChartContextProps = { @@ -130,15 +127,10 @@ const ChartTooltipContent = React.forwardRef< const [item] = payload const key = `${labelKey || item.dataKey || item.name || "value"}` const itemConfig = getPayloadConfigFromPayload(config, item, key) - const value = - !labelKey && typeof label === "string" - ? config[label as keyof typeof config]?.label || label - : itemConfig?.label + const value = !labelKey && typeof label === "string" ? config[label as keyof typeof config]?.label || label : itemConfig?.label if (labelFormatter) { - return ( -
{labelFormatter(value, payload)}
- ) + return
{labelFormatter(value, payload)}
} if (!value) { @@ -186,16 +178,12 @@ const ChartTooltipContent = React.forwardRef< ) : ( !hideIndicator && (
) )} -
+
{nestLabel ? tooltipLabel : null} - - {itemConfig?.label || item.name} - + {itemConfig?.label || item.name}
- {item.value && ( - - {item.value.toLocaleString()} - - )} + {item.value && {item.value.toLocaleString()}}
)} @@ -252,25 +229,13 @@ const ChartLegendContent = React.forwardRef< } return ( -
+
{payload.map((item) => { const key = `${nameKey || item.dataKey || "value"}` const itemConfig = getPayloadConfigFromPayload(config, item, key) return ( -
svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground", - )} - > +
svg]:h-3 [&>svg]:w-3 [&>svg]:text-muted-foreground")}> {itemConfig?.icon && !hideIcon ? ( ) : ( @@ -296,31 +261,17 @@ function getPayloadConfigFromPayload(config: ChartConfig, payload: unknown, key: return undefined } - const payloadPayload = - "payload" in payload && typeof payload.payload === "object" && payload.payload !== null - ? payload.payload - : undefined + const payloadPayload = "payload" in payload && typeof payload.payload === "object" && payload.payload !== null ? payload.payload : undefined let configLabelKey: string = key if (key in payload && typeof payload[key as keyof typeof payload] === "string") { configLabelKey = payload[key as keyof typeof payload] as string - } else if ( - payloadPayload && - key in payloadPayload && - typeof payloadPayload[key as keyof typeof payloadPayload] === "string" - ) { + } else if (payloadPayload && key in payloadPayload && typeof payloadPayload[key as keyof typeof payloadPayload] === "string") { configLabelKey = payloadPayload[key as keyof typeof payloadPayload] as string } return configLabelKey in config ? config[configLabelKey] : config[key as keyof typeof config] } -export { - ChartContainer, - ChartTooltip, - ChartTooltipContent, - ChartLegend, - ChartLegendContent, - ChartStyle, -} +export { ChartContainer, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, ChartStyle } diff --git a/src/components/ui/checkbox.tsx b/src/components/ui/checkbox.tsx index 1d3fd05..3fd5900 100644 --- a/src/components/ui/checkbox.tsx +++ b/src/components/ui/checkbox.tsx @@ -3,23 +3,22 @@ import * as CheckboxPrimitive from "@radix-ui/react-checkbox" import { Check } from "lucide-react" import * as React from "react" -const Checkbox = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - - - - -)) +const Checkbox = React.forwardRef, React.ComponentPropsWithoutRef>( + ({ className, ...props }, ref) => ( + + + + + + ), +) Checkbox.displayName = CheckboxPrimitive.Root.displayName export { Checkbox } diff --git a/src/components/ui/dialog.tsx b/src/components/ui/dialog.tsx index 7887930..a9739fe 100644 --- a/src/components/ui/dialog.tsx +++ b/src/components/ui/dialog.tsx @@ -56,46 +56,21 @@ const DialogHeader = ({ className, ...props }: React.HTMLAttributes) => ( -
+
) DialogFooter.displayName = "DialogFooter" -const DialogTitle = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) +const DialogTitle = React.forwardRef, React.ComponentPropsWithoutRef>( + ({ className, ...props }, ref) => ( + + ), +) DialogTitle.displayName = DialogPrimitive.Title.displayName const DialogDescription = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) +>(({ className, ...props }, ref) => ) DialogDescription.displayName = DialogPrimitive.Description.displayName -export { - Dialog, - DialogPortal, - DialogOverlay, - DialogClose, - DialogTrigger, - DialogContent, - DialogHeader, - DialogFooter, - DialogTitle, - DialogDescription, -} +export { Dialog, DialogPortal, DialogOverlay, DialogClose, DialogTrigger, DialogContent, DialogHeader, DialogFooter, DialogTitle, DialogDescription } diff --git a/src/components/ui/dropdown-menu.tsx b/src/components/ui/dropdown-menu.tsx index be700fb..6dd57f0 100644 --- a/src/components/ui/dropdown-menu.tsx +++ b/src/components/ui/dropdown-menu.tsx @@ -138,24 +138,14 @@ const DropdownMenuLabel = React.forwardRef< inset?: boolean } >(({ className, inset, ...props }, ref) => ( - + )) DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName const DropdownMenuSeparator = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - -)) +>(({ className, ...props }, ref) => ) DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName const DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes) => { diff --git a/src/components/ui/input.tsx b/src/components/ui/input.tsx index 8609d3e..7149a26 100644 --- a/src/components/ui/input.tsx +++ b/src/components/ui/input.tsx @@ -3,21 +3,19 @@ import * as React from "react" export interface InputProps extends React.InputHTMLAttributes {} -const Input = React.forwardRef( - ({ className, type, ...props }, ref) => { - return ( - - ) - }, -) +const Input = React.forwardRef(({ className, type, ...props }, ref) => { + return ( + + ) +}) Input.displayName = "Input" export { Input } diff --git a/src/components/ui/label.tsx b/src/components/ui/label.tsx index ed46b19..f3f0208 100644 --- a/src/components/ui/label.tsx +++ b/src/components/ui/label.tsx @@ -3,16 +3,12 @@ import * as LabelPrimitive from "@radix-ui/react-label" import { type VariantProps, cva } from "class-variance-authority" import * as React from "react" -const labelVariants = cva( - "text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70", -) +const labelVariants = cva("text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70") const Label = React.forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & VariantProps ->(({ className, ...props }, ref) => ( - -)) +>(({ className, ...props }, ref) => ) Label.displayName = LabelPrimitive.Root.displayName export { Label } diff --git a/src/components/ui/progress.tsx b/src/components/ui/progress.tsx index db6f7e6..c37320f 100644 --- a/src/components/ui/progress.tsx +++ b/src/components/ui/progress.tsx @@ -8,11 +8,7 @@ const Progress = React.forwardRef< indicatorClassName?: string } >(({ className, value, indicatorClassName, ...props }, ref) => ( - + , - React.ComponentPropsWithoutRef ->(({ className, orientation = "horizontal", decorative = true, ...props }, ref) => ( - -)) +const Separator = React.forwardRef, React.ComponentPropsWithoutRef>( + ({ className, orientation = "horizontal", decorative = true, ...props }, ref) => ( + + ), +) Separator.displayName = SeparatorPrimitive.Root.displayName export { Separator } diff --git a/src/components/ui/switch.tsx b/src/components/ui/switch.tsx index 1920d2e..7a59c05 100644 --- a/src/components/ui/switch.tsx +++ b/src/components/ui/switch.tsx @@ -2,25 +2,24 @@ import { cn } from "@/lib/utils" import * as SwitchPrimitives from "@radix-ui/react-switch" import * as React from "react" -const Switch = React.forwardRef< - React.ElementRef, - React.ComponentPropsWithoutRef ->(({ className, ...props }, ref) => ( - - , React.ComponentPropsWithoutRef>( + ({ className, ...props }, ref) => ( + - -)) + {...props} + ref={ref} + > + + + ), +) Switch.displayName = SwitchPrimitives.Root.displayName export { Switch } diff --git a/src/components/ui/table.tsx b/src/components/ui/table.tsx index ac5fd8b..68a695d 100644 --- a/src/components/ui/table.tsx +++ b/src/components/ui/table.tsx @@ -1,88 +1,48 @@ import { cn } from "@/lib/utils" import * as React from "react" -const Table = React.forwardRef>( - ({ className, ...props }, ref) => ( -
- - - ), -) +const Table = React.forwardRef>(({ className, ...props }, ref) => ( +
+
+ +)) Table.displayName = "Table" -const TableHeader = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( +const TableHeader = React.forwardRef>(({ className, ...props }, ref) => ( )) TableHeader.displayName = "TableHeader" -const TableBody = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( +const TableBody = React.forwardRef>(({ className, ...props }, ref) => ( )) TableBody.displayName = "TableBody" -const TableFooter = React.forwardRef< - HTMLTableSectionElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( - tr]:last:border-b-0", className)} - {...props} - /> +const TableFooter = React.forwardRef>(({ className, ...props }, ref) => ( + tr]:last:border-b-0", className)} {...props} /> )) TableFooter.displayName = "TableFooter" -const TableRow = React.forwardRef>( - ({ className, ...props }, ref) => ( - - ), -) +const TableRow = React.forwardRef>(({ className, ...props }, ref) => ( + +)) TableRow.displayName = "TableRow" -const TableHead = React.forwardRef< - HTMLTableCellElement, - React.ThHTMLAttributes ->(({ className, ...props }, ref) => ( +const TableHead = React.forwardRef>(({ className, ...props }, ref) => (
)) TableHead.displayName = "TableHead" -const TableCell = React.forwardRef< - HTMLTableCellElement, - React.TdHTMLAttributes ->(({ className, ...props }, ref) => ( - +const TableCell = React.forwardRef>(({ className, ...props }, ref) => ( + )) TableCell.displayName = "TableCell" -const TableCaption = React.forwardRef< - HTMLTableCaptionElement, - React.HTMLAttributes ->(({ className, ...props }, ref) => ( +const TableCaption = React.forwardRef>(({ className, ...props }, ref) => (
)) TableCaption.displayName = "TableCaption" diff --git a/src/context/sort-context.ts b/src/context/sort-context.ts index 2891400..62796f8 100644 --- a/src/context/sort-context.ts +++ b/src/context/sort-context.ts @@ -1,31 +1,8 @@ import { createContext } from "react" -export type SortType = - | "default" - | "name" - | "uptime" - | "system" - | "cpu" - | "mem" - | "stg" - | "up" - | "down" - | "up total" - | "down total" +export type SortType = "default" | "name" | "uptime" | "system" | "cpu" | "mem" | "stg" | "up" | "down" | "up total" | "down total" -export const SORT_TYPES: SortType[] = [ - "default", - "name", - "uptime", - "system", - "cpu", - "mem", - "stg", - "up", - "down", - "up total", - "down total", -] +export const SORT_TYPES: SortType[] = ["default", "name", "uptime", "system", "cpu", "mem", "stg", "up", "down", "up total", "down total"] export type SortOrder = "asc" | "desc" diff --git a/src/context/sort-provider.tsx b/src/context/sort-provider.tsx index a250fec..804f9a6 100644 --- a/src/context/sort-provider.tsx +++ b/src/context/sort-provider.tsx @@ -6,9 +6,5 @@ export function SortProvider({ children }: { children: ReactNode }) { const [sortType, setSortType] = useState("default") const [sortOrder, setSortOrder] = useState("desc") - return ( - - {children} - - ) + return {children} } diff --git a/src/context/tooltip-provider.tsx b/src/context/tooltip-provider.tsx index 0790246..7e8b6c0 100644 --- a/src/context/tooltip-provider.tsx +++ b/src/context/tooltip-provider.tsx @@ -5,9 +5,5 @@ import { TooltipContext, TooltipData } from "./tooltip-context" export function TooltipProvider({ children }: { children: ReactNode }) { const [tooltipData, setTooltipData] = useState(null) - return ( - - {children} - - ) + return {children} } diff --git a/src/lib/nezha-api.ts b/src/lib/nezha-api.ts index 3c4f504..0570d21 100644 --- a/src/lib/nezha-api.ts +++ b/src/lib/nezha-api.ts @@ -1,10 +1,4 @@ -import { - LoginUserResponse, - MonitorResponse, - ServerGroupResponse, - ServiceResponse, - SettingResponse, -} from "@/types/nezha-api" +import { LoginUserResponse, MonitorResponse, ServerGroupResponse, ServiceResponse, SettingResponse } from "@/types/nezha-api" export const fetchServerGroup = async (): Promise => { const response = await fetch("/api/v1/server-group") diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 05206dc..16bff0c 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -8,9 +8,7 @@ export function cn(...inputs: ClassValue[]) { } export function formatNezhaInfo(now: number, serverInfo: NezhaServer) { - const lastActiveTime = serverInfo.last_active.startsWith("000") - ? 0 - : parseISOTimestamp(serverInfo.last_active) + const lastActiveTime = serverInfo.last_active.startsWith("000") ? 0 : parseISOTimestamp(serverInfo.last_active) return { ...serverInfo, cpu: serverInfo.state.cpu || 0, @@ -47,12 +45,11 @@ export function formatNezhaInfo(now: number, serverInfo: NezhaServer) { } } -export function getDaysBetweenDatesWithAutoRenewal({ - autoRenewal, - cycle, - startDate, - endDate, -}: BillingData): { days: number; cycleLabel: string; remainingPercentage: number } { +export function getDaysBetweenDatesWithAutoRenewal({ autoRenewal, cycle, startDate, endDate }: BillingData): { + days: number + cycleLabel: string + remainingPercentage: number +} { let months = 1 // 套餐资费 let cycleLabel = cycle @@ -100,12 +97,9 @@ export function getDaysBetweenDatesWithAutoRenewal({ days: getDaysBetweenDates(endDate, new Date(nowTime).toISOString()), cycleLabel: cycleLabel, remainingPercentage: - getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) / - dayjs(endDate).diff(startDate, "day") > - 1 + getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) / dayjs(endDate).diff(startDate, "day") > 1 ? 1 - : getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) / - dayjs(endDate).diff(startDate, "day"), + : getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) / dayjs(endDate).diff(startDate, "day"), } } diff --git a/src/main.tsx b/src/main.tsx index ba8f264..f584633 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -30,8 +30,7 @@ ReactDOM.createRoot(document.getElementById("root")!).render( duration={1000} toastOptions={{ classNames: { - default: - "w-fit rounded-full px-2.5 py-1.5 bg-neutral-100 border border-neutral-200 backdrop-blur-xl shadow-none", + default: "w-fit rounded-full px-2.5 py-1.5 bg-neutral-100 border border-neutral-200 backdrop-blur-xl shadow-none", }, }} position="top-center" diff --git a/src/pages/Server.tsx b/src/pages/Server.tsx index bf10cc9..5f1053f 100644 --- a/src/pages/Server.tsx +++ b/src/pages/Server.tsx @@ -15,14 +15,7 @@ import { fetchServerGroup } from "@/lib/nezha-api" import { cn, formatNezhaInfo } from "@/lib/utils" import { NezhaWebsocketResponse } from "@/types/nezha-api" import { ServerGroup } from "@/types/nezha-api" -import { - ArrowDownIcon, - ArrowUpIcon, - ArrowsUpDownIcon, - ChartBarSquareIcon, - MapIcon, - ViewColumnsIcon, -} from "@heroicons/react/20/solid" +import { ArrowDownIcon, ArrowUpIcon, ArrowsUpDownIcon, ChartBarSquareIcon, MapIcon, ViewColumnsIcon } from "@heroicons/react/20/solid" import { useQuery } from "@tanstack/react-query" import { useEffect, useState } from "react" import { useTranslation } from "react-i18next" @@ -44,7 +37,7 @@ export default function Servers() { const [currentGroup, setCurrentGroup] = useState("All") const customBackgroundImage = - // @ts-expect-error ShowNetTransfer is a global variable + // @ts-expect-error CustomBackgroundImage is a global variable (window.CustomBackgroundImage as string) !== "" ? window.CustomBackgroundImage : undefined useEffect(() => { @@ -96,60 +89,40 @@ export default function Servers() { nezhaWsData?.servers?.filter((server) => { if (currentGroup === "All") return true const group = groupData?.data?.find( - (g: ServerGroup) => - g.group.name === currentGroup && - Array.isArray(g.servers) && - g.servers.includes(server.id), + (g: ServerGroup) => g.group.name === currentGroup && Array.isArray(g.servers) && g.servers.includes(server.id), ) return !!group }) || [] const totalServers = filteredServers.length || 0 - const onlineServers = - filteredServers.filter((server) => formatNezhaInfo(nezhaWsData.now, server).online)?.length || 0 - const offlineServers = - filteredServers.filter((server) => !formatNezhaInfo(nezhaWsData.now, server).online)?.length || - 0 + const onlineServers = filteredServers.filter((server) => formatNezhaInfo(nezhaWsData.now, server).online)?.length || 0 + const offlineServers = filteredServers.filter((server) => !formatNezhaInfo(nezhaWsData.now, server).online)?.length || 0 const up = filteredServers.reduce( - (total, server) => - formatNezhaInfo(nezhaWsData.now, server).online - ? total + (server.state?.net_out_transfer ?? 0) - : total, + (total, server) => (formatNezhaInfo(nezhaWsData.now, server).online ? total + (server.state?.net_out_transfer ?? 0) : total), 0, ) || 0 const down = filteredServers.reduce( - (total, server) => - formatNezhaInfo(nezhaWsData.now, server).online - ? total + (server.state?.net_in_transfer ?? 0) - : total, + (total, server) => (formatNezhaInfo(nezhaWsData.now, server).online ? total + (server.state?.net_in_transfer ?? 0) : total), 0, ) || 0 const upSpeed = filteredServers.reduce( - (total, server) => - formatNezhaInfo(nezhaWsData.now, server).online - ? total + (server.state?.net_out_speed ?? 0) - : total, + (total, server) => (formatNezhaInfo(nezhaWsData.now, server).online ? total + (server.state?.net_out_speed ?? 0) : total), 0, ) || 0 const downSpeed = filteredServers.reduce( - (total, server) => - formatNezhaInfo(nezhaWsData.now, server).online - ? total + (server.state?.net_in_speed ?? 0) - : total, + (total, server) => (formatNezhaInfo(nezhaWsData.now, server).online ? total + (server.state?.net_in_speed ?? 0) : total), 0, ) || 0 filteredServers = status === "all" ? filteredServers - : filteredServers.filter((server) => - [status].includes(formatNezhaInfo(nezhaWsData.now, server).online ? "online" : "offline"), - ) + : filteredServers.filter((server) => [status].includes(formatNezhaInfo(nezhaWsData.now, server).online ? "online" : "offline")) filteredServers = filteredServers.sort((a, b) => { const serverAInfo = formatNezhaInfo(nezhaWsData.now, a) @@ -277,17 +250,14 @@ export default function Servers() { className={cn( "rounded-[50px] flex items-center gap-1 dark:text-white border dark:border-none text-black cursor-pointer dark:[text-shadow:_0_1px_0_rgb(0_0_0_/_20%)] dark:bg-stone-800 bg-stone-100 p-[10px] transition-all shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] ", { - "shadow-[inset_0_1px_0_rgba(0,0,0,0.2)] dark:bg-stone-700 bg-stone-200": - settingsOpen, + "shadow-[inset_0_1px_0_rgba(0,0,0,0.2)] dark:bg-stone-700 bg-stone-200": settingsOpen, }, { "dark:bg-stone-800/50 bg-stone-100/50 ": customBackgroundImage, }, )} > -

- {sortType === "default" ? "Sort" : sortType.toUpperCase()} -

+

{sortType === "default" ? "Sort" : sortType.toUpperCase()}

{sortOrder === "asc" && sortType !== "default" ? ( ) : sortOrder === "desc" && sortType !== "default" ? ( @@ -309,8 +279,7 @@ export default function Servers() { className={cn( "rounded-[5px] text-[11px] w-fit px-1 py-0.5 cursor-pointer bg-transparent border transition-all dark:shadow-none ", { - "bg-black text-white dark:bg-white dark:text-black shadow-[inset_0_1px_0_rgba(255,255,255,0.2)]": - sortType === type, + "bg-black text-white dark:bg-white dark:text-black shadow-[inset_0_1px_0_rgba(255,255,255,0.2)]": sortType === type, }, )} > @@ -330,8 +299,7 @@ export default function Servers() { className={cn( "rounded-[5px] text-[11px] w-fit px-1 py-0.5 cursor-pointer bg-transparent border transition-all shadow-[inset_0_1px_0_rgba(255,255,255,0.2)] dark:shadow-none", { - "bg-black text-white dark:bg-white dark:text-black": - sortOrder === order && sortType !== "default", + "bg-black text-white dark:bg-white dark:text-black": sortOrder === order && sortType !== "default", }, )} > @@ -344,9 +312,7 @@ export default function Servers() { - {showMap === "1" && ( - - )} + {showMap === "1" && } {showServices === "1" && } {inline === "1" && (