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); 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() { get turnedOn() {
return this.props.device.on; return this.props.device.on;
} }

View file

@ -62,6 +62,20 @@ class Sensor extends Component {
return this.props.device.name; 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() { componentDidMount() {
if (this.props.device.kind === "sensor") { if (this.props.device.kind === "sensor") {
switch (this.props.device.sensor) { switch (this.props.device.sensor) {

View file

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