Merge branch '82-scene-states-update' of https://lab.si.usi.ch/sa4-2020/the-sanmarinoes/frontend into 82-scene-states-update
This commit is contained in:
commit
34f83c9cce
4 changed files with 41 additions and 3 deletions
|
@ -19,6 +19,7 @@ class Device extends React.Component {
|
|||
this.modalRef = React.createRef();
|
||||
this.edit = this.edit.bind(this);
|
||||
this.resetSmartPlug = this.resetSmartPlug.bind(this);
|
||||
this.deleteState=this.deleteState.bind(this);
|
||||
}
|
||||
|
||||
edit() {
|
||||
|
@ -33,11 +34,11 @@ class Device extends React.Component {
|
|||
}
|
||||
|
||||
deleteState() {
|
||||
//console.log("alpaca "+this.props);
|
||||
this.props.deleteState(this.props.id, this.props.type);
|
||||
}
|
||||
|
||||
renderDeviceComponent() {
|
||||
console.log(JSON.stringify(this.props.stateOrDevice));
|
||||
switch (
|
||||
this.props.tab === "Devices"
|
||||
? this.props.stateOrDevice.kind
|
||||
|
|
|
@ -378,7 +378,7 @@ export const RemoteService = {
|
|||
updateState: (data, type) => {
|
||||
return (dispatch) => {
|
||||
let url;
|
||||
if (type == "dimmableState") {
|
||||
if (type === "dimmableState") {
|
||||
url = "/dimmableState";
|
||||
} else {
|
||||
url = "/switchableState";
|
||||
|
@ -397,7 +397,20 @@ export const RemoteService = {
|
|||
},
|
||||
|
||||
deleteState: (id, type)=>{
|
||||
|
||||
return (dispatch)=>{
|
||||
let url;
|
||||
if (type === "dimmableState") {
|
||||
url = "/dimmableState";
|
||||
} else {
|
||||
url = "/switchableState";
|
||||
}
|
||||
return Endpoint.delete(url+`/${id}`)
|
||||
.then((_) => dispatch(actions.stateDelete(id)))
|
||||
.catch((err) => {
|
||||
console.warn("state delete error", err);
|
||||
throw new RemoteError(["Network error"]);
|
||||
});
|
||||
};
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -356,6 +356,26 @@ function reducer(previousState, action) {
|
|||
change.active = { activeScene: { $set: -1 } };
|
||||
}
|
||||
|
||||
newState = update(previousState, change);
|
||||
break;
|
||||
case "STATE_DELETE":
|
||||
if (!(action.stateId in previousState.sceneStates)) {
|
||||
console.warn(`State to delete ${action.stateId} does not exist`);
|
||||
break;
|
||||
}
|
||||
|
||||
change = {
|
||||
sceneStates: { $unset: [action.stateId] },
|
||||
};
|
||||
|
||||
if (previousState.scenes[previousState.sceneStates[action.stateId].sceneId]) {
|
||||
change.scenes = {
|
||||
[previousState.sceneStates[action.stateId].sceneId]: {
|
||||
sceneStates: { $remove: [action.stateId] },
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
newState = update(previousState, change);
|
||||
break;
|
||||
case "DEVICE_DELETE":
|
||||
|
|
|
@ -40,6 +40,10 @@ const actions = {
|
|||
devices,
|
||||
partial,
|
||||
}),
|
||||
stateDelete: (stateId)=>({
|
||||
type: "STATE_DELETE",
|
||||
stateId,
|
||||
}),
|
||||
deviceOperationUpdate: (devices) => ({
|
||||
type: "DEVICES_UPDATE",
|
||||
devices,
|
||||
|
|
Loading…
Reference in a new issue