WIP on room change
This commit is contained in:
parent
69a6cbae6d
commit
7b430045e7
3 changed files with 32 additions and 11 deletions
|
@ -49,9 +49,9 @@ const mapStateToProps = (state, _) => ({
|
||||||
if (state.active.activeRoom === -1) {
|
if (state.active.activeRoom === -1) {
|
||||||
return Object.values(state.devices);
|
return Object.values(state.devices);
|
||||||
} else {
|
} else {
|
||||||
return state.rooms[state.active.activeRoom].devices.map(
|
const deviceArray = [...state.rooms[state.active.activeRoom].devices];
|
||||||
(id) => state.devices[id]
|
console.log(deviceArray);
|
||||||
);
|
return deviceArray.map((id) => state.devices[id]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
get isActiveRoomHome() {
|
get isActiveRoomHome() {
|
||||||
|
|
|
@ -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;
|
let change;
|
||||||
|
@ -87,6 +100,7 @@ function reducer(previousState, action) {
|
||||||
change = {
|
change = {
|
||||||
devices: {},
|
devices: {},
|
||||||
rooms: {},
|
rooms: {},
|
||||||
|
pendingJoins: { rooms: {} },
|
||||||
};
|
};
|
||||||
for (const device of action.devices) {
|
for (const device of action.devices) {
|
||||||
change.devices[device.id] = { $set: device };
|
change.devices[device.id] = { $set: device };
|
||||||
|
@ -96,12 +110,16 @@ function reducer(previousState, action) {
|
||||||
devices.$add = devices.$add || [];
|
devices.$add = devices.$add || [];
|
||||||
devices.$add.push(device.id);
|
devices.$add.push(device.id);
|
||||||
} else {
|
} else {
|
||||||
console.warn(
|
// room does not exist yet, so add to the list of pending
|
||||||
"Cannot join device",
|
// joins
|
||||||
device,
|
|
||||||
`in room ${device.roomId} since that
|
if (!change.pendingJoins.rooms[device.roomId]) {
|
||||||
room has not been fetched`
|
change.pendingJoins.rooms[device.roomId] = {
|
||||||
);
|
$set: new Set([device.id]),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
change.pendingJoins.rooms[device.roomId].$set.add(device.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newState = update(newState, change);
|
newState = update(newState, change);
|
||||||
|
@ -175,6 +193,9 @@ function reducer(previousState, action) {
|
||||||
|
|
||||||
const initState = {
|
const initState = {
|
||||||
errors: {},
|
errors: {},
|
||||||
|
pendingJoins: {
|
||||||
|
rooms: {},
|
||||||
|
},
|
||||||
active: {
|
active: {
|
||||||
activeRoom: -1,
|
activeRoom: -1,
|
||||||
},
|
},
|
||||||
|
|
|
@ -185,8 +185,8 @@ class Navbar extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const setActiveRoom = (dispatch) => {
|
const setActiveRoom = (activeRoom) => {
|
||||||
return (activeRoom) => dispatch(appActions.setActiveRoom(activeRoom));
|
return (dispatch) => dispatch(appActions.setActiveRoom(activeRoom));
|
||||||
};
|
};
|
||||||
|
|
||||||
const mapStateToProps = (state, _) => ({ rooms: state.rooms });
|
const mapStateToProps = (state, _) => ({ rooms: state.rooms });
|
||||||
|
|
Loading…
Reference in a new issue