Update pagespeed redux store

This commit is contained in:
Alex Holliday
2024-09-05 13:25:19 -07:00
parent 0487095d05
commit cca41fe6df
4 changed files with 10 additions and 16 deletions

View File

@@ -3,7 +3,7 @@ import { jwtDecode } from "jwt-decode";
import { networkService } from "../../main";
const initialState = {
isLoading: false,
monitors: [],
monitorsSummary: [],
success: null,
msg: null,
};
@@ -53,14 +53,10 @@ export const getPageSpeedByTeamId = createAsyncThunk(
async (token, thunkApi) => {
const user = jwtDecode(token);
try {
const res = await networkService.getMonitorsByTeamId(
const res = await networkService.getMonitorsAndSummaryByTeamId(
token,
user.teamId,
25,
["pagespeed"],
null,
"desc",
false
["pagespeed"]
);
return res.data;
@@ -155,7 +151,7 @@ const pageSpeedMonitorSlice = createSlice({
reducers: {
clearMonitorState: (state) => {
state.isLoading = false;
state.monitors = [];
state.monitorsSummary = [];
state.success = null;
state.msg = null;
},
@@ -172,7 +168,7 @@ const pageSpeedMonitorSlice = createSlice({
.addCase(getPageSpeedByTeamId.fulfilled, (state, action) => {
state.isLoading = false;
state.success = action.payload.msg;
state.monitors = action.payload.data;
state.monitorsSummary = action.payload.data;
})
.addCase(getPageSpeedByTeamId.rejected, (state, action) => {
state.isLoading = false;

View File

@@ -217,7 +217,6 @@ const PageSpeedDetails = () => {
null,
null
);
console.log(res.data.data);
setMonitor(res?.data?.data ?? {});
setAudits(res?.data?.data?.checks?.[0]?.audits ?? []);
} catch (error) {

View File

@@ -18,7 +18,7 @@ const PageSpeed = ({ isAdmin }) => {
const navigate = useNavigate();
const { authToken } = useSelector((state) => state.auth);
const { monitors, isLoading } = useSelector(
const { monitorsSummary, isLoading } = useSelector(
(state) => state.pageSpeedMonitors
);
useEffect(() => {
@@ -27,7 +27,7 @@ const PageSpeed = ({ isAdmin }) => {
// will show skeletons only on initial load
// since monitor state is being added to redux persist, there's no reason to display skeletons on every render
let isActuallyLoading = isLoading && monitors?.monitors.length === 0;
let isActuallyLoading = isLoading && monitorsSummary?.monitors?.length === 0;
return (
<Box
@@ -46,7 +46,7 @@ const PageSpeed = ({ isAdmin }) => {
>
{isActuallyLoading ? (
<SkeletonLayout />
) : monitors?.monitors?.length !== 0 ? (
) : monitorsSummary?.monitors?.length !== 0 ? (
<Box
sx={{
"& p": {
@@ -73,8 +73,8 @@ const PageSpeed = ({ isAdmin }) => {
</Stack>
</Box>
<Grid container spacing={theme.spacing(12)}>
{monitors?.monitors?.map((monitor) => (
<Card data={monitor} key={`monitor-${monitor._id}`} />
{monitorsSummary?.monitors?.map((monitor) => (
<Card data={monitor} key={monitor._id} />
))}
</Grid>
</Box>

View File

@@ -321,7 +321,6 @@ const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
},
{ up: 0, down: 0, paused: 0 }
);
console.log(monitorCounts);
monitorCounts.total = monitors.length;
return { monitors, monitorCounts };
} catch (error) {