From 5c4b1abbfa20de1155109cffb7c878603981b93b Mon Sep 17 00:00:00 2001 From: Ghost <31184695+GHOSCHT@users.noreply.github.com> Date: Mon, 10 Aug 2020 14:56:13 +0200 Subject: [PATCH] Add connection reducer --- .../app/renderer/store/actions/actionTypes.js | 4 ++++ .../reducers/comConnectionStatusReducer.js | 17 +++++++++++++++++ Dashboard/app/renderer/store/reducers/index.js | 3 ++- 3 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 Dashboard/app/renderer/store/actions/actionTypes.js create mode 100644 Dashboard/app/renderer/store/reducers/comConnectionStatusReducer.js diff --git a/Dashboard/app/renderer/store/actions/actionTypes.js b/Dashboard/app/renderer/store/actions/actionTypes.js new file mode 100644 index 0000000..db231f5 --- /dev/null +++ b/Dashboard/app/renderer/store/actions/actionTypes.js @@ -0,0 +1,4 @@ +export const SET_CONNECTION_PARAMS = 'SET_CONNECTION_PARAMS'; +export const CONNECT = 'CONNECT'; +export const DISCONNECT = 'DISCONNECT'; +export const SET_CONNECTION_STATUS = 'SET_CONNECTION_STATUS'; diff --git a/Dashboard/app/renderer/store/reducers/comConnectionStatusReducer.js b/Dashboard/app/renderer/store/reducers/comConnectionStatusReducer.js new file mode 100644 index 0000000..e965254 --- /dev/null +++ b/Dashboard/app/renderer/store/reducers/comConnectionStatusReducer.js @@ -0,0 +1,17 @@ +import { SET_CONNECTION_STATUS } from '../actions/actionTypes'; + +const initialState = false; + +export default (state = initialState, { type, payload }) => { + switch (type) { + case SET_CONNECTION_STATUS: + if (typeof payload === 'boolean') { + return payload; + } else { + return state; + } + + default: + return state; + } +}; diff --git a/Dashboard/app/renderer/store/reducers/index.js b/Dashboard/app/renderer/store/reducers/index.js index 916f388..41c47ae 100644 --- a/Dashboard/app/renderer/store/reducers/index.js +++ b/Dashboard/app/renderer/store/reducers/index.js @@ -1,6 +1,7 @@ import { combineReducers } from 'redux'; import comConnectionReducer from './comConnectionReducer'; +import comConnectionStatusReducer from './comConnectionStatusReducer'; -const rootReducer = combineReducers({ comConnectionReducer }); +const rootReducer = combineReducers({ comConnectionReducer, comConnectionStatusReducer }); export default rootReducer;