From f6c15bbe9ff29bf33cd5c1f83b6bb19bf47c18be Mon Sep 17 00:00:00 2001 From: Aja Beckett Date: Mon, 23 Oct 2023 17:51:55 -0700 Subject: [PATCH 1/4] chore: add loading state Attaching a loading state to the call that's populating the user's Sites and Projects data, so we can show loading indicators in the mobile app. --- src/soilId/soilIdSlice.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/soilId/soilIdSlice.ts b/src/soilId/soilIdSlice.ts index 58ddc3f8..ee198449 100644 --- a/src/soilId/soilIdSlice.ts +++ b/src/soilId/soilIdSlice.ts @@ -89,6 +89,7 @@ export type ProjectSoilSettings = Omit< const initialState = { soilData: {} as Record, projectSettings: {} as Record, + loading: false, }; export const sameDepth = @@ -151,6 +152,14 @@ const soilIdSlice = createSlice({ builder.addCase(deleteProjectDepthInterval.fulfilled, (state, action) => { state.projectSettings[action.meta.arg.projectId] = action.payload; }); + + builder.addCase(fetchSoilDataForUser.fulfilled, (state, action) => { + state.loading = false; + }); + + builder.addCase(fetchSoilDataForUser.pending, (state, action) => { + state.loading = true; + }); }, }); From ad933158d3d4ef3a7d0c4c3990f4515c2ff3d837 Mon Sep 17 00:00:00 2001 From: Aja Beckett Date: Mon, 23 Oct 2023 18:07:47 -0700 Subject: [PATCH 2/4] fix: remove unused actions --- src/soilId/soilIdSlice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/soilId/soilIdSlice.ts b/src/soilId/soilIdSlice.ts index ee198449..7dd22f47 100644 --- a/src/soilId/soilIdSlice.ts +++ b/src/soilId/soilIdSlice.ts @@ -153,11 +153,11 @@ const soilIdSlice = createSlice({ state.projectSettings[action.meta.arg.projectId] = action.payload; }); - builder.addCase(fetchSoilDataForUser.fulfilled, (state, action) => { + builder.addCase(fetchSoilDataForUser.fulfilled, (state) => { state.loading = false; }); - builder.addCase(fetchSoilDataForUser.pending, (state, action) => { + builder.addCase(fetchSoilDataForUser.pending, (state) => { state.loading = true; }); }, From 7dc2187fcdfee03ecc8527b29c86a64351be98b4 Mon Sep 17 00:00:00 2001 From: Aja Beckett Date: Mon, 23 Oct 2023 18:10:41 -0700 Subject: [PATCH 3/4] fix: remove parens --- src/soilId/soilIdSlice.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/soilId/soilIdSlice.ts b/src/soilId/soilIdSlice.ts index 7dd22f47..4f16f772 100644 --- a/src/soilId/soilIdSlice.ts +++ b/src/soilId/soilIdSlice.ts @@ -153,11 +153,11 @@ const soilIdSlice = createSlice({ state.projectSettings[action.meta.arg.projectId] = action.payload; }); - builder.addCase(fetchSoilDataForUser.fulfilled, (state) => { + builder.addCase(fetchSoilDataForUser.fulfilled, state => { state.loading = false; }); - builder.addCase(fetchSoilDataForUser.pending, (state) => { + builder.addCase(fetchSoilDataForUser.pending, state => { state.loading = true; }); }, From 6f77c97f443c10742160dbf7fd906a7121e8d323 Mon Sep 17 00:00:00 2001 From: Aja Beckett Date: Mon, 23 Oct 2023 18:20:07 -0700 Subject: [PATCH 4/4] fix: add rejected case --- src/soilId/soilIdSlice.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/soilId/soilIdSlice.ts b/src/soilId/soilIdSlice.ts index 4f16f772..6afae886 100644 --- a/src/soilId/soilIdSlice.ts +++ b/src/soilId/soilIdSlice.ts @@ -153,13 +153,13 @@ const soilIdSlice = createSlice({ state.projectSettings[action.meta.arg.projectId] = action.payload; }); - builder.addCase(fetchSoilDataForUser.fulfilled, state => { - state.loading = false; - }); - builder.addCase(fetchSoilDataForUser.pending, state => { state.loading = true; }); + + builder.addCase(fetchSoilDataForUser.rejected, state => { + state.loading = false; + }); }, });