From 88119041338d30b1da1d09555e6661dacc7de3db Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Tue, 3 Dec 2024 15:04:13 +0800 Subject: [PATCH] fix: cycle card grid --- src/components/CycleTransferStats.tsx | 47 ++++---- src/components/CycleTransferStatsClient.tsx | 112 ++++++++++---------- 2 files changed, 80 insertions(+), 79 deletions(-) diff --git a/src/components/CycleTransferStats.tsx b/src/components/CycleTransferStats.tsx index c70f3e5..60155c5 100644 --- a/src/components/CycleTransferStats.tsx +++ b/src/components/CycleTransferStats.tsx @@ -14,32 +14,35 @@ export const CycleTransferStatsCard: React.FC = ({ return (
{Object.entries(cycleStats).map(([cycleId, cycleData]) => { - const serverStats = cycleData.server_name - ? Object.entries(cycleData.server_name).map( - ([serverId, serverName]) => ({ - serverId, - serverName, - transfer: cycleData.transfer?.[serverId] || 0, - nextUpdate: cycleData.next_update?.[serverId], - }) - ) - : []; + if (!cycleData.server_name) { + return null; + } + + return Object.entries(cycleData.server_name).map(([serverId, serverName]) => { + const transfer = cycleData.transfer?.[serverId] || 0; + const nextUpdate = cycleData.next_update?.[serverId]; - if (serverStats.length === 0) { + if (!transfer && !nextUpdate) { return null; } - return ( - - ); + return ( + + ); + }); })}
); diff --git a/src/components/CycleTransferStatsClient.tsx b/src/components/CycleTransferStatsClient.tsx index 541dc3b..78e25a8 100644 --- a/src/components/CycleTransferStatsClient.tsx +++ b/src/components/CycleTransferStatsClient.tsx @@ -24,70 +24,68 @@ export const CycleTransferStatsClient: React.FC< return (
-
-
- {serverStats.map(({ serverId, serverName, transfer, nextUpdate }) => { - const progress = (transfer / max) * 100; + {serverStats.map(({ serverId, serverName, transfer, nextUpdate }) => { + const progress = (transfer / max) * 100; - return ( -
-
-
- {name} -
- - {new Date(from).toLocaleDateString()} -{" "} - {new Date(to).toLocaleDateString()} - -
-
-
- - {serverName} -
-
-

- {progress.toFixed(0)}% -

- -
-
-
-
-
+ return ( +
+
+
+ {name} +
+ + {new Date(from).toLocaleDateString()} -{" "} + {new Date(to).toLocaleDateString()} + +
+ +
+
+ + {serverName} +
+
+

+ {progress.toFixed(0)}% +

+ +
+
+ +
+
+
-
- - {formatBytes(transfer)} used - - - {formatBytes(max)} total - -
+
+ + {formatBytes(transfer)} used + + + {formatBytes(max)} total + +
-
-
- Next update: {new Date(nextUpdate).toLocaleString()} -
-
+
+
+ Next update: {new Date(nextUpdate).toLocaleString()}
- ); - })} -
-
+ +
+ ); + })}
); };