Skip to content

Commit

Permalink
fix(map): Removed places and layers from Session Storage [EP-3605]
Browse files Browse the repository at this point in the history
  • Loading branch information
ancashoria committed Jan 8, 2021
1 parent c50e425 commit aef4002
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 46 deletions.
9 changes: 0 additions & 9 deletions packages/earth-map/src/sagas/global/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,7 @@ export default function* global() {
function* persistData() {
const state = yield select(getAll);

// keep full reducer state instead of a substate. eg `places` instead of `places.search`
const keepThis: IEphemeralState = {
places: {
search: state.places.search.search,
filters: state.places.search.filters,
},
layers: {
search: state.layers.search.search,
filters: state.layers.search.filters,
},
global: {
lastViewedPlace: state.global.lastViewedPlace,
},
Expand Down
37 changes: 0 additions & 37 deletions packages/earth-map/src/store/ephemeral-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,11 @@
*/

import { setLastViewedPlace } from 'modules/global/actions';
import { setLayersSearch } from 'modules/layers/actions';
import { setMapStyle } from 'modules/map/actions';
import { setPlacesSearch } from 'modules/places/actions';
import { IPlace } from 'modules/places/model';
import { setUserGroup } from 'modules/user/actions';
import { Store } from 'redux';

export interface IEphemeralState {
places?: {
search?: any;
filters?: any;
};
layers?: {
search?: any;
filters?: any;
};
global?: {
lastViewedPlace?: IPlace;
};
Expand All @@ -47,38 +36,12 @@ export interface IEphemeralState {
* Put state from ephemeralState back into the store at init time by dispatching actions
*/
export default (store: Store, ephemeralState: IEphemeralState): void => {
/**
* Utility function to restore search state for either Places or Layers
*/
const restoreSearchFor = (panel: string, setGenericSearch: (value: any) => any): void => {
const scopedSearch = ephemeralState[panel];
if (!scopedSearch) {
return;
}

const { search, filters } = scopedSearch;
const hasFilters = search.length || Object.keys(filters).length;

store.dispatch(
setGenericSearch({
...scopedSearch,
...(hasFilters && {
open: true,
}),
})
);
};
// Put data from sessionStorage into redux store before triggering the sagas
if (ephemeralState) {
restoreSearchFor('places', setPlacesSearch);
restoreSearchFor('layers', setLayersSearch);

if (ephemeralState.global && ephemeralState.global.lastViewedPlace) {
store.dispatch(setLastViewedPlace(ephemeralState.global.lastViewedPlace));
}

ephemeralState.user && store.dispatch(setUserGroup(ephemeralState.user.group));

ephemeralState.map && store.dispatch(setMapStyle(ephemeralState.map.mapStyle));
}
};

0 comments on commit aef4002

Please sign in to comment.