This repository has been archived on 2023-12-22. You can view files and clone it, but cannot push or open issues or pull requests.
old-monorepo/Dashboard/src/redux/reducers/serialConnectionReducer.ts

59 lines
1.5 KiB
TypeScript
Raw Normal View History

2021-08-27 00:26:40 +02:00
import { createReducer } from "typesafe-actions";
import ISerialConnectionState from "../../interfaces/ISerialConnectionState";
import { SerialConnectionActionTypes } from "../actions/serialConnectionActions";
const initialState: ISerialConnectionState = {
port: null,
portController: null,
2021-08-27 00:26:40 +02:00
status: {
connecting: false,
connected: false,
error: null,
},
};
const SerialConnectionReducer = createReducer(initialState)
.handleType(SerialConnectionActionTypes.SET_SERIAL_PORT, (state, action) => ({
...state,
port: action.payload,
}))
.handleType(SerialConnectionActionTypes.CONNECTION_START, (state) => ({
...state,
status: {
connecting: true,
connected: false,
error: null,
},
}))
.handleType(SerialConnectionActionTypes.CONNECTION_FAILURE, (state, action) => ({
...state,
status: {
connecting: false,
connected: false,
error: action.payload.message,
},
}))
.handleType(SerialConnectionActionTypes.CONNECTION_SUCCESS, (state) => ({
...state,
status: {
connecting: false,
connected: true,
error: null,
},
}))
.handleType(SerialConnectionActionTypes.CONNECTION_END, (state) => ({
2021-08-27 00:26:40 +02:00
...state,
portController: null,
2021-08-27 00:26:40 +02:00
status: {
2021-08-27 20:03:26 +02:00
...state.status,
2021-08-27 00:26:40 +02:00
connecting: false,
connected: false,
},
}))
.handleType(SerialConnectionActionTypes.SET_PORT_CONTROLLER, (state, action) => ({
...state,
portController: action.payload,
2021-08-27 00:26:40 +02:00
}));
export default SerialConnectionReducer;