Skip to content

Commit

Permalink
resolved bug with reset & LS
Browse files Browse the repository at this point in the history
  • Loading branch information
SanjeevLakhwani committed Mar 4, 2024
1 parent 9c3bc75 commit b26b081
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/js/features/data/data.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const data = createSlice({
})
.addCase(makeGetDataRequestThunk.fulfilled, (state, { payload }) => {
state.sections = payload.sectionData;
state.defaultLayout = payload.sectionData;
state.defaultLayout = payload.defaultData;
state.counts = payload.counts;
state.isFetchingData = false;
})
Expand Down
6 changes: 4 additions & 2 deletions src/js/features/data/makeGetDataRequest.thunk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Counts, OverviewResponse } from '@/types/overviewResponse';
import { printAPIError } from '@/utils/error.util';

export const makeGetDataRequestThunk = createAsyncThunk<
{ sectionData: Sections; counts: Counts },
{ sectionData: Sections; counts: Counts; defaultData: Sections },
void,
{ rejectValue: string }
>('data/makeGetDataRequest', async (_, { rejectWithValue }) => {
Expand Down Expand Up @@ -46,6 +46,8 @@ export const makeGetDataRequestThunk = createAsyncThunk<
charts: charts.map(normalizeChart),
}));

const defaultSectionData = JSON.parse(JSON.stringify(sectionData));

// comparing to the local store and updating itself
let convertedData = convertSequenceAndDisplayData(sectionData);
const localValue = getValue(LOCALSTORAGE_CHARTS_KEY, convertedData, (val: LocalStorageData) =>
Expand All @@ -63,5 +65,5 @@ export const makeGetDataRequestThunk = createAsyncThunk<
convertedData = convertSequenceAndDisplayData(sectionData);
saveValue(LOCALSTORAGE_CHARTS_KEY, convertedData);

return { sectionData, counts: overviewResponse.counts };
return { sectionData, counts: overviewResponse.counts, defaultData: defaultSectionData };
});

0 comments on commit b26b081

Please sign in to comment.