Merge branch 'redux-fix' into 'dev'

Fix to socket state reducer and state updated in devices that use circularinput

See merge request sa4-2020/the-sanmarinoes/frontend!84
This commit is contained in:
Claudio Maggioni 2020-04-16 16:01:34 +02:00
commit af209221f0
3 changed files with 29 additions and 5 deletions

View file

@ -44,6 +44,12 @@ class Light extends Component {
this.setIntensity = this.setIntensity.bind(this);
}
componentDidUpdate(prevProps, prevState) {
if (this.props.device.intensity !== prevProps.device.intensity) {
this.setState({ intensity: this.props.device.intensity, timeout: null });
}
}
get turnedOn() {
return this.props.device.on;
}

View file

@ -62,6 +62,20 @@ class Sensor extends Component {
return this.props.device.name;
};
componentDidUpdate(prevProps) {
if (
this.props.device.kind === "sensor" &&
this.props.device.value !== prevProps.device.value
) {
this.setState({ value: this.props.device.value });
} else if (
this.props.device.kind === "motionSensor" &&
this.props.device.detected !== prevProps.device.detected
) {
this.setState({ motion: true, detected: this.props.device.detected });
}
}
componentDidMount() {
if (this.props.device.kind === "sensor") {
switch (this.props.device.sensor) {

View file

@ -89,12 +89,16 @@ function reducer(previousState, action) {
};
for (const device of action.devices) {
const roomId = previousState.devices[device.id].roomId;
change.rooms[roomId] = change.rooms[roomId] || {
devices: { $remove: [] },
};
change.rooms[roomId].devices.$remove.push(device.id);
if (!previousState.devices[device.id]) continue;
change.devices.$unset.push(device.id);
const roomId = previousState.devices[device.id].roomId;
if (roomId in previousState.rooms) {
change.rooms[roomId] = change.rooms[roomId] || {
devices: { $remove: [] },
};
change.rooms[roomId].devices.$remove.push(device.id);
}
}
} else {
// otherwise, just delete all devices and all joins