From 3d202a04b99f0e61b6ccf8b7a5610e1a15ca58e7 Mon Sep 17 00:00:00 2001 From: Herbert Eiselt Date: Mon, 11 Feb 2019 14:54:12 +0100 Subject: Add sdnr wt odlux Add complete sdnr wireless transport app odlux core and apps Change-Id: I5dcbfb8f3b790e3bda7c8df67bd69d81958f65e5 Issue-ID: SDNC-576 Signed-off-by: Herbert Eiselt --- .../src/handlers/applicationStateHandler.ts | 70 ++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 sdnr/wt/odlux/framework/src/handlers/applicationStateHandler.ts (limited to 'sdnr/wt/odlux/framework/src/handlers/applicationStateHandler.ts') diff --git a/sdnr/wt/odlux/framework/src/handlers/applicationStateHandler.ts b/sdnr/wt/odlux/framework/src/handlers/applicationStateHandler.ts new file mode 100644 index 000000000..2a952b61e --- /dev/null +++ b/sdnr/wt/odlux/framework/src/handlers/applicationStateHandler.ts @@ -0,0 +1,70 @@ +import { IActionHandler } from '../flux/action'; +import { SetTitleAction } from '../actions/titleActions'; + +import { AddSnackbarNotification, RemoveSnackbarNotification } from '../actions/snackbarActions'; +import { AddErrorInfoAction, RemoveErrorInfoAction, ClearErrorInfoAction } from '../actions/errorActions'; + +import { IconType } from '../models/iconDefinition'; + +import { ErrorInfo } from '../models/errorInfo'; +import { SnackbarItem } from '../models/snackbarItem'; + +export interface IApplicationState { + title: string; + icon?: IconType; + + errors: ErrorInfo[]; + snackBars: SnackbarItem[]; +} + +const applicationStateInit: IApplicationState = { title: "Loading ...", errors: [], snackBars:[] }; + +export const applicationStateHandler: IActionHandler = (state = applicationStateInit, action) => { + if (action instanceof SetTitleAction) { + state = { + ...state, + title: action.title, + icon: action.icon + }; + } else if (action instanceof AddErrorInfoAction) { + state = { + ...state, + errors: [ + ...state.errors, + action.errorInfo + ] + }; + } else if (action instanceof RemoveErrorInfoAction) { + const index = state.errors.indexOf(action.errorInfo); + if (index > -1) { + state = { + ...state, + errors: [ + ...state.errors.slice(0, index), + ...state.errors.slice(index + 1) + ] + }; + } + } else if (action instanceof ClearErrorInfoAction) { + if (state.errors && state.errors.length) { + state = { + ...state, + errors: [] + }; + } + } else if (action instanceof AddSnackbarNotification) { + state = { + ...state, + snackBars: [ + ...state.snackBars, + action.notification + ] + }; + } else if (action instanceof RemoveSnackbarNotification) { + state = { + ...state, + snackBars: state.snackBars.filter(s => s.key !== action.key) + }; + } + return state; +}; -- cgit 1.2.3-korg