diff --git a/client/src/Pages/PageSpeed/Details/Components/PageSpeedStatusBoxes/index.jsx b/client/src/Pages/PageSpeed/Details/Components/PageSpeedStatusBoxes/index.jsx index 13d7edf8c..872b1e293 100644 --- a/client/src/Pages/PageSpeed/Details/Components/PageSpeedStatusBoxes/index.jsx +++ b/client/src/Pages/PageSpeed/Details/Components/PageSpeedStatusBoxes/index.jsx @@ -4,34 +4,31 @@ import { Typography } from "@mui/material"; import { getHumanReadableDuration } from "../../../../../Utils/timeUtils.js"; import { useTranslation } from "react-i18next"; -const PageSpeedStatusBoxes = ({ shouldRender, monitor }) => { +const PageSpeedStatusBoxes = ({ shouldRender, monitorStats }) => { + const lastChecked = monitorStats?.lastCheckTimestamp + ? Date.now() - monitorStats.lastCheckTimestamp + : 0; + + // Determine time since last failure + const timeOfLastFailure = monitorStats?.timeOfLastFailure; + const timeSinceLastFailure = + timeOfLastFailure > 0 + ? Date.now() - timeOfLastFailure + : Date.now() - new Date(monitorStats?.createdAt); + + const streakTime = getHumanReadableDuration(timeSinceLastFailure); + + const time = getHumanReadableDuration(lastChecked); + const { t } = useTranslation(); - // Calculate time since first check (checks since) - const checks = monitor?.checks || []; - const oldestCheck = checks.length > 0 ? checks[checks.length - 1] : null; - const oldestCheckTime = oldestCheck?.createdAt - ? new Date(oldestCheck.createdAt).getTime() - : null; - const checksSinceDuration = oldestCheckTime ? Date.now() - oldestCheckTime : 0; - - // Calculate time since last check - const latestCheck = checks.length > 0 ? checks[0] : null; - const latestCheckTime = latestCheck?.createdAt - ? new Date(latestCheck.createdAt).getTime() - : null; - const lastCheckDuration = latestCheckTime ? Date.now() - latestCheckTime : 0; - - const uptimeDuration = getHumanReadableDuration(checksSinceDuration); - const time = getHumanReadableDuration(lastCheckDuration); - return ( - {uptimeDuration} + {streakTime} {t("ago")} }