import Stack from "@mui/material/Stack"; import { BasePage, StatBox } from "@/components/design-elements"; import { HeaderControls, HeaderRange } from "@/components/monitors"; import { HistogramPageSpeedScores } from "@/components/monitors/HistogramPageSpeedScores"; import { ChartPageSpeedReport } from "@/components/monitors/ChartPageSpeedReport"; import { ChartPageSpeedReportLegend } from "@/components/monitors/ChartPageSpeedReportLegend"; import { useTranslation } from "react-i18next"; import { useState } from "react"; import { useParams } from "react-router"; import { useTheme } from "@mui/material/styles"; import { useGet, usePatch } from "@/hooks/UseApi"; import type { ApiResponse } from "@/hooks/UseApi"; import type { IMonitor, IMonitorWithMonitorStats } from "@/types/monitor"; import { getStatusPalette } from "@/utils/MonitorUtils"; import prettyMilliseconds from "pretty-ms"; import useMediaQuery from "@mui/material/useMediaQuery"; import { config } from "@/config/index"; const GLOBAL_REFRESH = config.GLOBAL_REFRESH; const PageSpeedDetailsPage = () => { const { t } = useTranslation(); const theme = useTheme(); const { id } = useParams(); const [range, setRange] = useState("2h"); const isSmall = useMediaQuery(theme.breakpoints.down("md")); const { patch, loading: isPatching } = usePatch(); const { response, isValidating, refetch } = useGet< ApiResponse >( `/monitors/${id}?embedChecks=true&range=${range}`, {}, { refreshInterval: GLOBAL_REFRESH, keepPreviousData: true } ); const monitor = response?.data?.monitor; const stats = response?.data?.stats; const checks = response?.data?.checks || []; const streakDuration = stats?.currentStreakStartedAt ? Date.now() - stats?.currentStreakStartedAt : 0; const lastChecked = stats?.lastCheckTimestamp ? Date.now() - stats?.lastCheckTimestamp : -1; if (!monitor) { return null; } const palette = getStatusPalette(monitor?.status); return ( = 0 ? `${prettyMilliseconds(lastChecked, { secondsDecimalDigits: 0, })} ago` : "N/A" } /> ); }; export default PageSpeedDetailsPage;