init: 初始化

This commit is contained in:
Montia37
2025-08-13 04:32:05 +08:00
commit af6f7b1d09
343 changed files with 9919 additions and 0 deletions

42
src/hooks/usePingChart.ts Normal file
View File

@@ -0,0 +1,42 @@
import { useState, useEffect } from "react";
import { useNodeData } from "@/contexts/NodeDataContext";
import type { PingHistoryResponse, NodeData } from "@/types/node";
export const usePingChart = (node: NodeData | null, hours: number) => {
const { getPingHistory } = useNodeData();
const [pingHistory, setPingHistory] = useState<PingHistoryResponse | null>(
null
);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!node?.uuid) {
setPingHistory(null);
setLoading(false);
return;
}
setLoading(true);
setError(null);
const fetchHistory = async () => {
try {
const data = await getPingHistory(node.uuid, hours);
setPingHistory(data);
} catch (err: any) {
setError(err.message || "Failed to fetch history data");
} finally {
setLoading(false);
}
};
fetchHistory();
}, [node?.uuid, hours, getPingHistory]);
return {
loading,
error,
pingHistory,
};
};