2024-08-07 17:52:46 -04:00
|
|
|
import { Box, Grid, Skeleton, Stack, Typography } from "@mui/material";
|
2024-07-30 13:40:31 -04:00
|
|
|
import { useEffect } from "react";
|
2024-07-28 16:51:47 -04:00
|
|
|
import { useTheme } from "@emotion/react";
|
|
|
|
|
import { formatDate, formatDurationRounded } from "../../Utils/timeUtils";
|
|
|
|
|
import { StatusLabel } from "../../Components/Label";
|
2024-07-30 13:40:31 -04:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { getPageSpeedByUserId } from "../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
|
|
|
|
import PageSpeedIcon from "../../assets/icons/page-speed.svg?react";
|
|
|
|
|
import Fallback from "../../Components/Fallback";
|
|
|
|
|
import "./index.css";
|
2024-08-01 20:12:30 -04:00
|
|
|
import Button from "../../Components/Button";
|
|
|
|
|
import { useNavigate } from "react-router";
|
2024-08-03 12:04:40 -04:00
|
|
|
import { getLastChecked } from "../../Utils/monitorUtils";
|
2024-07-28 16:51:47 -04:00
|
|
|
|
|
|
|
|
const Card = ({ data }) => {
|
|
|
|
|
const theme = useTheme();
|
2024-08-02 18:17:52 -04:00
|
|
|
const navigate = useNavigate();
|
2024-07-28 16:51:47 -04:00
|
|
|
|
|
|
|
|
return (
|
2024-08-02 18:17:52 -04:00
|
|
|
<Grid
|
|
|
|
|
item
|
|
|
|
|
lg={6}
|
|
|
|
|
flexGrow={1}
|
|
|
|
|
sx={{ "&:hover > .MuiStack-root": { backgroundColor: "#f9fafb" } }}
|
|
|
|
|
>
|
|
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
gap={theme.gap.medium}
|
|
|
|
|
p={theme.gap.ml}
|
|
|
|
|
onClick={() => navigate(`/pagespeed/${data._id}`)}
|
|
|
|
|
sx={{ cursor: "pointer" }}
|
|
|
|
|
>
|
2024-07-28 16:51:47 -04:00
|
|
|
<PageSpeedIcon style={{ width: theme.gap.ml, height: theme.gap.ml }} />
|
|
|
|
|
<Box flex={1}>
|
|
|
|
|
<Stack direction="row" justifyContent="space-between">
|
|
|
|
|
<Typography component="h2" mb={theme.gap.xs}>
|
|
|
|
|
{data.name}
|
|
|
|
|
</Typography>
|
|
|
|
|
<StatusLabel
|
2024-07-30 15:44:41 -04:00
|
|
|
status={data.status ? "up" : "cannot resolve"}
|
|
|
|
|
text={data.status ? "Live (collecting data)" : "Inactive"}
|
2024-07-28 16:51:47 -04:00
|
|
|
/>
|
|
|
|
|
</Stack>
|
2024-07-30 15:44:41 -04:00
|
|
|
<Typography>{data.url.replace(/^https?:\/\//, "")}</Typography>
|
2024-07-28 16:51:47 -04:00
|
|
|
<Typography mt={theme.gap.large}>
|
|
|
|
|
<Typography component="span" fontWeight={600}>
|
|
|
|
|
Last checked:{" "}
|
|
|
|
|
</Typography>
|
|
|
|
|
{formatDate(getLastChecked(data.checks, false))}{" "}
|
|
|
|
|
<Typography component="span" fontStyle="italic">
|
|
|
|
|
({formatDurationRounded(getLastChecked(data.checks))} ago)
|
|
|
|
|
</Typography>
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
</Stack>
|
|
|
|
|
</Grid>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const PageSpeed = () => {
|
|
|
|
|
const theme = useTheme();
|
2024-07-30 13:40:31 -04:00
|
|
|
const dispatch = useDispatch();
|
2024-08-01 20:12:30 -04:00
|
|
|
const navigate = useNavigate();
|
2024-07-28 16:51:47 -04:00
|
|
|
|
2024-07-30 13:40:31 -04:00
|
|
|
const { authToken } = useSelector((state) => state.auth);
|
2024-08-07 17:52:46 -04:00
|
|
|
const { monitors, isLoading } = useSelector(
|
|
|
|
|
(state) => state.pageSpeedMonitors
|
|
|
|
|
);
|
2024-07-30 13:40:31 -04:00
|
|
|
useEffect(() => {
|
|
|
|
|
dispatch(getPageSpeedByUserId(authToken));
|
|
|
|
|
}, []);
|
2024-07-28 16:51:47 -04:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Box className="page-speed">
|
2024-08-07 17:52:46 -04:00
|
|
|
{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 ? (
|
2024-07-28 16:51:47 -04:00
|
|
|
<Stack gap={theme.gap.xs}>
|
2024-08-01 20:12:30 -04:00
|
|
|
<Stack
|
|
|
|
|
direction="row"
|
|
|
|
|
justifyContent="space-between"
|
|
|
|
|
mb={theme.gap.large}
|
|
|
|
|
>
|
|
|
|
|
<Box>
|
|
|
|
|
<Typography component="h1">All page speed monitors</Typography>
|
|
|
|
|
<Typography mt={theme.gap.xs}>
|
|
|
|
|
Click on one of the monitors to get more site speed information.
|
|
|
|
|
</Typography>
|
|
|
|
|
</Box>
|
|
|
|
|
<Button
|
|
|
|
|
level="primary"
|
|
|
|
|
label="Create new"
|
2024-08-02 18:08:36 -04:00
|
|
|
onClick={() => navigate("/pagespeed/create")}
|
2024-08-01 20:12:30 -04:00
|
|
|
/>
|
|
|
|
|
</Stack>
|
2024-07-28 16:51:47 -04:00
|
|
|
<Grid container spacing={theme.gap.large}>
|
2024-07-30 13:40:31 -04:00
|
|
|
{monitors?.map((monitor) => (
|
2024-07-28 16:51:47 -04:00
|
|
|
<Card data={monitor} key={`monitor-${monitor._id}`} />
|
|
|
|
|
))}
|
|
|
|
|
</Grid>
|
|
|
|
|
</Stack>
|
|
|
|
|
) : (
|
|
|
|
|
<Fallback
|
|
|
|
|
title="page speed"
|
|
|
|
|
checks={[
|
|
|
|
|
"Report on the user experience of a page",
|
|
|
|
|
"Help analyze webpage speed",
|
|
|
|
|
"Give suggestions on how the page can be improved",
|
|
|
|
|
]}
|
2024-08-02 18:08:36 -04:00
|
|
|
link="/pagespeed/create"
|
2024-07-28 16:51:47 -04:00
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
</Box>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default PageSpeed;
|