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.

MeetingParticipantList.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import { FlatList, Text, View } from 'react-native';
  4. import { Button } from 'react-native-paper';
  5. import { translate } from '../../../base/i18n';
  6. import { Icon, IconInviteMore } from '../../../base/icons';
  7. import { getLocalParticipant, getParticipantCountWithFake } from '../../../base/participants';
  8. import { connect } from '../../../base/redux';
  9. import { doInvitePeople } from '../../../invite/actions.native';
  10. import { shouldRenderInviteButton } from '../../functions';
  11. import MeetingParticipantItem from './MeetingParticipantItem';
  12. import styles from './styles';
  13. type Props = {
  14. /**
  15. * The ID of the local participant.
  16. */
  17. _localParticipantId: string,
  18. /**
  19. * The number of participants in the conference.
  20. */
  21. _participantsCount: number,
  22. /**
  23. * Whether or not to show the invite button.
  24. */
  25. _showInviteButton: boolean,
  26. /**
  27. * The remote participants.
  28. */
  29. _sortedRemoteParticipants: Map<string, string>,
  30. /**
  31. * The redux dispatch function.
  32. */
  33. dispatch: Function,
  34. /**
  35. * Translation function.
  36. */
  37. t: Function
  38. }
  39. /**
  40. * The meeting participant list component.
  41. */
  42. class MeetingParticipantList extends PureComponent<Props> {
  43. /**
  44. * Creates new MeetingParticipantList instance.
  45. *
  46. * @param {Props} props - The props of the component.
  47. */
  48. constructor(props: Props) {
  49. super(props);
  50. this._keyExtractor = this._keyExtractor.bind(this);
  51. this._onInvite = this._onInvite.bind(this);
  52. this._renderParticipant = this._renderParticipant.bind(this);
  53. }
  54. _keyExtractor: Function;
  55. /**
  56. * Returns a key for a passed item of the list.
  57. *
  58. * @param {string} item - The user ID.
  59. * @returns {string} - The user ID.
  60. */
  61. _keyExtractor(item) {
  62. return item;
  63. }
  64. _onInvite: () => void;
  65. /**
  66. * Handles ivite button presses.
  67. *
  68. * @returns {void}
  69. */
  70. _onInvite() {
  71. this.props.dispatch(doInvitePeople());
  72. }
  73. /**
  74. * Renders the "invite more" icon.
  75. *
  76. * @returns {ReactElement}
  77. */
  78. _renderInviteMoreIcon() {
  79. return (
  80. <Icon
  81. size = { 20 }
  82. src = { IconInviteMore } />
  83. );
  84. }
  85. _renderParticipant: Object => Object;
  86. /**
  87. * Renders a participant.
  88. *
  89. * @param {Object} flatListItem - Information about the item to be rendered.
  90. * @param {string} flatListItem.item - The ID of the participant.
  91. * @returns {ReactElement}
  92. */
  93. _renderParticipant({ item/* , index, separators */ }) {
  94. return (
  95. <MeetingParticipantItem
  96. key = { item }
  97. participantID = { item } />
  98. );
  99. }
  100. /**
  101. * Implements React's {@link Component#render()}.
  102. *
  103. * @inheritdoc
  104. * @returns {ReactElement}
  105. */
  106. render() {
  107. const {
  108. _localParticipantId,
  109. _participantsCount,
  110. _showInviteButton,
  111. _sortedRemoteParticipants,
  112. t
  113. } = this.props;
  114. return (
  115. <View
  116. style = { styles.meetingListContainer }>
  117. <Text style = { styles.meetingListDescription }>
  118. {t('participantsPane.headings.participantsList',
  119. { count: _participantsCount })}
  120. </Text>
  121. {
  122. _showInviteButton
  123. && <Button
  124. children = { t('participantsPane.actions.invite') }
  125. icon = { this._renderInviteMoreIcon }
  126. labelStyle = { styles.inviteLabel }
  127. mode = 'contained'
  128. onPress = { this._onInvite }
  129. style = { styles.inviteButton } />
  130. }
  131. <FlatList
  132. bounces = { false }
  133. data = { [ _localParticipantId, ..._sortedRemoteParticipants ] }
  134. horizontal = { false }
  135. keyExtractor = { this._keyExtractor }
  136. renderItem = { this._renderParticipant }
  137. scrollEnabled = { false }
  138. showsHorizontalScrollIndicator = { false }
  139. style = { styles.meetingList }
  140. windowSize = { 2 } />
  141. </View>
  142. );
  143. }
  144. }
  145. /**
  146. * Maps (parts of) the redux state to the associated props for this component.
  147. *
  148. * @param {Object} state - The Redux state.
  149. * @private
  150. * @returns {Props}
  151. */
  152. function _mapStateToProps(state): Object {
  153. const _participantsCount = getParticipantCountWithFake(state);
  154. const { remoteParticipants } = state['features/filmstrip'];
  155. const _showInviteButton = shouldRenderInviteButton(state);
  156. return {
  157. _participantsCount,
  158. _showInviteButton,
  159. _sortedRemoteParticipants: remoteParticipants,
  160. _localParticipantId: getLocalParticipant(state)?.id
  161. };
  162. }
  163. export default translate(connect(_mapStateToProps)(MeetingParticipantList));