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.

LobbyParticipantList.js 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 { withPixelLineHeight } from '../../../base/styles/functions.web';
  7. import { admitMultiple } from '../../../lobby/actions.web';
  8. import { getKnockingParticipants, getLobbyEnabled } from '../../../lobby/functions';
  9. import { LobbyParticipantItem } from './LobbyParticipantItem';
  10. const useStyles = makeStyles(theme => {
  11. return {
  12. headingContainer: {
  13. alignItems: 'center',
  14. display: 'flex',
  15. justifyContent: 'space-between'
  16. },
  17. heading: {
  18. ...withPixelLineHeight(theme.typography.heading7),
  19. color: theme.palette.text02
  20. },
  21. link: {
  22. ...withPixelLineHeight(theme.typography.labelBold),
  23. color: theme.palette.link01,
  24. cursor: 'pointer'
  25. }
  26. };
  27. });
  28. export const LobbyParticipantList = () => {
  29. const lobbyEnabled = useSelector(getLobbyEnabled);
  30. const participants = useSelector(getKnockingParticipants);
  31. const { t } = useTranslation();
  32. const classes = useStyles();
  33. const dispatch = useDispatch();
  34. const admitAll = useCallback(() => {
  35. dispatch(admitMultiple(participants));
  36. }, [ dispatch, participants ]);
  37. if (!lobbyEnabled || !participants.length) {
  38. return null;
  39. }
  40. return (
  41. <>
  42. <div className = { classes.headingContainer }>
  43. <div className = { classes.heading }>
  44. {t('participantsPane.headings.lobby', { count: participants.length })}
  45. </div>
  46. {
  47. participants.length > 1 && (
  48. <div
  49. className = { classes.link }
  50. onClick = { admitAll }>{t('lobby.admitAll')}</div>
  51. )
  52. }
  53. </div>
  54. <div>
  55. {participants.map(p => (
  56. <LobbyParticipantItem
  57. key = { p.id }
  58. participant = { p } />)
  59. )}
  60. </div>
  61. </>
  62. );
  63. };