Add skeletons and loading conditions

This commit is contained in:
Alex Holliday committed 2025-01-28 15:51:58 -08:00
1 parent ac2cf49082
commit a33c0c16a0
5 files changed
+64 -11

No files matched your search

@@ -1,13 +1,20 @@
import ChartBox from "../../../../../Components/Charts/ChartBox"; import ChartBox from "../../../../../Components/Charts/ChartBox";
import AreaChart from "../Charts/AreaChart"; import AreaChart from "../Charts/AreaChart";
import AreaChartLegend from "../Charts/AreaChartLegend"; import AreaChartLegend from "../Charts/AreaChartLegend";
import SkeletonLayout from "./skeleton";
import ScoreIcon from "../../../../../assets/icons/monitor-graph-line.svg?react"; import ScoreIcon from "../../../../../assets/icons/monitor-graph-line.svg?react";
import { Stack } from "@mui/material"; import { Stack } from "@mui/material";
import PropTypes from "prop-types";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
const PageSpeedAreaChart = ({ shouldRender, monitor, metrics, handleMetrics }) => { const PageSpeedAreaChart = ({ shouldRender, monitor, metrics, handleMetrics }) => {
const theme = useTheme(); const theme = useTheme();
if (!shouldRender) {
return <SkeletonLayout />;
}
if (typeof monitor === "undefined") { if (typeof monitor === "undefined") {
return null; return null;
} }
@@ -42,4 +49,11 @@ const PageSpeedAreaChart = ({ shouldRender, monitor, metrics, handleMetrics }) =
); );
}; };
PageSpeedAreaChart.propTypes = {
shouldRender: PropTypes.bool,
monitor: PropTypes.object,
metrics: PropTypes.object,
handleMetrics: PropTypes.func,
};
export default PageSpeedAreaChart; export default PageSpeedAreaChart;
@@ -0,0 +1,17 @@
import { Box, Skeleton } from "@mui/material";
const SkeletonLayout = () => {
return (
<Box
height={"100%"}
width={"100%"}
>
<Skeleton
height={"100%"}
width={"100%"}
/>
</Box>
);
};
export default SkeletonLayout;
@@ -4,9 +4,19 @@ import PieChart from "../Charts/PieChart";
import { Typography } from "@mui/material"; import { Typography } from "@mui/material";
import { useTheme } from "@emotion/react"; import { useTheme } from "@emotion/react";
import PieChartLegend from "../Charts/PieChartLegend"; import PieChartLegend from "../Charts/PieChartLegend";
import SkeletonLayout from "./skeleton";
const PerformanceReport = ({ audits }) => { const PerformanceReport = ({ shouldRender, audits }) => {
console.log("shouldRender", shouldRender);
const theme = useTheme(); const theme = useTheme();
if (!shouldRender) {
return <SkeletonLayout />;
}
if (typeof audits === "undefined") {
return null;
}
return ( return (
<ChartBox <ChartBox
icon={<PerformanceIcon />} icon={<PerformanceIcon />}
@@ -0,0 +1,17 @@
import { Box, Skeleton } from "@mui/material";
const SkeletonLayout = () => {
return (
<Box
height={"100%"}
width={"100%"}
>
<Skeleton
height={"100%"}
width={"100%"}
/>
</Box>
);
};
export default SkeletonLayout;
+4 -9
View File
@@ -44,14 +44,6 @@ const PageSpeedDetails = () => {
setMetrics((prev) => ({ ...prev, [id]: !prev[id] })); setMetrics((prev) => ({ ...prev, [id]: !prev[id] }));
}; };
if (isLoading) {
return "funk";
}
if (typeof audits === "undefined") {
return "No Data";
}
return ( return (
<Stack gap={theme.spacing(10)}> <Stack gap={theme.spacing(10)}>
<Breadcrumbs list={BREADCRUMBS} /> <Breadcrumbs list={BREADCRUMBS} />
@@ -76,7 +68,10 @@ const PageSpeedDetails = () => {
metrics={metrics} metrics={metrics}
handleMetrics={handleMetrics} handleMetrics={handleMetrics}
/> />
<PerformanceReport audits={audits} /> <PerformanceReport
shouldRender={!isLoading}
audits={audits}
/>
</Stack> </Stack>
); );
}; };