A button to promote all peers from lobby, fixes #287

This commit is contained in:
Håvar Aambø Fosstveit
2020-05-04 15:09:05 +02:00
parent a00d33ee4b
commit a1ed79c5db
23 changed files with 117 additions and 39 deletions
@@ -27,6 +27,7 @@ const ListLobbyPeer = (props) =>
const {
roomClient,
peer,
promotionInProgress,
canPromote,
classes
} = props;
@@ -55,7 +56,11 @@ const ListLobbyPeer = (props) =>
})}
>
<IconButton
disabled={!canPromote || peer.promotionInProgress}
disabled={
!canPromote ||
peer.promotionInProgress ||
promotionInProgress
}
onClick={(e) =>
{
e.stopPropagation();
@@ -71,18 +76,20 @@ const ListLobbyPeer = (props) =>
ListLobbyPeer.propTypes =
{
roomClient : PropTypes.any.isRequired,
advancedMode : PropTypes.bool,
peer : PropTypes.object.isRequired,
canPromote : PropTypes.bool.isRequired,
classes : PropTypes.object.isRequired
roomClient : PropTypes.any.isRequired,
advancedMode : PropTypes.bool,
peer : PropTypes.object.isRequired,
promotionInProgress : PropTypes.bool.isRequired,
canPromote : PropTypes.bool.isRequired,
classes : PropTypes.object.isRequired
};
const mapStateToProps = (state, { id }) =>
{
return {
peer : state.lobbyPeers[id],
canPromote :
peer : state.lobbyPeers[id],
promotionInProgress : state.room.lobbyPeersPromotionInProgress,
canPromote :
state.me.roles.some((role) =>
state.room.permissionsFromRoles.PROMOTE_PEER.includes(role))
};
@@ -97,6 +104,8 @@ export default withRoomContext(connect(
{
return (
prev.room.permissionsFromRoles === next.room.permissionsFromRoles &&
prev.room.lobbyPeersPromotionInProgress ===
next.room.lobbyPeersPromotionInProgress &&
prev.me.roles === next.me.roles &&
prev.lobbyPeers === next.lobbyPeers
);
@@ -51,9 +51,11 @@ const styles = (theme) =>
});
const LockDialog = ({
roomClient,
room,
handleCloseLockDialog,
lobbyPeers,
canPromote,
classes
}) =>
{
@@ -102,6 +104,20 @@ const LockDialog = ({
</DialogContent>
}
<DialogActions>
<Button
disabled={
lobbyPeers.length === 0 ||
!canPromote ||
room.lobbyPeersPromotionInProgress
}
onClick={() => roomClient.promoteAllLobbyPeers()}
color='primary'
>
<FormattedMessage
id='label.promoteAllPeers'
defaultMessage='Promote all'
/>
</Button>
<Button onClick={() => handleCloseLockDialog(false)} color='primary'>
<FormattedMessage
id='label.close'
@@ -115,10 +131,12 @@ const LockDialog = ({
LockDialog.propTypes =
{
roomClient : PropTypes.object.isRequired,
room : appPropTypes.Room.isRequired,
handleCloseLockDialog : PropTypes.func.isRequired,
handleAccessCode : PropTypes.func.isRequired,
lobbyPeers : PropTypes.array,
canPromote : PropTypes.bool,
classes : PropTypes.object.isRequired
};
@@ -126,7 +144,10 @@ const mapStateToProps = (state) =>
{
return {
room : state.room,
lobbyPeers : lobbyPeersKeySelector(state)
lobbyPeers : lobbyPeersKeySelector(state),
canPromote :
state.me.roles.some((role) =>
state.room.permissionsFromRoles.PROMOTE_PEER.includes(role))
};
};
@@ -144,6 +165,7 @@ export default withRoomContext(connect(
{
return (
prev.room === next.room &&
prev.me.roles === next.me.roles &&
prev.lobbyPeers === next.lobbyPeers
);
}