fixed update state
This commit is contained in:
parent
c878702331
commit
af0c157205
5 changed files with 23 additions and 29 deletions
|
@ -54,8 +54,8 @@ const mapStateToProps = (state, _) => ({
|
||||||
const stateArray = [
|
const stateArray = [
|
||||||
...state.scenes[state.active.activeScene].sceneStates,
|
...state.scenes[state.active.activeScene].sceneStates,
|
||||||
].sort();
|
].sort();
|
||||||
console.log(stateArray);
|
console.log("STATESCENE", stateArray);
|
||||||
return stateArray;
|
return stateArray.map((id) => state.sceneStates[id]);
|
||||||
} else {
|
} else {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
|
@ -211,11 +211,11 @@ const mapStateToProps = (state, ownProps) => ({
|
||||||
if (state.active.activeTab === "Devices") {
|
if (state.active.activeTab === "Devices") {
|
||||||
return state.devices[ownProps.id];
|
return state.devices[ownProps.id];
|
||||||
} else {
|
} else {
|
||||||
console.log(
|
/*console.log(
|
||||||
state.sceneStates,
|
state.sceneStates,
|
||||||
ownProps.id,
|
ownProps.id,
|
||||||
state.sceneStates[ownProps.id]
|
state.sceneStates[ownProps.id]
|
||||||
);
|
);*/
|
||||||
return state.sceneStates[ownProps.id];
|
return state.sceneStates[ownProps.id];
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -234,9 +234,9 @@ const mapStateToProps = (state, ownProps) => ({
|
||||||
console.log("ALPACA", state, ownProps);
|
console.log("ALPACA", state, ownProps);
|
||||||
if (state.active.activeTab === "Scenes") {
|
if (state.active.activeTab === "Scenes") {
|
||||||
if (state.sceneStates[ownProps.id]) {
|
if (state.sceneStates[ownProps.id]) {
|
||||||
console.log(state.sceneStates[ownProps.id], ownProps.id);
|
//console.log(state.sceneStates[ownProps.id], ownProps.id);
|
||||||
const id = state.sceneStates[ownProps.id].deviceId;
|
const id = state.sceneStates[ownProps.id].deviceId;
|
||||||
console.log(id, state.devices[id].kind);
|
//console.log(id, state.devices[id].kind);
|
||||||
return state.devices[id].kind;
|
return state.devices[id].kind;
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return "";
|
||||||
|
|
|
@ -75,11 +75,11 @@ class Light extends Component {
|
||||||
this.props
|
this.props
|
||||||
.updateState(
|
.updateState(
|
||||||
{
|
{
|
||||||
id: this.props.sceneState.id,
|
id: this.props.stateOrDevice.id,
|
||||||
on: on,
|
on: on,
|
||||||
sceneId: this.props.sceneState.sceneId,
|
sceneId: this.props.stateOrDevice.sceneId,
|
||||||
},
|
},
|
||||||
this.props.sceneState.kind
|
this.props.stateOrDevice.kind
|
||||||
)
|
)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
|
|
|
@ -107,7 +107,6 @@ function reducer(previousState, action) {
|
||||||
break;
|
break;
|
||||||
case "STATES_UPDATE":
|
case "STATES_UPDATE":
|
||||||
//console.log(action.sceneStates);
|
//console.log(action.sceneStates);
|
||||||
newState = previousState;
|
|
||||||
change = null;
|
change = null;
|
||||||
|
|
||||||
// if room is given, delete all devices in that room
|
// if room is given, delete all devices in that room
|
||||||
|
@ -118,7 +117,7 @@ function reducer(previousState, action) {
|
||||||
sceneStates: { $unset: [] },
|
sceneStates: { $unset: [] },
|
||||||
};
|
};
|
||||||
|
|
||||||
const scene = newState.scenes[action.sceneId];
|
const scene = previousState.scenes[action.sceneId];
|
||||||
for (const stateId of scene.sceneStates) {
|
for (const stateId of scene.sceneStates) {
|
||||||
change.sceneStates.$unset.push(stateId);
|
change.sceneStates.$unset.push(stateId);
|
||||||
}
|
}
|
||||||
|
@ -147,17 +146,19 @@ function reducer(previousState, action) {
|
||||||
change.scenes[sceneState.sceneId].sceneStates || {};
|
change.scenes[sceneState.sceneId].sceneStates || {};
|
||||||
const sceneStates = change.scenes[sceneState.sceneId].sceneStates;
|
const sceneStates = change.scenes[sceneState.sceneId].sceneStates;
|
||||||
sceneStates.$add = sceneStates.$add || [];
|
sceneStates.$add = sceneStates.$add || [];
|
||||||
sceneStates.$add.push(sceneState);
|
sceneStates.$add.push(sceneState.id);
|
||||||
} else {
|
} else {
|
||||||
// room does not exist yet, so add to the list of pending
|
// room does not exist yet, so add to the list of pending
|
||||||
// joins
|
// joins
|
||||||
|
|
||||||
if (!change.pendingJoins.scenes[sceneState.sceneId]) {
|
if (!change.pendingJoins.scenes[sceneState.sceneId]) {
|
||||||
change.pendingJoins.scenes[sceneState.sceneId] = {
|
change.pendingJoins.scenes[sceneState.sceneId] = {
|
||||||
$set: new Set([sceneState]),
|
$set: new Set([sceneState.id]),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
change.pendingJoins.scenes[sceneState.sceneId].$set.add(sceneState);
|
change.pendingJoins.scenes[sceneState.sceneId].$set.add(
|
||||||
|
sceneState.id
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -292,16 +293,12 @@ function reducer(previousState, action) {
|
||||||
sceneStates: { [action.sceneState.id]: { $set: action.sceneState } },
|
sceneStates: { [action.sceneState.id]: { $set: action.sceneState } },
|
||||||
};
|
};
|
||||||
|
|
||||||
if (
|
if (previousState.scenes[action.sceneState.sceneId]) {
|
||||||
!previousState.scenes[action.sceneState.sceneId].sceneStates[
|
console.log("PREVSTATE", change, previousState);
|
||||||
action.sceneState.id
|
|
||||||
]
|
|
||||||
) {
|
|
||||||
console.log("Ciao");
|
|
||||||
change.scenes = {
|
change.scenes = {
|
||||||
[action.sceneState.sceneId]: {
|
[action.sceneState.sceneId]: {
|
||||||
sceneStates: {
|
sceneStates: {
|
||||||
$add: [action.sceneState],
|
$add: [action.sceneState.id],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -309,12 +306,13 @@ function reducer(previousState, action) {
|
||||||
change.pendingJoins = {
|
change.pendingJoins = {
|
||||||
scenes: {
|
scenes: {
|
||||||
[action.sceneState.sceneId]: {
|
[action.sceneState.sceneId]: {
|
||||||
$add: [action.sceneState],
|
$add: [action.sceneState.id],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
newState = update(previousState, change);
|
newState = update(previousState, change);
|
||||||
|
console.log("NEWSTATE ", newState);
|
||||||
break;
|
break;
|
||||||
case "ROOM_DELETE":
|
case "ROOM_DELETE":
|
||||||
if (!(action.roomId in previousState.rooms)) {
|
if (!(action.roomId in previousState.rooms)) {
|
||||||
|
@ -467,7 +465,7 @@ function reducer(previousState, action) {
|
||||||
console.warn(`Action type ${action.type} unknown`, action);
|
console.warn(`Action type ${action.type} unknown`, action);
|
||||||
return previousState;
|
return previousState;
|
||||||
}
|
}
|
||||||
|
console.log("THETRUEALPACA", newState, action.type, action);
|
||||||
return newState;
|
return newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,10 +34,6 @@ const actions = {
|
||||||
sceneId,
|
sceneId,
|
||||||
sceneStates,
|
sceneStates,
|
||||||
}),
|
}),
|
||||||
stateUpdate: (state) => ({
|
|
||||||
type: "STATE_UPDATE",
|
|
||||||
state,
|
|
||||||
}),
|
|
||||||
devicesUpdate: (roomId, devices, partial = false) => ({
|
devicesUpdate: (roomId, devices, partial = false) => ({
|
||||||
type: "DEVICES_UPDATE",
|
type: "DEVICES_UPDATE",
|
||||||
roomId,
|
roomId,
|
||||||
|
|
Loading…
Reference in a new issue