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;