Skip to content

Commit

Permalink
feat: gpu info
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 2, 2024
1 parent a4bdf10 commit 3d4bd79
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 24 deletions.
43 changes: 21 additions & 22 deletions src/components/NetworkChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,28 +111,27 @@ export const NetworkChartClient = React.memo(function NetworkChart({

const defaultChart = "All";

const [activeCharts, setActiveCharts] = React.useState<string[]>([defaultChart]);
const [activeCharts, setActiveCharts] = React.useState<string[]>([
defaultChart,
]);

const handleButtonClick = useCallback(
(chart: string) => {
setActiveCharts((prev) => {
if (chart === defaultChart) {
return [defaultChart];
}

const newCharts = prev.filter(c => c !== defaultChart);
const chartIndex = newCharts.indexOf(chart);

if (chartIndex === -1) {
return newCharts.length === 0 ? [chart] : [...newCharts, chart];
} else {
const result = newCharts.filter(c => c !== chart);
return result.length === 0 ? [defaultChart] : result;
}
});
},
[],
);
const handleButtonClick = useCallback((chart: string) => {
setActiveCharts((prev) => {
if (chart === defaultChart) {
return [defaultChart];
}

const newCharts = prev.filter((c) => c !== defaultChart);
const chartIndex = newCharts.indexOf(chart);

if (chartIndex === -1) {
return newCharts.length === 0 ? [chart] : [...newCharts, chart];
} else {
const result = newCharts.filter((c) => c !== chart);
return result.length === 0 ? [defaultChart] : result;
}
});
}, []);

const getColorByIndex = useCallback(
(chart: string) => {
Expand Down Expand Up @@ -177,7 +176,7 @@ export const NetworkChartClient = React.memo(function NetworkChart({
/>
));
}

return activeCharts.map((chart) => (
<Line
key={chart}
Expand Down
16 changes: 14 additions & 2 deletions src/components/ServerDetailOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,20 @@ export default function ServerDetailOverview({
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"CPU"}</p>
{server.host.cpu ? (
<div className="text-xs"> {server.host.cpu}</div>
{server.host.cpu.length > 0 ? (
<div className="text-xs"> {server.host.cpu.join(", ")}</div>
) : (
<div className="text-xs"> {t("serverDetail.unknown")}</div>
)}
</section>
</CardContent>
</Card>
<Card className="rounded-[10px] bg-transparent border-none shadow-none">
<CardContent className="px-1.5 py-1">
<section className="flex flex-col items-start gap-0.5">
<p className="text-xs text-muted-foreground">{"GPU"}</p>
{server.host.gpu.length > 0 ? (
<div className="text-xs">{server.host.gpu.join(", ")}</div>
) : (
<div className="text-xs"> {t("serverDetail.unknown")}</div>
)}
Expand Down
1 change: 1 addition & 0 deletions src/types/nezha-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface NezhaServerHost {
platform: string;
platform_version: string;
cpu: string[];
gpu: string[];
mem_total: number;
disk_total: number;
swap_total: number;
Expand Down

0 comments on commit 3d4bd79

Please sign in to comment.