fix: lint

This commit is contained in:
hamster1963 2024-11-23 19:34:14 +08:00
parent 3275ea9211
commit 2e06f22a86
4 changed files with 51 additions and 33 deletions

View File

@ -7,7 +7,6 @@ import { ReactQueryDevtools } from "@tanstack/react-query-devtools";
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { Toaster } from "sonner";
const queryClient = new QueryClient();
ReactDOM.createRoot(document.getElementById("root")!).render(

View File

@ -1,11 +1,11 @@
import useWebSocket from 'react-use-websocket';
import useWebSocket from "react-use-websocket";
import { NezhaAPIResponse } from "@/types/nezha-api";
import ServerCard from '@/components/ServerCard';
import { formatNezhaInfo } from '@/lib/utils';
import ServerOverview from '@/components/ServerOverview';
import ServerCard from "@/components/ServerCard";
import { formatNezhaInfo } from "@/lib/utils";
import ServerOverview from "@/components/ServerOverview";
export default function Servers() {
const { lastMessage, readyState } = useWebSocket('/api/v1/ws/server', {
const { lastMessage, readyState } = useWebSocket("/api/v1/ws/server", {
shouldReconnect: () => true, // 自动重连
reconnectInterval: 3000, // 重连间隔
});
@ -16,25 +16,45 @@ export default function Servers() {
}
// 解析消息
const nezhaWsData = lastMessage ? JSON.parse(lastMessage.data) as NezhaAPIResponse : null;
const nezhaWsData = lastMessage
? (JSON.parse(lastMessage.data) as NezhaAPIResponse)
: null;
if (!nezhaWsData) {
return <div className='flex flex-col items-center justify-center '><p className='font-semibold text-sm'>...</p></div>;
return (
<div className="flex flex-col items-center justify-center ">
<p className="font-semibold text-sm">...</p>
</div>
);
}
// 计算服务器总数和在线数量
const totalServers = nezhaWsData.servers.length;
const onlineServers = nezhaWsData.servers.filter(server => formatNezhaInfo(server).online).length;
const offlineServers = nezhaWsData.servers.filter(server => !formatNezhaInfo(server).online).length;
const up = nezhaWsData.servers.reduce((total, server) => total + server.state.net_out_transfer, 0);
const down = nezhaWsData.servers.reduce((total, server) => total + server.state.net_in_transfer, 0);
const onlineServers = nezhaWsData.servers.filter(
(server) => formatNezhaInfo(server).online,
).length;
const offlineServers = nezhaWsData.servers.filter(
(server) => !formatNezhaInfo(server).online,
).length;
const up = nezhaWsData.servers.reduce(
(total, server) => total + server.state.net_out_transfer,
0,
);
const down = nezhaWsData.servers.reduce(
(total, server) => total + server.state.net_in_transfer,
0,
);
return (
<div className="mx-auto w-full max-w-5xl px-0">
<ServerOverview total={totalServers} online={onlineServers} offline={offlineServers} up={up} down={down} />
<section
className="grid grid-cols-1 gap-2 md:grid-cols-2 mt-6"
>
<ServerOverview
total={totalServers}
online={onlineServers}
offline={offlineServers}
up={up}
down={down}
/>
<section className="grid grid-cols-1 gap-2 md:grid-cols-2 mt-6">
{nezhaWsData.servers.map((serverInfo) => (
<ServerCard key={serverInfo.id} serverInfo={serverInfo} />
))}

View File

@ -3,7 +3,6 @@ export interface NezhaAPIResponse {
servers: NezhaAPI[];
}
export interface NezhaAPI {
id: number;
name: string;

View File

@ -12,11 +12,11 @@ export default defineConfig({
},
server: {
proxy: {
'/api/v1/ws/server': {
target: 'ws://localhost:8080',
"/api/v1/ws/server": {
target: "ws://localhost:8080",
changeOrigin: true,
ws: true,
},
}
}
},
},
});