Fixed updates from @christiancp

This commit is contained in:
Claudio Maggioni (maggicl) 2020-05-01 11:18:25 +02:00
parent 146aae1684
commit 292a33e5bc
4 changed files with 102 additions and 86 deletions

View file

@ -26,7 +26,7 @@ class DevicePanel extends Component {
return ( return (
<Grid <Grid
doubling doubling
columns={2} columns={3}
divided="vertically" divided="vertically"
style={{ paddingTop: "3rem" }} style={{ paddingTop: "3rem" }}
> >

View file

@ -7,11 +7,18 @@ import Switcher from "./Switch";
import Videocam from "./Videocam"; import Videocam from "./Videocam";
import Curtains from "./Curtain"; import Curtains from "./Curtain";
import Thermostat from "./Thermostats"; 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 { RemoteService } from "../../../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
import DeviceSettingsModal from "./DeviceSettingsModal"; import DeviceSettingsModal from "./DeviceSettingsModal";
const centerComponent = {
marginLeft: "50%",
transform: "translateX(-50%)",
marginTop: "10%",
marginBottom: "10%",
};
class Device extends React.Component { class Device extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
@ -101,75 +108,83 @@ class Device extends React.Component {
<Videocam id={this.props.stateOrDevice.id} tab={this.props.tab} /> <Videocam id={this.props.stateOrDevice.id} tab={this.props.tab} />
); );
default: default:
//throw new Error("Device type unknown"); throw new Error("Device type unknown");
return undefined;
} }
} }
deviceDescription() {
return (
<div className="ui two buttons">
<Button color="blue" icon onClick={this.edit} labelPosition="left">
<Icon name="pencil" />
Edit
</Button>
{this.props.stateOrDevice.kind === "smartPlug" ? (
<Button
color="orange"
icon
onClick={this.resetSmartPlug}
labelPosition="left"
>
<Icon name="undo" />
Reset
</Button>
) : null}
</div>
);
}
stateDescription() {
return (
<div class="ui one button">
<Button
color="red"
icon
onClick={this.deleteState}
labelPosition="left"
>
<Icon name="undo" />
Delete
</Button>
</div>
);
}
get deviceName() {
return this.props.tab === "Devices"
? this.props.stateOrDevice.name
: this.props.device.name;
}
render() { render() {
{ {
if (this.props.type !== "") { return (
return ( <Card>
<Segment> <Card.Content>
<Grid columns={2}> <Card.Header textAlign="center">
<Grid.Column>{this.renderDeviceComponent()}</Grid.Column> <Header as="h3">{this.deviceName}</Header>
{this.props.tab === "Devices" ? ( {this.props.tab === "Scenes" ? (
<Grid.Column textAlign="center"> <Header as="h4">{this.props.roomName}</Header>
<Header as="h3">{this.props.stateOrDevice.name}</Header>
<Button
color="blue"
icon
onClick={this.edit}
labelPosition="left"
>
<Icon name="pencil" />
Edit
</Button>
{this.props.stateOrDevice.kind === "smartPlug" ? (
<Button
color="orange"
icon
onClick={this.resetSmartPlug}
labelPosition="left"
>
<Icon name="undo" />
Reset
</Button>
) : null}
</Grid.Column>
) : ( ) : (
<Grid.Column textAlign="center"> ""
<Header as="h3">{this.props.device.name}</Header>
{this.props.tab === "Scenes" ? (
<Header as="h4">{this.props.roomName}</Header>
) : (
""
)}
<Button
color="red"
icon
onClick={this.deleteState}
labelPosition="left"
>
<Icon name="undo" />
Delete
</Button>
</Grid.Column>
)} )}
</Grid> </Card.Header>
{this.props.stateOrDevice && this.props.tab === "Devices" ? (
<DeviceSettingsModal <Card.Description style={centerComponent}>
ref={this.modalRef} {this.renderDeviceComponent()}
id={this.props.stateOrDevice.id} </Card.Description>
/> </Card.Content>
) : ( <Card.Content extra>
"" {this.props.tab === "Devices"
)} ? this.deviceDescription()
</Segment> : this.stateDescription()}
); </Card.Content>
} else { <DeviceSettingsModal
return null; ref={this.modalRef}
} id={this.props.stateOrDevice.id}
/>
</Card>
);
} }
} }
} }
@ -198,7 +213,6 @@ const mapStateToProps = (state, ownProps) => ({
} }
}, },
get type() { get type() {
console.log("ALPACA", state, ownProps);
if (state.active.activeTab === "Scenes") { if (state.active.activeTab === "Scenes") {
if (state.sceneStates[ownProps.id]) { if (state.sceneStates[ownProps.id]) {
//console.log(state.sceneStates[ownProps.id], ownProps.id); //console.log(state.sceneStates[ownProps.id], ownProps.id);

View file

@ -26,26 +26,24 @@ const DeleteModal = (props) => (
); );
const SettingsForm = (props) => { const SettingsForm = (props) => {
const handleInputChange = (e) => {
const { name, value } = e.target;
setValues({ ...values, [name]: value });
};
const [values, setValues] = useState({ name: "" }); const [values, setValues] = useState({ name: "" });
const handleInputChange = (e) => { console.log(props);
const { name, value } = e.target.value;
setValues({ ...values, [name]: value });
console.log("EDDDDITING!!", e.target.value);
console.log(props);
};
return ( return (
<Form> <Form>
<Form.Field> <Form.Field>
<label>Edit Name:</label> <label>Edit Name: </label>
<input <Input
autoComplete="off" autoComplete="off"
name="name" name="name"
onChange={handleInputChange} onChange={handleInputChange}
value={props.name} placeholder={props.name}
autoFocus="on"
placeholder="Device name"
/> />
</Form.Field> </Form.Field>
@ -109,20 +107,25 @@ class DeviceSettingsModal extends Component {
); );
} }
_editForm = null;
get editForm() {
this._editForm = this._editForm || (
<SettingsForm
name={this.state.name}
removeDevice={this.deleteDevice}
saveFunction={this.updateDevice}
/>
);
return this._editForm;
}
render() { render() {
const SettingsModal = () => ( return (
<Modal closeIcon onClose={this.closeModal} open={this.state.openModal}> <Modal closeIcon onClose={this.closeModal} open={this.state.openModal}>
<Modal.Header>Settings of {this.props.device.name}</Modal.Header> <Modal.Header>Settings of {this.props.device.name}</Modal.Header>
<Modal.Content> <Modal.Content>{this.editForm}</Modal.Content>
<SettingsForm
name={this.state.name}
removeDevice={this.deleteDevice}
saveFunction={this.updateDevice}
/>
</Modal.Content>
</Modal> </Modal>
); );
return <SettingsModal />;
} }
} }

View file

@ -499,7 +499,6 @@ function reducer(previousState, action) {
console.warn(`Action type ${action.type} unknown`, action); console.warn(`Action type ${action.type} unknown`, action);
return previousState; return previousState;
} }
console.log("THETRUEALPACA", newState, action.type, action);
return newState; return newState;
} }