Added skeletons to pagespeed pages
This commit is contained in:
1 parent
51bfc83903
commit
ea4cf6efd3
2 files changed
+150
-13
No files matched your search
@@ -1,4 +1,4 @@
|
|||||||
import { Box, Stack, Typography } from "@mui/material";
|
import { Box, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { PieChart } from "@mui/x-charts/PieChart";
|
import { PieChart } from "@mui/x-charts/PieChart";
|
||||||
import { useDrawingArea } from "@mui/x-charts";
|
import { useDrawingArea } from "@mui/x-charts";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
@@ -136,6 +136,7 @@ const PageSpeedDetails = () => {
|
|||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitor = async () => {
|
const fetchMonitor = async () => {
|
||||||
|
try {
|
||||||
const res = await axiosInstance.get(
|
const res = await axiosInstance.get(
|
||||||
`/monitors/${monitorId}?sortOrder=desc`,
|
`/monitors/${monitorId}?sortOrder=desc`,
|
||||||
{
|
{
|
||||||
@@ -147,6 +148,10 @@ const PageSpeedDetails = () => {
|
|||||||
|
|
||||||
setMonitor(res.data.data);
|
setMonitor(res.data.data);
|
||||||
setAudits(res.data.data.checks[0].audits);
|
setAudits(res.data.data.checks[0].audits);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error fetching pagespeed monitor of id: " + monitorId);
|
||||||
|
navigate("/not-found");
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchMonitor();
|
fetchMonitor();
|
||||||
@@ -244,8 +249,13 @@ const PageSpeedDetails = () => {
|
|||||||
const [highlightedItem, setHighLightedItem] = useState(null);
|
const [highlightedItem, setHighLightedItem] = useState(null);
|
||||||
const [expand, setExpand] = useState(false);
|
const [expand, setExpand] = useState(false);
|
||||||
|
|
||||||
|
let loading = Object.keys(monitor).length === 0;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Stack className="page-speed-details" gap={theme.gap.large}>
|
<Stack className="page-speed-details" gap={theme.gap.large}>
|
||||||
|
{loading ? (
|
||||||
|
<Skeleton variant="rounded" width="15%" height={34} />
|
||||||
|
) : (
|
||||||
<Button
|
<Button
|
||||||
level="tertiary"
|
level="tertiary"
|
||||||
label="Back"
|
label="Back"
|
||||||
@@ -262,14 +272,39 @@ const PageSpeedDetails = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<Stack
|
)}
|
||||||
direction="row"
|
<Stack direction="row" gap={theme.gap.small}>
|
||||||
gap={theme.gap.small}
|
{loading ? (
|
||||||
justifyContent="space-between"
|
<>
|
||||||
>
|
<Skeleton
|
||||||
|
variant="circular"
|
||||||
|
style={{ minWidth: 24, minHeight: 24 }}
|
||||||
|
/>
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton variant="rounded" width="50%" height={24} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={18}
|
||||||
|
sx={{ mt: theme.gap.small }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="15%"
|
||||||
|
height={34}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<GreenCheck />
|
<GreenCheck />
|
||||||
<Box>
|
<Box>
|
||||||
<Typography component="h1" mb={theme.gap.xs} sx={{ lineHeight: 1 }}>
|
<Typography
|
||||||
|
component="h1"
|
||||||
|
mb={theme.gap.xs}
|
||||||
|
sx={{ lineHeight: 1 }}
|
||||||
|
>
|
||||||
{monitor?.url}
|
{monitor?.url}
|
||||||
</Typography>
|
</Typography>
|
||||||
<Typography
|
<Typography
|
||||||
@@ -299,6 +334,8 @@ const PageSpeedDetails = () => {
|
|||||||
},
|
},
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
@@ -306,6 +343,29 @@ const PageSpeedDetails = () => {
|
|||||||
gap={theme.gap.xl}
|
gap={theme.gap.xl}
|
||||||
flexWrap="wrap"
|
flexWrap="wrap"
|
||||||
>
|
>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="30%"
|
||||||
|
height={90}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="30%"
|
||||||
|
height={90}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="30%"
|
||||||
|
height={90}
|
||||||
|
sx={{ flex: 1 }}
|
||||||
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<StatBox
|
<StatBox
|
||||||
icon={<LastCheckedIcon />}
|
icon={<LastCheckedIcon />}
|
||||||
title="Last checked"
|
title="Last checked"
|
||||||
@@ -317,7 +377,8 @@ const PageSpeedDetails = () => {
|
|||||||
fontStyle="italic"
|
fontStyle="italic"
|
||||||
sx={{ opacity: 0.8 }}
|
sx={{ opacity: 0.8 }}
|
||||||
>
|
>
|
||||||
({formatDurationRounded(getLastChecked(monitor?.checks))} ago)
|
({formatDurationRounded(getLastChecked(monitor?.checks))}{" "}
|
||||||
|
ago)
|
||||||
</Typography>
|
</Typography>
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
@@ -347,11 +408,31 @@ const PageSpeedDetails = () => {
|
|||||||
title="Checks every"
|
title="Checks every"
|
||||||
value={formatDurationRounded(monitor?.interval)}
|
value={formatDurationRounded(monitor?.interval)}
|
||||||
></StatBox>
|
></StatBox>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<Typography component="h2">Score history</Typography>
|
<Typography component="h2">Score history</Typography>
|
||||||
<Box height="300px">
|
<Box height="300px">
|
||||||
<PageSpeedLineChart pageSpeedChecks={monitor?.checks?.slice(0, 25)} />
|
<PageSpeedLineChart
|
||||||
|
pageSpeedChecks={monitor?.checks?.slice(0, 25)}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{loading ? (
|
||||||
|
<>
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton variant="rounded" width="100%" height={300} />
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
<Typography component="h2">Performance report</Typography>
|
<Typography component="h2">Performance report</Typography>
|
||||||
<Stack direction="row" alignItems="center" overflow="hidden">
|
<Stack direction="row" alignItems="center" overflow="hidden">
|
||||||
<Stack
|
<Stack
|
||||||
@@ -549,7 +630,9 @@ const PageSpeedDetails = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Find the position where the number ends and the unit begins
|
// Find the position where the number ends and the unit begins
|
||||||
const match = audit.displayValue.match(/(\d+\.?\d*)\s*([a-zA-Z]+)/);
|
const match = audit.displayValue.match(
|
||||||
|
/(\d+\.?\d*)\s*([a-zA-Z]+)/
|
||||||
|
);
|
||||||
let value;
|
let value;
|
||||||
let unit;
|
let unit;
|
||||||
if (match) {
|
if (match) {
|
||||||
@@ -598,6 +681,8 @@ const PageSpeedDetails = () => {
|
|||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
</Stack>
|
</Stack>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Box, Grid, Stack, Typography } from "@mui/material";
|
import { Box, Grid, Skeleton, Stack, Typography } from "@mui/material";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
||||||
@@ -63,14 +63,66 @@ const PageSpeed = () => {
|
|||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const { authToken } = useSelector((state) => state.auth);
|
const { authToken } = useSelector((state) => state.auth);
|
||||||
const { monitors } = useSelector((state) => state.pageSpeedMonitors);
|
const { monitors, isLoading } = useSelector(
|
||||||
|
(state) => state.pageSpeedMonitors
|
||||||
|
);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(getPageSpeedByUserId(authToken));
|
dispatch(getPageSpeedByUserId(authToken));
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className="page-speed">
|
<Box className="page-speed">
|
||||||
{monitors?.length !== 0 ? (
|
{isLoading ? (
|
||||||
|
<Stack gap={theme.gap.xs}>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="space-between"
|
||||||
|
mb={theme.gap.large}
|
||||||
|
>
|
||||||
|
<Box width="80%">
|
||||||
|
<Skeleton variant="rounded" width="25%" height={24} />
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="50%"
|
||||||
|
height={19.5}
|
||||||
|
sx={{ mt: theme.gap.xs }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="20%"
|
||||||
|
height={34}
|
||||||
|
sx={{ alignSelf: "flex-end" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
<Stack direction="row" flexWrap="wrap" gap={theme.gap.large}>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
<Skeleton
|
||||||
|
variant="rounded"
|
||||||
|
width="100%"
|
||||||
|
height={120}
|
||||||
|
sx={{ flex: "35%" }}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
) : monitors?.length !== 0 ? (
|
||||||
<Stack gap={theme.gap.xs}>
|
<Stack gap={theme.gap.xs}>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
|
|||||||
Reference in new issue
Block a user