Update pagespeed redux store

This commit is contained in:
Alex Holliday committed 2024-09-05 13:25:19 -07:00
1 parent 0487095d05
commit cca41fe6df
4 files changed
+10 -16

No files matched your search

@@ -3,7 +3,7 @@ import { jwtDecode } from "jwt-decode";
import { networkService } from "../../main"; import { networkService } from "../../main";
const initialState = { const initialState = {
isLoading: false, isLoading: false,
monitors: [], monitorsSummary: [],
success: null, success: null,
msg: null, msg: null,
}; };
@@ -53,14 +53,10 @@ export const getPageSpeedByTeamId = createAsyncThunk(
async (token, thunkApi) => { async (token, thunkApi) => {
const user = jwtDecode(token); const user = jwtDecode(token);
try { try {
const res = await networkService.getMonitorsByTeamId( const res = await networkService.getMonitorsAndSummaryByTeamId(
token, token,
user.teamId, user.teamId,
25, ["pagespeed"]
["pagespeed"],
null,
"desc",
false
); );
return res.data; return res.data;
@@ -155,7 +151,7 @@ const pageSpeedMonitorSlice = createSlice({
reducers: { reducers: {
clearMonitorState: (state) => { clearMonitorState: (state) => {
state.isLoading = false; state.isLoading = false;
state.monitors = []; state.monitorsSummary = [];
state.success = null; state.success = null;
state.msg = null; state.msg = null;
}, },
@@ -172,7 +168,7 @@ const pageSpeedMonitorSlice = createSlice({
.addCase(getPageSpeedByTeamId.fulfilled, (state, action) => { .addCase(getPageSpeedByTeamId.fulfilled, (state, action) => {
state.isLoading = false; state.isLoading = false;
state.success = action.payload.msg; state.success = action.payload.msg;
state.monitors = action.payload.data; state.monitorsSummary = action.payload.data;
}) })
.addCase(getPageSpeedByTeamId.rejected, (state, action) => { .addCase(getPageSpeedByTeamId.rejected, (state, action) => {
state.isLoading = false; state.isLoading = false;
@@ -217,7 +217,6 @@ const PageSpeedDetails = () => {
null, null,
null null
); );
console.log(res.data.data);
setMonitor(res?.data?.data ?? {}); setMonitor(res?.data?.data ?? {});
setAudits(res?.data?.data?.checks?.[0]?.audits ?? []); setAudits(res?.data?.data?.checks?.[0]?.audits ?? []);
} catch (error) { } catch (error) {
+5 -5
View File
@@ -18,7 +18,7 @@ const PageSpeed = ({ isAdmin }) => {
const navigate = useNavigate(); const navigate = useNavigate();
const { authToken } = useSelector((state) => state.auth); const { authToken } = useSelector((state) => state.auth);
const { monitors, isLoading } = useSelector( const { monitorsSummary, isLoading } = useSelector(
(state) => state.pageSpeedMonitors (state) => state.pageSpeedMonitors
); );
useEffect(() => { useEffect(() => {
@@ -27,7 +27,7 @@ const PageSpeed = ({ isAdmin }) => {
// will show skeletons only on initial load // 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 // 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 ( return (
<Box <Box
@@ -46,7 +46,7 @@ const PageSpeed = ({ isAdmin }) => {
> >
{isActuallyLoading ? ( {isActuallyLoading ? (
<SkeletonLayout /> <SkeletonLayout />
) : monitors?.monitors?.length !== 0 ? ( ) : monitorsSummary?.monitors?.length !== 0 ? (
<Box <Box
sx={{ sx={{
"& p": { "& p": {
@@ -73,8 +73,8 @@ const PageSpeed = ({ isAdmin }) => {
</Stack> </Stack>
</Box> </Box>
<Grid container spacing={theme.spacing(12)}> <Grid container spacing={theme.spacing(12)}>
{monitors?.monitors?.map((monitor) => ( {monitorsSummary?.monitors?.map((monitor) => (
<Card data={monitor} key={`monitor-${monitor._id}`} /> <Card data={monitor} key={monitor._id} />
))} ))}
</Grid> </Grid>
</Box> </Box>
-1
View File
@@ -321,7 +321,6 @@ const getMonitorsAndSummaryByTeamId = async (teamId, type) => {
}, },
{ up: 0, down: 0, paused: 0 } { up: 0, down: 0, paused: 0 }
); );
console.log(monitorCounts);
monitorCounts.total = monitors.length; monitorCounts.total = monitors.length;
return { monitors, monitorCounts }; return { monitors, monitorCounts };
} catch (error) { } catch (error) {