WIP on room change

This commit is contained in:
Claudio Maggioni 2020-04-10 17:52:02 +02:00
parent 69a6cbae6d
commit 7b430045e7
3 changed files with 32 additions and 11 deletions

View file

@ -49,9 +49,9 @@ const mapStateToProps = (state, _) => ({
if (state.active.activeRoom === -1) {
return Object.values(state.devices);
} else {
return state.rooms[state.active.activeRoom].devices.map(
(id) => state.devices[id]
);
const deviceArray = [...state.rooms[state.active.activeRoom].devices];
console.log(deviceArray);
return deviceArray.map((id) => state.devices[id]);
}
},
get isActiveRoomHome() {

View file

@ -21,6 +21,19 @@ function reducer(previousState, action) {
},
});
}
if (newState.pendingJoins.rooms[room.id]) {
newState = update(newState, {
pendingJoins: { rooms: { $unset: [room.id] } },
rooms: {
[room.id]: {
devices: {
$add: [...newState.pendingJoins.rooms[room.id]],
},
},
},
});
}
};
let change;
@ -87,6 +100,7 @@ function reducer(previousState, action) {
change = {
devices: {},
rooms: {},
pendingJoins: { rooms: {} },
};
for (const device of action.devices) {
change.devices[device.id] = { $set: device };
@ -96,12 +110,16 @@ function reducer(previousState, action) {
devices.$add = devices.$add || [];
devices.$add.push(device.id);
} else {
console.warn(
"Cannot join device",
device,
`in room ${device.roomId} since that
room has not been fetched`
);
// room does not exist yet, so add to the list of pending
// joins
if (!change.pendingJoins.rooms[device.roomId]) {
change.pendingJoins.rooms[device.roomId] = {
$set: new Set([device.id]),
};
} else {
change.pendingJoins.rooms[device.roomId].$set.add(device.id);
}
}
}
newState = update(newState, change);
@ -175,6 +193,9 @@ function reducer(previousState, action) {
const initState = {
errors: {},
pendingJoins: {
rooms: {},
},
active: {
activeRoom: -1,
},

View file

@ -185,8 +185,8 @@ class Navbar extends Component {
}
}
const setActiveRoom = (dispatch) => {
return (activeRoom) => dispatch(appActions.setActiveRoom(activeRoom));
const setActiveRoom = (activeRoom) => {
return (dispatch) => dispatch(appActions.setActiveRoom(activeRoom));
};
const mapStateToProps = (state, _) => ({ rooms: state.rooms });