Fixed updates from @christiancp
This commit is contained in:
parent
146aae1684
commit
292a33e5bc
4 changed files with 102 additions and 86 deletions
|
@ -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" }}
|
||||||
>
|
>
|
||||||
|
|
|
@ -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,27 +108,14 @@ 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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
deviceDescription() {
|
||||||
{
|
|
||||||
if (this.props.type !== "") {
|
|
||||||
return (
|
return (
|
||||||
<Segment>
|
<div className="ui two buttons">
|
||||||
<Grid columns={2}>
|
<Button color="blue" icon onClick={this.edit} labelPosition="left">
|
||||||
<Grid.Column>{this.renderDeviceComponent()}</Grid.Column>
|
|
||||||
{this.props.tab === "Devices" ? (
|
|
||||||
<Grid.Column textAlign="center">
|
|
||||||
<Header as="h3">{this.props.stateOrDevice.name}</Header>
|
|
||||||
<Button
|
|
||||||
color="blue"
|
|
||||||
icon
|
|
||||||
onClick={this.edit}
|
|
||||||
labelPosition="left"
|
|
||||||
>
|
|
||||||
<Icon name="pencil" />
|
<Icon name="pencil" />
|
||||||
Edit
|
Edit
|
||||||
</Button>
|
</Button>
|
||||||
|
@ -136,15 +130,13 @@ class Device extends React.Component {
|
||||||
Reset
|
Reset
|
||||||
</Button>
|
</Button>
|
||||||
) : null}
|
) : null}
|
||||||
</Grid.Column>
|
</div>
|
||||||
) : (
|
);
|
||||||
<Grid.Column textAlign="center">
|
}
|
||||||
<Header as="h3">{this.props.device.name}</Header>
|
|
||||||
{this.props.tab === "Scenes" ? (
|
stateDescription() {
|
||||||
<Header as="h4">{this.props.roomName}</Header>
|
return (
|
||||||
) : (
|
<div class="ui one button">
|
||||||
""
|
|
||||||
)}
|
|
||||||
<Button
|
<Button
|
||||||
color="red"
|
color="red"
|
||||||
icon
|
icon
|
||||||
|
@ -154,22 +146,45 @@ class Device extends React.Component {
|
||||||
<Icon name="undo" />
|
<Icon name="undo" />
|
||||||
Delete
|
Delete
|
||||||
</Button>
|
</Button>
|
||||||
</Grid.Column>
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
get deviceName() {
|
||||||
|
return this.props.tab === "Devices"
|
||||||
|
? this.props.stateOrDevice.name
|
||||||
|
: this.props.device.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
{
|
||||||
|
return (
|
||||||
|
<Card>
|
||||||
|
<Card.Content>
|
||||||
|
<Card.Header textAlign="center">
|
||||||
|
<Header as="h3">{this.deviceName}</Header>
|
||||||
|
{this.props.tab === "Scenes" ? (
|
||||||
|
<Header as="h4">{this.props.roomName}</Header>
|
||||||
|
) : (
|
||||||
|
""
|
||||||
)}
|
)}
|
||||||
</Grid>
|
</Card.Header>
|
||||||
{this.props.stateOrDevice && this.props.tab === "Devices" ? (
|
|
||||||
|
<Card.Description style={centerComponent}>
|
||||||
|
{this.renderDeviceComponent()}
|
||||||
|
</Card.Description>
|
||||||
|
</Card.Content>
|
||||||
|
<Card.Content extra>
|
||||||
|
{this.props.tab === "Devices"
|
||||||
|
? this.deviceDescription()
|
||||||
|
: this.stateDescription()}
|
||||||
|
</Card.Content>
|
||||||
<DeviceSettingsModal
|
<DeviceSettingsModal
|
||||||
ref={this.modalRef}
|
ref={this.modalRef}
|
||||||
id={this.props.stateOrDevice.id}
|
id={this.props.stateOrDevice.id}
|
||||||
/>
|
/>
|
||||||
) : (
|
</Card>
|
||||||
""
|
|
||||||
)}
|
|
||||||
</Segment>
|
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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);
|
||||||
|
|
|
@ -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) => {
|
|
||||||
const { name, value } = e.target.value;
|
|
||||||
setValues({ ...values, [name]: value });
|
|
||||||
console.log("EDDDDITING!!", e.target.value);
|
|
||||||
console.log(props);
|
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 {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
_editForm = null;
|
||||||
const SettingsModal = () => (
|
get editForm() {
|
||||||
<Modal closeIcon onClose={this.closeModal} open={this.state.openModal}>
|
this._editForm = this._editForm || (
|
||||||
<Modal.Header>Settings of {this.props.device.name}</Modal.Header>
|
|
||||||
<Modal.Content>
|
|
||||||
<SettingsForm
|
<SettingsForm
|
||||||
name={this.state.name}
|
name={this.state.name}
|
||||||
removeDevice={this.deleteDevice}
|
removeDevice={this.deleteDevice}
|
||||||
saveFunction={this.updateDevice}
|
saveFunction={this.updateDevice}
|
||||||
/>
|
/>
|
||||||
</Modal.Content>
|
);
|
||||||
|
return this._editForm;
|
||||||
|
}
|
||||||
|
|
||||||
|
render() {
|
||||||
|
return (
|
||||||
|
<Modal closeIcon onClose={this.closeModal} open={this.state.openModal}>
|
||||||
|
<Modal.Header>Settings of {this.props.device.name}</Modal.Header>
|
||||||
|
<Modal.Content>{this.editForm}</Modal.Content>
|
||||||
</Modal>
|
</Modal>
|
||||||
);
|
);
|
||||||
return <SettingsModal />;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue