From 1b32cbbbfd7ee42b131e747e4feaa4e5254167b4 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Fri, 12 Dec 2025 15:04:22 -0800 Subject: [PATCH] Enhancement: refactor UptimeRobot widget (#6088) --- src/widgets/uptimerobot/component.jsx | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/widgets/uptimerobot/component.jsx b/src/widgets/uptimerobot/component.jsx index 2c0f564be..3948fc54c 100644 --- a/src/widgets/uptimerobot/component.jsx +++ b/src/widgets/uptimerobot/component.jsx @@ -49,10 +49,12 @@ export default function Component({ service }) { // single monitor const monitor = uptimerobotData.monitors[0]; + const logs = Array.isArray(monitor.logs) ? monitor.logs : []; + const lastUpLog = logs.find((log) => log.type === 2); + const lastDownLog = logs.find((log) => log.type === 1); + let status; let uptime = 0; - let logIndex = 0; - const hasLogs = Array.isArray(monitor.logs) && monitor.logs.length > 0; switch (monitor.status) { case 0: @@ -63,8 +65,7 @@ export default function Component({ service }) { break; case 2: status = t("uptimerobot.up"); - uptime = t("common.duration", { value: hasLogs ? monitor.logs[0].duration : 0 }); - logIndex = 1; + uptime = t("common.duration", { value: lastUpLog?.duration ?? 0 }); break; case 8: status = t("uptimerobot.seemsdown"); @@ -77,14 +78,14 @@ export default function Component({ service }) { break; } - const lastDown = hasLogs ? new Date(monitor.logs[logIndex].datetime * 1000).toLocaleString() : ""; - const downDuration = t("common.duration", { value: hasLogs ? monitor.logs[logIndex].duration : 0 }); - const hideDown = !hasLogs || (logIndex === 1 && monitor.logs[logIndex].type !== 1); + const lastDown = lastDownLog ? new Date(lastDownLog.datetime * 1000).toLocaleString() : ""; + const downDuration = t("common.duration", { value: lastDownLog?.duration ?? 0 }); + const hideDown = !lastDownLog; return ( - {hasLogs && } + {!hideDown && } {!hideDown && }