diff options
Diffstat (limited to 'sdnr/wt/odlux/apps/maintenanceApp/src/handlers')
-rw-r--r-- | sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenanceAppRootHandler.ts | 27 | ||||
-rw-r--r-- | sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenenceEntriesHandler.ts | 40 |
2 files changed, 67 insertions, 0 deletions
diff --git a/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenanceAppRootHandler.ts b/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenanceAppRootHandler.ts new file mode 100644 index 000000000..956d05843 --- /dev/null +++ b/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenanceAppRootHandler.ts @@ -0,0 +1,27 @@ +// main state handler + +import { combineActionHandler } from '../../../../framework/src/flux/middleware'; + +import { IApplicationStoreState } from '../../../../framework/src/store/applicationStore'; + +import { IConnectAppStoreState } from '../../../connectApp/src/handlers/connectAppRootHandler'; + +import { IMaintenenceEntriesState, maintenenceEntriesActionHandler } from './maintenenceEntriesHandler'; + +export interface IMaintenanceAppStoreState { + maintenenceEntries : IMaintenenceEntriesState +} + +declare module '../../../../framework/src/store/applicationStore' { + interface IApplicationStoreState { + maintenanceApp: IMaintenanceAppStoreState, + connectApp: IConnectAppStoreState + } +} + +const actionHandlers = { + maintenenceEntries: maintenenceEntriesActionHandler +}; + +export const maintenanceAppRootHandler = combineActionHandler<IMaintenanceAppStoreState>(actionHandlers); +export default maintenanceAppRootHandler; diff --git a/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenenceEntriesHandler.ts b/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenenceEntriesHandler.ts new file mode 100644 index 000000000..13f4a3b6d --- /dev/null +++ b/sdnr/wt/odlux/apps/maintenanceApp/src/handlers/maintenenceEntriesHandler.ts @@ -0,0 +1,40 @@ +import { IActionHandler } from '../../../../framework/src/flux/action'; + +import { MaintenenceEntry } from '../models/maintenenceEntryType'; +import { LoadAllMainteneceEntriesAction, AllMainteneceEntriesLoadedAction, UpdateMaintenanceEntry } from '../actions/maintenenceActions'; + +export interface IMaintenenceEntriesState { + entries: MaintenenceEntry[]; + busy: boolean; +} + +const maintenanceEntriesStateInit: IMaintenenceEntriesState = { + entries: [], + busy: false +}; + +export const maintenenceEntriesActionHandler: IActionHandler<IMaintenenceEntriesState> = (state = maintenanceEntriesStateInit, action) => { + if (action instanceof LoadAllMainteneceEntriesAction){ + state = { + ...state, + busy: true, + } + } else if (action instanceof AllMainteneceEntriesLoadedAction){ + state = { + ...state, + entries: action.maintenenceEntries || [], + busy: false, + } + } else if (action instanceof UpdateMaintenanceEntry) { + const index = state.entries.findIndex(e => action.maintenenceEntry.mountId === e.mountId); + state = { + ...state, + entries: index > -1 ? [ + ...state.entries.slice(0, index), + action.maintenenceEntry, + ...state.entries.slice(index+1), + ] : [...state.entries, action.maintenenceEntry] + } + } + return state; +}
\ No newline at end of file |