idk how but delete works
This commit is contained in:
parent
b6a27195fe
commit
79afe780b3
4 changed files with 41 additions and 3 deletions
|
@ -19,6 +19,7 @@ class Device extends React.Component {
|
||||||
this.modalRef = React.createRef();
|
this.modalRef = React.createRef();
|
||||||
this.edit = this.edit.bind(this);
|
this.edit = this.edit.bind(this);
|
||||||
this.resetSmartPlug = this.resetSmartPlug.bind(this);
|
this.resetSmartPlug = this.resetSmartPlug.bind(this);
|
||||||
|
this.deleteState=this.deleteState.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
edit() {
|
edit() {
|
||||||
|
@ -33,11 +34,11 @@ class Device extends React.Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteState() {
|
deleteState() {
|
||||||
|
//console.log("alpaca "+this.props);
|
||||||
this.props.deleteState(this.props.id, this.props.type);
|
this.props.deleteState(this.props.id, this.props.type);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderDeviceComponent() {
|
renderDeviceComponent() {
|
||||||
console.log(JSON.stringify(this.props.stateOrDevice));
|
|
||||||
switch (
|
switch (
|
||||||
this.props.tab === "Devices"
|
this.props.tab === "Devices"
|
||||||
? this.props.stateOrDevice.kind
|
? this.props.stateOrDevice.kind
|
||||||
|
|
|
@ -378,7 +378,7 @@ export const RemoteService = {
|
||||||
updateState: (data, type) => {
|
updateState: (data, type) => {
|
||||||
return (dispatch) => {
|
return (dispatch) => {
|
||||||
let url;
|
let url;
|
||||||
if (type == "dimmableState") {
|
if (type === "dimmableState") {
|
||||||
url = "/dimmableState";
|
url = "/dimmableState";
|
||||||
} else {
|
} else {
|
||||||
url = "/switchableState";
|
url = "/switchableState";
|
||||||
|
@ -397,7 +397,20 @@ export const RemoteService = {
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteState: (id, type)=>{
|
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 } };
|
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);
|
newState = update(previousState, change);
|
||||||
break;
|
break;
|
||||||
case "DEVICE_DELETE":
|
case "DEVICE_DELETE":
|
||||||
|
|
|
@ -40,6 +40,10 @@ const actions = {
|
||||||
devices,
|
devices,
|
||||||
partial,
|
partial,
|
||||||
}),
|
}),
|
||||||
|
stateDelete: (stateId)=>({
|
||||||
|
type: "STATE_DELETE",
|
||||||
|
stateId,
|
||||||
|
}),
|
||||||
deviceOperationUpdate: (devices) => ({
|
deviceOperationUpdate: (devices) => ({
|
||||||
type: "DEVICES_UPDATE",
|
type: "DEVICES_UPDATE",
|
||||||
devices,
|
devices,
|
||||||
|
|
Loading…
Reference in a new issue