From 2d9bdf63fb2302bc06f517479baf846811fa18e4 Mon Sep 17 00:00:00 2001 From: britea Date: Sat, 25 Apr 2020 18:23:40 +0200 Subject: [PATCH] fixed problem in scene state --- .../components/dashboard/devices/Device.js | 100 ++++++++++-------- smart-hut/src/store.js | 6 +- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index ecc650b..fe025ab 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -127,52 +127,59 @@ class Device extends React.Component { tab={this.props.tab} /> ); - case "": - return ""; default: - throw new Error("Device type unknown"); + //throw new Error("Device type unknown"); + return undefined; } } render() { - return ( - - - {this.renderDeviceComponent()} - {this.props.tab === "Devices" ? ( - -
{this.props.stateOrDevice.name}
- - {this.props.stateOrDevice.kind === "smartPlug" ? ( - - ) : null} -
- ) : ( - -
- {this.props.stateOrDevice ? this.props.stateOrDevice.name : ""} -
-
- )} -
-
- ); + { + if (this.props.type !== "") { + return ( + + + {this.renderDeviceComponent()} + {this.props.tab === "Devices" ? ( + +
{this.props.stateOrDevice.name}
+ + {this.props.stateOrDevice.kind === "smartPlug" ? ( + + ) : null} +
+ ) : ( + +
+ {this.props.stateOrDevice + ? this.props.stateOrDevice.name + : ""} +
+
+ )} +
+
+ ); + } else { + return null; + } + } } } /* @@ -211,9 +218,14 @@ const mapStateToProps = (state, ownProps) => ({ }, get type() { if (state.active.activeTab === "Scenes") { - const id = state.sceneStates[ownProps.id].deviceId; - console.log(id, state.devices[id].kind); - return state.devices[id].kind; + if (state.sceneStates[ownProps.id]) { + console.log(state.sceneStates[ownProps.id], ownProps.id); + const id = state.sceneStates[ownProps.id].deviceId; + console.log(id, state.devices[id].kind); + return state.devices[id].kind; + } else { + return ""; + } } else { return null; } diff --git a/smart-hut/src/store.js b/smart-hut/src/store.js index 8e9be90..a8362c7 100644 --- a/smart-hut/src/store.js +++ b/smart-hut/src/store.js @@ -81,7 +81,9 @@ function reducer(previousState, action) { const updateSceneStateProps = (state) => { change.sceneStates[state.id] = {}; - change.sceneStates[state.id] = { $set: state.id }; + for (const key in state) { + change.sceneStates[state.id][key] = { $set: state[key] }; + } }; switch (action.type) { @@ -104,7 +106,7 @@ function reducer(previousState, action) { } break; case "STATE_UPDATE": - console.log(action.sceneStates); + //console.log(action.sceneStates); newState = previousState; change = null;