Skip to content

Commit

Permalink
Only load localstate if params are not included in url request
Browse files Browse the repository at this point in the history
  • Loading branch information
bo-lu committed Sep 12, 2024
1 parent 671da88 commit 304b2aa
Showing 1 changed file with 29 additions and 26 deletions.
55 changes: 29 additions & 26 deletions src/reducers/localStorage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,36 @@ function checkNestedProperty(obj, props: string): boolean {

export const loadState = (): StoreEnhancer<unknown, unknown> | undefined => {
try {
const serializedState = localStorage.getItem('state');
if (serializedState === null) {
return undefined;
const urlParams = new URLSearchParams(window.location.search);
if (!urlParams.toString()) {
const serializedState = localStorage.getItem('state');
if (serializedState === null) {
return undefined;
}
const state = JSON.parse(serializedState);
if (!checkNestedProperty(state, 'mappingReducer.spatempfilter')) {
state['mappingReducer'].spatempfilter = INITSPATIALTEMPORALFILTER;
}
if (!checkNestedProperty(state, 'mappingReducer.spatialfilter')) {
state['mappingReducer'].spatialfilter = [];
}
if (!checkNestedProperty(state, 'mappingReducer.metasrcfilter')) {
state['mappingReducer'].metasrcfilter = INITMETADATASRCFILTER;
}
if (!checkNestedProperty(state, 'mappingReducer.stacfilter')) {
state['mappingReducer'].stacfilter = [];
}
if (!checkNestedProperty(state, 'mappingReducer.center')) {
state['mappingReducer'].center = INITMAINMAPINFO.center;
}
if (!checkNestedProperty(state, 'mappingReducer.zoom')) {
state['mappingReducer'].zoom = INITMAINMAPINFO.zoom;
}
if (!checkNestedProperty(state, 'mappingReducer.freezeMapSearch')) {
state['mappingReducer'].freezeMapSearch = { freeze: true };
}
return state;
}
const state = JSON.parse(serializedState);
if (!checkNestedProperty(state, 'mappingReducer.spatempfilter')) {
state['mappingReducer'].spatempfilter = INITSPATIALTEMPORALFILTER;
}
if (!checkNestedProperty(state, 'mappingReducer.spatialfilter')) {
state['mappingReducer'].spatialfilter = [];
}
if (!checkNestedProperty(state, 'mappingReducer.metasrcfilter')) {
state['mappingReducer'].metasrcfilter = INITMETADATASRCFILTER;
}
if (!checkNestedProperty(state, 'mappingReducer.stacfilter')) {
state['mappingReducer'].stacfilter = [];
}
if (!checkNestedProperty(state, 'mappingReducer.center')) {
state['mappingReducer'].center = INITMAINMAPINFO.center;
}
if (!checkNestedProperty(state, 'mappingReducer.zoom')) {
state['mappingReducer'].zoom = INITMAINMAPINFO.zoom;
}
if (!checkNestedProperty(state, 'mappingReducer.freezeMapSearch')) {
state['mappingReducer'].freezeMapSearch = { freeze: true };
}
return state;
} catch (err) {
return undefined;
}
Expand Down

0 comments on commit 304b2aa

Please sign in to comment.