diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index ae4451c..e6cc7f9 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -25,7 +25,7 @@ class DevicePanel extends Component { render() { return (
- + {this.props.devices.map((e, i) => { return ( diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 2f4410f..ef202ac 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -4,7 +4,7 @@ import SmartPlug from "./SmartPlug"; import Sensor from "./Sensor"; import { ButtonDimmer, KnobDimmer } from "./Dimmer"; import Switcher from "./Switch"; -import { Segment } from "semantic-ui-react"; +import { Segment, Grid, Header, Button, Icon } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { connect } from "react-redux"; import DeviceSettingsModal from "./DeviceSettingsModal"; @@ -25,7 +25,7 @@ class Device extends React.Component { resetSmartPlug() { this.props - .resetSmartPlug(this.props.id) + .smartPlugReset(this.props.id) .catch((err) => console.error(`Smart plug reset error`, err)); } @@ -55,14 +55,26 @@ class Device extends React.Component { render() { return ( - {this.renderDeviceComponent()} -

{this.props.device.name}

- - {this.props.device.type === "smartPlug" ? ( - - ) : null} - - + + + {this.renderDeviceComponent()} + + +
{this.props.device.name}
+ + {this.props.device.kind === "smartPlug" ? ( + + ) : null} +
+ +
); } diff --git a/smart-hut/src/components/dashboard/devices/NewDevice.js b/smart-hut/src/components/dashboard/devices/NewDevice.js index 5616ae0..b0fda2a 100644 --- a/smart-hut/src/components/dashboard/devices/NewDevice.js +++ b/smart-hut/src/components/dashboard/devices/NewDevice.js @@ -9,6 +9,8 @@ import { Input, Modal, } from "semantic-ui-react"; +import { RemoteService } from "../../../remote"; +import { connect } from "react-redux"; const StyledDiv = styled.div` background-color: #505bda; @@ -29,7 +31,7 @@ const StyledDiv = styled.div` } `; -export default class NewDevice extends Component { +class NewDevice extends Component { constructor(props) { super(props); this.state = { @@ -376,3 +378,12 @@ export default class NewDevice extends Component { ); } } + +const mapStateToProps = (state, _) => ({ + devices: Object.values(state.devices) +}); +const NewDeviceContainer = connect( + mapStateToProps, + RemoteService +)(NewDevice); +export default NewDeviceContainer; \ No newline at end of file diff --git a/smart-hut/src/store.js b/smart-hut/src/store.js index f988a63..6e4bc49 100644 --- a/smart-hut/src/store.js +++ b/smart-hut/src/store.js @@ -106,6 +106,8 @@ function reducer(previousState, action) { change.devices[device.id] = { $set: device }; if (device.roomId in newState.rooms) { + change.rooms[device.roomId] = {}; + change.rooms[device.roomId].devices = {}; const devices = change.rooms[device.roomId].devices; devices.$add = devices.$add || []; devices.$add.push(device.id); diff --git a/smart-hut/src/storeActions.js b/smart-hut/src/storeActions.js index 3da8e33..3a20fee 100644 --- a/smart-hut/src/storeActions.js +++ b/smart-hut/src/storeActions.js @@ -27,6 +27,11 @@ const actions = { devices, partial, }), + deviceOperationUpdate: (devices) => ({ + type: "DEVICES_UPDATE", + devices, + partial: true, + }), roomsUpdate: (rooms) => ({ type: "ROOMS_UPDATE", rooms,