You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

LobbyParticipants.js 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // @flow
  2. import { makeStyles } from '@material-ui/core/styles';
  3. import React, { useCallback } from 'react';
  4. import { useTranslation } from 'react-i18next';
  5. import { useSelector, useDispatch } from 'react-redux';
  6. import { Avatar } from '../../../base/avatar';
  7. import { Icon, IconCheck, IconClose } from '../../../base/icons';
  8. import { withPixelLineHeight } from '../../../base/styles/functions.web';
  9. import { admitMultiple } from '../../../lobby/actions.web';
  10. import { getLobbyEnabled, getKnockingParticipants } from '../../../lobby/functions';
  11. import { Drawer, DrawerPortal } from '../../../toolbox/components/web';
  12. import { showOverflowDrawer } from '../../../toolbox/functions';
  13. import { useLobbyActions, useParticipantDrawer } from '../../hooks';
  14. import LobbyParticipantItems from './LobbyParticipantItems';
  15. const useStyles = makeStyles(theme => {
  16. return {
  17. drawerActions: {
  18. listStyleType: 'none',
  19. margin: 0,
  20. padding: 0
  21. },
  22. drawerItem: {
  23. alignItems: 'center',
  24. color: theme.palette.text01,
  25. display: 'flex',
  26. padding: '12px 16px',
  27. ...withPixelLineHeight(theme.typography.bodyShortRegularLarge),
  28. '&:first-child': {
  29. marginTop: '15px'
  30. },
  31. '&:hover': {
  32. cursor: 'pointer',
  33. background: theme.palette.action02
  34. }
  35. },
  36. icon: {
  37. marginRight: 16
  38. },
  39. headingContainer: {
  40. alignItems: 'center',
  41. display: 'flex',
  42. justifyContent: 'space-between'
  43. },
  44. heading: {
  45. ...withPixelLineHeight(theme.typography.heading7),
  46. color: theme.palette.text02
  47. },
  48. link: {
  49. ...withPixelLineHeight(theme.typography.labelBold),
  50. color: theme.palette.link01,
  51. cursor: 'pointer'
  52. }
  53. };
  54. });
  55. /**
  56. * Component used to display a list of participants waiting in the lobby.
  57. *
  58. * @returns {ReactNode}
  59. */
  60. export default function LobbyParticipants() {
  61. const lobbyEnabled = useSelector(getLobbyEnabled);
  62. const participants = useSelector(getKnockingParticipants);
  63. const { t } = useTranslation();
  64. const classes = useStyles();
  65. const dispatch = useDispatch();
  66. const admitAll = useCallback(() => {
  67. dispatch(admitMultiple(participants));
  68. }, [ dispatch, participants ]);
  69. const overflowDrawer = useSelector(showOverflowDrawer);
  70. const [ drawerParticipant, closeDrawer, openDrawerForParticipant ] = useParticipantDrawer();
  71. const [ admit, reject ] = useLobbyActions(drawerParticipant, closeDrawer);
  72. if (!lobbyEnabled || !participants.length) {
  73. return null;
  74. }
  75. return (
  76. <>
  77. <div className = { classes.headingContainer }>
  78. <div className = { classes.heading }>
  79. {t('participantsPane.headings.lobby', { count: participants.length })}
  80. </div>
  81. <div
  82. className = { classes.link }
  83. onClick = { admitAll }>{t('lobby.admitAll')}</div>
  84. </div>
  85. <LobbyParticipantItems
  86. openDrawerForParticipant = { openDrawerForParticipant }
  87. overflowDrawer = { overflowDrawer }
  88. participants = { participants } />
  89. <DrawerPortal>
  90. <Drawer
  91. isOpen = { Boolean(drawerParticipant && overflowDrawer) }
  92. onClose = { closeDrawer }>
  93. <ul className = { classes.drawerActions }>
  94. <li className = { classes.drawerItem }>
  95. <Avatar
  96. className = { classes.icon }
  97. participantId = { drawerParticipant && drawerParticipant.participantID }
  98. size = { 20 } />
  99. <span>{ drawerParticipant && drawerParticipant.displayName }</span>
  100. </li>
  101. <li
  102. className = { classes.drawerItem }
  103. onClick = { admit }>
  104. <Icon
  105. className = { classes.icon }
  106. size = { 20 }
  107. src = { IconCheck } />
  108. <span>{ t('lobby.admit') }</span>
  109. </li>
  110. <li
  111. className = { classes.drawerItem }
  112. onClick = { reject }>
  113. <Icon
  114. className = { classes.icon }
  115. size = { 20 }
  116. src = { IconClose } />
  117. <span>{ t('lobby.reject')}</span>
  118. </li>
  119. </ul>
  120. </Drawer>
  121. </DrawerPortal>
  122. </>
  123. );
  124. }