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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // @flow
  2. import React, { useCallback } from 'react';
  3. import { useTranslation } from 'react-i18next';
  4. import { Text, View } from 'react-native';
  5. import { Button, withTheme } from 'react-native-paper';
  6. import { useDispatch, useSelector } from 'react-redux';
  7. import { admitMultiple } from '../../../lobby/actions.native';
  8. import { getKnockingParticipants, getLobbyEnabled } from '../../../lobby/functions';
  9. import { LobbyParticipantItem } from './LobbyParticipantItem';
  10. import styles from './styles';
  11. type Props = {
  12. /**
  13. * Theme used for styles.
  14. */
  15. theme: Object
  16. };
  17. const LobbyParticipantList = ({ theme }: Props) => {
  18. const lobbyEnabled = useSelector(getLobbyEnabled);
  19. const participants = useSelector(getKnockingParticipants);
  20. const dispatch = useDispatch();
  21. const admitAll = useCallback(() =>
  22. dispatch(admitMultiple(participants)),
  23. [ dispatch, participants ]);
  24. const { t } = useTranslation();
  25. const { palette } = theme;
  26. if (!lobbyEnabled || !participants.length) {
  27. return null;
  28. }
  29. return (
  30. <View
  31. style = { styles.lobbyListContainer } >
  32. <View style = { styles.lobbyListDetails } >
  33. <Text style = { styles.lobbyListDescription }>
  34. {t('participantsPane.headings.waitingLobby',
  35. { count: participants.length })}
  36. </Text>
  37. {
  38. participants.length > 1 && (
  39. <Button
  40. color = { palette.action02 }
  41. labelStyle = { styles.admitAllParticipantsActionButtonLabel }
  42. mode = 'text'
  43. onPress = { admitAll }>
  44. {t('lobby.admitAll')}
  45. </Button>
  46. )
  47. }
  48. </View>
  49. {
  50. participants.map(p => (
  51. <LobbyParticipantItem
  52. key = { p.id }
  53. participant = { p } />)
  54. )
  55. }
  56. </View>
  57. );
  58. };
  59. export default withTheme(LobbyParticipantList);