Fixed bugs on previous refactors

This commit is contained in:
Claudio Maggioni (maggicl) 2020-04-10 23:13:23 +02:00
parent 7b430045e7
commit b5cbad53d1
5 changed files with 42 additions and 12 deletions

View file

@ -25,7 +25,7 @@ class DevicePanel extends Component {
render() { render() {
return ( return (
<div style={panelStyle}> <div style={panelStyle}>
<Grid doubling columns={4} divided="vertically"> <Grid doubling columns={2} divided="vertically">
{this.props.devices.map((e, i) => { {this.props.devices.map((e, i) => {
return ( return (
<Grid.Column key={i}> <Grid.Column key={i}>

View file

@ -4,7 +4,7 @@ import SmartPlug from "./SmartPlug";
import Sensor from "./Sensor"; import Sensor from "./Sensor";
import { ButtonDimmer, KnobDimmer } from "./Dimmer"; import { ButtonDimmer, KnobDimmer } from "./Dimmer";
import Switcher from "./Switch"; 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 { RemoteService } from "../../../remote";
import { connect } from "react-redux"; import { connect } from "react-redux";
import DeviceSettingsModal from "./DeviceSettingsModal"; import DeviceSettingsModal from "./DeviceSettingsModal";
@ -25,7 +25,7 @@ class Device extends React.Component {
resetSmartPlug() { resetSmartPlug() {
this.props this.props
.resetSmartPlug(this.props.id) .smartPlugReset(this.props.id)
.catch((err) => console.error(`Smart plug reset error`, err)); .catch((err) => console.error(`Smart plug reset error`, err));
} }
@ -55,14 +55,26 @@ class Device extends React.Component {
render() { render() {
return ( return (
<Segment> <Segment>
<Grid columns={2}>
<Grid.Column>
{this.renderDeviceComponent()} {this.renderDeviceComponent()}
<h3>{this.props.device.name}</h3> </Grid.Column>
<button onClick={this.edit}>Edit</button> <Grid.Column textAlign='center'>
{this.props.device.type === "smartPlug" ? ( <Header as='h3'>{this.props.device.name}</Header>
<button onClick={this.resetSmartPlug}></button> <Button color='blue' icon onClick={this.edit} labelPosition='left'>
<Icon name='pencil' />
Edit
</Button>
{this.props.device.kind === "smartPlug" ? (
<Button color='orange' icon onClick={this.resetSmartPlug}
labelPosition='left'>
<Icon name='undo' />
Reset
</Button>
) : null} ) : null}
</Grid.Column>
<DeviceSettingsModal ref={this.modalRef} id={this.props.id} /> <DeviceSettingsModal ref={this.modalRef} id={this.props.id} />
</Grid>
</Segment> </Segment>
); );
} }

View file

@ -9,6 +9,8 @@ import {
Input, Input,
Modal, Modal,
} from "semantic-ui-react"; } from "semantic-ui-react";
import { RemoteService } from "../../../remote";
import { connect } from "react-redux";
const StyledDiv = styled.div` const StyledDiv = styled.div`
background-color: #505bda; background-color: #505bda;
@ -29,7 +31,7 @@ const StyledDiv = styled.div`
} }
`; `;
export default class NewDevice extends Component { class NewDevice extends Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.state = { 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;

View file

@ -106,6 +106,8 @@ function reducer(previousState, action) {
change.devices[device.id] = { $set: device }; change.devices[device.id] = { $set: device };
if (device.roomId in newState.rooms) { if (device.roomId in newState.rooms) {
change.rooms[device.roomId] = {};
change.rooms[device.roomId].devices = {};
const devices = change.rooms[device.roomId].devices; const devices = change.rooms[device.roomId].devices;
devices.$add = devices.$add || []; devices.$add = devices.$add || [];
devices.$add.push(device.id); devices.$add.push(device.id);

View file

@ -27,6 +27,11 @@ const actions = {
devices, devices,
partial, partial,
}), }),
deviceOperationUpdate: (devices) => ({
type: "DEVICES_UPDATE",
devices,
partial: true,
}),
roomsUpdate: (rooms) => ({ roomsUpdate: (rooms) => ({
type: "ROOMS_UPDATE", type: "ROOMS_UPDATE",
rooms, rooms,