From 292a33e5bcb9c8132dc9746648282b0e78215228 Mon Sep 17 00:00:00 2001 From: "Claudio Maggioni (maggicl)" Date: Fri, 1 May 2020 11:18:25 +0200 Subject: [PATCH] Fixed updates from @christiancp --- .../src/components/dashboard/DevicePanel.js | 2 +- .../components/dashboard/devices/Device.js | 142 ++++++++++-------- .../dashboard/devices/DeviceSettingsModal.js | 43 +++--- smart-hut/src/store.js | 1 - 4 files changed, 102 insertions(+), 86 deletions(-) diff --git a/smart-hut/src/components/dashboard/DevicePanel.js b/smart-hut/src/components/dashboard/DevicePanel.js index 2fb222d..70f34f5 100644 --- a/smart-hut/src/components/dashboard/DevicePanel.js +++ b/smart-hut/src/components/dashboard/DevicePanel.js @@ -26,7 +26,7 @@ class DevicePanel extends Component { return ( diff --git a/smart-hut/src/components/dashboard/devices/Device.js b/smart-hut/src/components/dashboard/devices/Device.js index 17ad4c7..954c67e 100644 --- a/smart-hut/src/components/dashboard/devices/Device.js +++ b/smart-hut/src/components/dashboard/devices/Device.js @@ -7,11 +7,18 @@ import Switcher from "./Switch"; import Videocam from "./Videocam"; import Curtains from "./Curtain"; import Thermostat from "./Thermostats"; -import { Segment, Grid, Header, Button, Icon } from "semantic-ui-react"; +import { Segment, Grid, Header, Button, Icon, Card } from "semantic-ui-react"; import { RemoteService } from "../../../remote"; import { connect } from "react-redux"; import DeviceSettingsModal from "./DeviceSettingsModal"; +const centerComponent = { + marginLeft: "50%", + transform: "translateX(-50%)", + marginTop: "10%", + marginBottom: "10%", +}; + class Device extends React.Component { constructor(props) { super(props); @@ -101,75 +108,83 @@ class Device extends React.Component { ); default: - //throw new Error("Device type unknown"); - return undefined; + throw new Error("Device type unknown"); } } + deviceDescription() { + return ( +
+ + {this.props.stateOrDevice.kind === "smartPlug" ? ( + + ) : null} +
+ ); + } + + stateDescription() { + return ( +
+ +
+ ); + } + + get deviceName() { + return this.props.tab === "Devices" + ? this.props.stateOrDevice.name + : this.props.device.name; + } + render() { { - if (this.props.type !== "") { - return ( - - - {this.renderDeviceComponent()} - {this.props.tab === "Devices" ? ( - -
{this.props.stateOrDevice.name}
- - {this.props.stateOrDevice.kind === "smartPlug" ? ( - - ) : null} -
+ return ( + + + +
{this.deviceName}
+ {this.props.tab === "Scenes" ? ( +
{this.props.roomName}
) : ( - -
{this.props.device.name}
- {this.props.tab === "Scenes" ? ( -
{this.props.roomName}
- ) : ( - "" - )} - -
+ "" )} -
- {this.props.stateOrDevice && this.props.tab === "Devices" ? ( - - ) : ( - "" - )} -
- ); - } else { - return null; - } + + + + {this.renderDeviceComponent()} + + + + {this.props.tab === "Devices" + ? this.deviceDescription() + : this.stateDescription()} + + + + ); } } } @@ -198,7 +213,6 @@ const mapStateToProps = (state, ownProps) => ({ } }, get type() { - console.log("ALPACA", state, ownProps); if (state.active.activeTab === "Scenes") { if (state.sceneStates[ownProps.id]) { //console.log(state.sceneStates[ownProps.id], ownProps.id); diff --git a/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js b/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js index 5a563e6..fc7956b 100644 --- a/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js +++ b/smart-hut/src/components/dashboard/devices/DeviceSettingsModal.js @@ -26,26 +26,24 @@ const DeleteModal = (props) => ( ); const SettingsForm = (props) => { + const handleInputChange = (e) => { + const { name, value } = e.target; + setValues({ ...values, [name]: value }); + }; + const [values, setValues] = useState({ name: "" }); - const handleInputChange = (e) => { - const { name, value } = e.target.value; - setValues({ ...values, [name]: value }); - console.log("EDDDDITING!!", e.target.value); - console.log(props); - }; + console.log(props); return (
- - Edit Name: + @@ -109,20 +107,25 @@ class DeviceSettingsModal extends Component { ); } + _editForm = null; + get editForm() { + this._editForm = this._editForm || ( + + ); + return this._editForm; + } + render() { - const SettingsModal = () => ( + return ( Settings of {this.props.device.name} - - - + {this.editForm} ); - return ; } } diff --git a/smart-hut/src/store.js b/smart-hut/src/store.js index eade971..002c0db 100644 --- a/smart-hut/src/store.js +++ b/smart-hut/src/store.js @@ -499,7 +499,6 @@ function reducer(previousState, action) { console.warn(`Action type ${action.type} unknown`, action); return previousState; } - console.log("THETRUEALPACA", newState, action.type, action); return newState; }