FarmMapsLib/projects/common/src/fm/reducers/app-common.reducer.ts

96 lines
3.1 KiB
TypeScript
Raw Normal View History

2019-07-15 14:54:19 +00:00
import { tassign } from 'tassign';
import { IItemTypes} from '../models/item.types';
import { IListItem } from '../models/list.item';
import { IUser } from '../models/user';
import * as appCommonActions from '../actions/app-common.actions';
import { createSelector, createFeatureSelector, ActionReducerMap } from '@ngrx/store';
import { MODULE_NAME } from '../module-name';
export interface State {
openedModalName: string,
initialized: boolean,
rootItems: IListItem[],
itemTypes: IItemTypes,
2019-11-04 17:47:15 +00:00
user:IUser,
fullScreen: boolean,
routeLoading:boolean
2019-07-15 14:54:19 +00:00
}
export const initialState: State = {
openedModalName: null,
initialized: false,
rootItems: [],
itemTypes: {},
2019-11-04 17:47:15 +00:00
user:null,
fullScreen: true,
routeLoading: false
2019-07-15 14:54:19 +00:00
}
export function reducer(state = initialState, action: appCommonActions.Actions ): State {
switch (action.type) {
case appCommonActions.INITUSERSUCCESS: {
let a = action as appCommonActions.InitUserSuccess;
return tassign(state, { user: a.user });
}
case appCommonActions.INITROOTSUCCESS: {
let a = action as appCommonActions.InitRootSuccess;
return tassign(state, { rootItems:a.items});
}
case appCommonActions.OPENMODAL: {
return tassign(state, { openedModalName: action.modalName });
}
case appCommonActions.CLOSEMODAL: {
return tassign(state, { openedModalName: null });
}
case appCommonActions.INITIALIZED: {
return tassign(state, { initialized: true });
}
case appCommonActions.LOADITEMTYPESSUCCESS: {
let a = action as appCommonActions.LoadItemTypesSuccess;
return tassign(state, { itemTypes: a.itemTypes });
}
2019-11-04 17:47:15 +00:00
case appCommonActions.FULLSCREEN: {
return tassign(state, {
fullScreen:true
});
}
case appCommonActions.SHOWNAVBAR: {
return tassign(state, {
fullScreen: false
});
}
case appCommonActions.STARTROUTELOADING: {
return tassign(state, {
routeLoading: true
});
}
case appCommonActions.ENDROUTELOADING: {
return tassign(state, {
routeLoading: false
});
}
2019-07-15 14:54:19 +00:00
default: {
return state;
}
}
}
export const getOpenedModalName = (state: State) => state.openedModalName;
export const getInitialized = (state: State) => state.initialized;
export const getItemTypes = (state: State) => state.itemTypes;
export const getRootItems = (state: State) => state.rootItems;
2019-11-04 17:47:15 +00:00
export const getFullScreen = (state: State) => state.fullScreen;
export const getRouteLoading = (state: State) => state.routeLoading;
2019-07-15 14:54:19 +00:00
export const selectAppCommonState = createFeatureSelector<State>(MODULE_NAME);
export const selectOpenedModalName = createSelector(selectAppCommonState, getOpenedModalName);
export const selectGetInitialized = createSelector(selectAppCommonState, getInitialized);
export const selectGetItemTypes = createSelector(selectAppCommonState, getItemTypes);
export const selectGetRootItems = createSelector(selectAppCommonState, getRootItems);
2019-11-04 17:47:15 +00:00
export const selectGetFullScreen = createSelector(selectAppCommonState, getFullScreen);
export const selectGetRouteLoading = createSelector(selectAppCommonState, getRouteLoading);