import * as layout from './layout.actions' ; export interface State { openedModalName : string ; leftSidebarOpened : boolean ; rightSidebarOpened : boolean ; windowHeight : number ; windowWidth : number ; alerts : Array < Object > ; } const initialState = { openedModalName : null , leftSidebarOpened : true , rightSidebarOpened : false , windowHeight : window . screen . height , windowWidth : window . screen . width , alerts : [ ] , } ; export function reducer ( state = initialState , action ) { switch ( action . type ) { case layout . ADD_ALERT : { return Object . assign ( { } , state , { alerts : [ ... state . alerts , action . payload ] } ) ; } case layout . REMOVE_ALERT : { return Object . assign ( { } , state , { alerts : state . alerts . filter ( alert => alert [ 'message' ] !== action . payload [ 'message' ] ) } ) ; } case layout . OPEN_MODAL : { const name = action . payload ; return Object . assign ( { } , state , { openedModalName : name } ) ; } case layout . CLOSE_MODAL : { return Object . assign ( { } , state , { openedModalName : null } ) ; } case layout . CLOSE_LEFT_SIDENAV : { return Object . assign ( { } , state , { leftSidebarOpened : false } ) ; } case layout . OPEN_LEFT_SIDENAV : { return Object . assign ( { } , state , { leftSidebarOpened : true } ) ; } case layout . CLOSE_RIGHT_SIDENAV : { return Object . assign ( { } , state , { rightSidebarOpened : false } ) ; } case layout . OPEN_RIGHT_SIDENAV : { return Object . assign ( { } , state , { rightSidebarOpened : true } ) ; } case layout . RESIZE_WINDOW : { const height = action . payload [ 'height' ] ; const width = action . payload [ 'width' ] ; const leftSidebarState = width < 768 ? false : state . leftSidebarOpened ; return Object . assign ( { } , state , { windowHeight : height , windowWidth : width , leftSidebarOpened : leftSidebarState } ) ; } default : return state ; } } export const getOpenedModalName = ( state ) => state . openedModalName ; export const getLeftSidenavState = ( state ) => state . leftSidebarOpened ; export const getRightSidenavState = ( state ) => state . rightSidebarOpened ; export const getWindowWidth = ( state ) => state . windowWidth ; export const getWindowHeight = ( state ) => state . windowHeight ; export const getAlerts = ( state ) => state . alerts ;