49 lines
1.5 KiB
JavaScript
49 lines
1.5 KiB
JavaScript
import React, {Component} from 'react';
|
|
import {Image} from "semantic-ui-react";
|
|
import {iconStyle, nameStyle, StyledDiv} from "./styleComponents";
|
|
import Settings from './DeviceSettings';
|
|
|
|
|
|
export default class Device extends Component {
|
|
constructor(props) {
|
|
super(props);
|
|
this.state = {
|
|
turnOnOff: "off",
|
|
icon: this.props.device.img
|
|
}
|
|
}
|
|
|
|
onClickDevice = () => {
|
|
if (!this.props.edit) {
|
|
if (this.props.device.type === "light") {
|
|
if (this.state.turnOnOff === "on") {
|
|
this.setState({
|
|
turnOnOff: "off",
|
|
icon: this.props.device.img
|
|
});
|
|
} else {
|
|
this.setState({
|
|
turnOnOff: "on",
|
|
icon: this.props.device.imgClick
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
render() {
|
|
return (
|
|
<StyledDiv onClick={this.props.edit ? () => {
|
|
} : this.onClickDevice} style={{textAlign: "center"}}>
|
|
<Settings
|
|
deviceId={this.props.device.id}
|
|
edit={this.props.edit}
|
|
onChangeData={(id, newSettings) => this.props.onChangeData(id, newSettings)}/>
|
|
<Image src={this.state.icon} style={iconStyle}/>
|
|
<h5 style={nameStyle}>{this.props.device.name}</h5>
|
|
</StyledDiv>
|
|
)
|
|
}
|
|
}
|
|
|
|
|