Refactor map component
All checks were successful
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good

This commit is contained in:
Willem Dantuma
2020-10-28 13:31:12 +01:00
parent fad2f19ae4
commit 9fb5a9698c
4 changed files with 123 additions and 123 deletions

View File

@@ -57,8 +57,8 @@ export interface State {
selectedOverlayLayer: IItemLayer,
styles:IStyles,
showLayerSwitcher:boolean,
setStateCount:number,
inSearch:boolean,
inZoom:boolean,
replaceUrl:boolean
}
@@ -96,8 +96,8 @@ export const initialState: State = {
selectedItemLayer: null,
styles: {},
showLayerSwitcher: false,
setStateCount: 0,
inSearch:false,
inZoom:false,
replaceUrl:true
}
@@ -110,16 +110,16 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
case mapActions.SETMAPSTATE: {
let a = action as mapActions.SetMapState;
return tassign(state, {
mapState: a.mapState,setStateCount: state.setStateCount+1
mapState: a.mapState
});
}
case mapActions.SETQUERYSTATE: {
let a = action as mapActions.SetQueryState;
return tassign(state, { queryState: tassign(a.queryState ),setStateCount: state.setStateCount+1,replaceUrl:a.replaceUrl});
return tassign(state, { queryState: tassign(a.queryState ),replaceUrl:a.replaceUrl});
}
case mapActions.SETSTATE: {
let a = action as mapActions.SetState;
return tassign(state, { mapState: tassign(a.mapState), queryState: tassign(a.queryState),setStateCount: state.setStateCount+1});
return tassign(state, { mapState: tassign(a.mapState), queryState: tassign(a.queryState)});
}
case mapActions.SETVIEWEXTENT: {
let a = action as mapActions.SetViewExtent;
@@ -147,7 +147,7 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
case mapActions.SELECTITEM: {
let a = action as mapActions.SelectItem;
let itemCode = state.selectedItem ? state.selectedItem.code : "";
let inSearch = (a.itemCode != itemCode || state.setStateCount == 1)
let inSearch = a.itemCode != itemCode;
return tassign(state, {
selectedItem: null,
selectedItemLayer: null,
@@ -316,7 +316,7 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
case mapActions.SETEXTENT: {
let a = action as mapActions.SetExtent;
return tassign(state, { extent: a.extent });
}
}
case mapActions.ADDLAYER: {
let a = action as mapActions.AddLayer;
let itemLayers = state.overlayLayers.slice(0);
@@ -436,27 +436,24 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
let a = action as mapActions.SelectOverlayLayer;
return tassign(state, { selectedOverlayLayer: a.itemLayer });
}
case commonActions.ESCAPE: {
let a = action as commonActions.Escape;
case mapActions.CLEAR: {
let newQueryState = tassign(state.queryState, { query: null, tags: null, itemCode: null, parentCode: null, itemType: null });
if (a.escapeKey) {
return tassign(state, {
panelVisible: false,
panelCollapsed:false,
selectedItem: null,
selectedItemLayer: null,
selectedFeature: null,
queryState: newQueryState,
clearEnabled: false,
searchCollapsed: true,
searchMinified: false,
features: [],
query:initialState.query,
showLayerSwitcher: false
});
} else {
return tassign(state, {});
}
return tassign(state, {
panelVisible: false,
panelCollapsed:false,
selectedItem: null,
selectedItemLayer: null,
selectedFeature: null,
queryState: newQueryState,
clearEnabled: false,
searchCollapsed: true,
searchMinified: false,
features: [],
query:initialState.query,
showLayerSwitcher: false,
extent: null
});
}
case mapActions.SETSTYLE:{
let a = action as mapActions.SetStyle;
@@ -471,10 +468,7 @@ export function reducer(state = initialState, action: mapActions.Actions | commo
case mapActions.SETREPLACEURL: {
let a= action as mapActions.SetReplaceUrl;
return tassign(state,{replaceUrl:a.replaceUrl});
}
case mapActions.CLEAR: {
return tassign(state,{setStateCount:0});
}
}
default: {
return state;
}
@@ -504,9 +498,8 @@ export const getSelectedItemLayer = (state: State) => state.selectedItemLayer;
export const getPeriod = (state:State) => state.period;
export const getStyles = (state:State) => state.styles;
export const getShowLayerSwitcher = (state:State) => state.showLayerSwitcher;
export const getSetStateCount = (state:State) => state.setStateCount;
export const getInSearch = (state:State) => state.inSearch;
export const getState = (state:State) => {return {mapState:state.mapState,queryState:state.queryState,setStateCount:state.setStateCount,replaceUrl:state.replaceUrl};}
export const getState = (state:State) => {return {mapState:state.mapState,queryState:state.queryState,replaceUrl:state.replaceUrl};}
export const selectMapState = createFeatureSelector<State>(MODULE_NAME);
export const selectGetMapState= createSelector(selectMapState, getMapState);
@@ -532,7 +525,6 @@ export const selectGetSelectedItemLayer = createSelector(selectMapState, getSele
export const selectGetPeriod = createSelector(selectMapState, getPeriod);
export const selectGetStyles = createSelector(selectMapState, getStyles);
export const selectGetShowLayerSwitcher = createSelector(selectMapState,getShowLayerSwitcher);
export const selectgetSetStateCount = createSelector(selectMapState,getSetStateCount);
export const selectGetInSearch = createSelector(selectMapState,getInSearch);
export const selectGetState = createSelector(selectMapState,getState);