Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ContactListPanel.web.js 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. import Button from '@atlaskit/button';
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import Avatar from '../../../../modules/UI/avatar/Avatar';
  5. import { translate } from '../../base/i18n';
  6. import { getParticipants } from '../../base/participants';
  7. import { openInviteDialog } from '../../invite';
  8. import ContactListItem from './ContactListItem';
  9. const { PropTypes } = React;
  10. declare var interfaceConfig: Object;
  11. /**
  12. * React component for showing a list of current conference participants, the
  13. * current conference lock state, and a button to open the invite dialog.
  14. *
  15. * @extends Component
  16. */
  17. class ContactListPanel extends Component {
  18. /**
  19. * Default values for {@code ContactListPanel} component's properties.
  20. *
  21. * @static
  22. */
  23. static propTypes = {
  24. /**
  25. * Whether or not the conference is currently locked with a password.
  26. */
  27. _locked: PropTypes.bool,
  28. /**
  29. * The participants to show in the contact list.
  30. */
  31. _participants: PropTypes.array,
  32. /**
  33. * Invoked to open an invite dialog.
  34. */
  35. dispatch: PropTypes.func,
  36. /**
  37. * Invoked to obtain translated strings.
  38. */
  39. t: PropTypes.func
  40. };
  41. /**
  42. * Initializes a new {@code ContactListPanel} instance.
  43. *
  44. * @param {Object} props - The read-only properties with which the new
  45. * instance is to be initialized.
  46. */
  47. constructor(props) {
  48. super(props);
  49. // Bind event handler so it is only bound once for every instance.
  50. this._onOpenInviteDialog = this._onOpenInviteDialog.bind(this);
  51. }
  52. /**
  53. * Implements React's {@link Component#render()}.
  54. *
  55. * @inheritdoc
  56. */
  57. render() {
  58. const { _locked, _participants, t } = this.props;
  59. return (
  60. <div className = 'contact-list-panel'>
  61. <div className = 'title'>
  62. { t('contactlist', { pcount: _participants.length }) }
  63. </div>
  64. <div className = 'sideToolbarBlock first'>
  65. <Button
  66. appearance = 'primary'
  67. className = 'contact-list-panel-invite-button'
  68. id = 'addParticipantsBtn'
  69. onClick = { this._onOpenInviteDialog }
  70. type = 'button'>
  71. { t('addParticipants') }
  72. </Button>
  73. <div>
  74. { _locked
  75. ? this._renderLockedMessage()
  76. : this._renderUnlockedMessage() }
  77. </div>
  78. </div>
  79. <ul id = 'contacts'>
  80. { this._renderContacts() }
  81. </ul>
  82. </div>
  83. );
  84. }
  85. /**
  86. * Dispatches an action to open an invite dialog.
  87. *
  88. * @private
  89. * @returns {void}
  90. */
  91. _onOpenInviteDialog() {
  92. this.props.dispatch(openInviteDialog());
  93. }
  94. /**
  95. * Renders React Elements for displaying information about each participant
  96. * in the contact list.
  97. *
  98. * @private
  99. * @returns {ReactElement[]}
  100. */
  101. _renderContacts() {
  102. return this.props._participants.map(({ avatarId, id, name }) =>
  103. ( // eslint-disable-line no-extra-parens
  104. <ContactListItem
  105. avatarURI = { interfaceConfig.SHOW_CONTACTLIST_AVATARS
  106. ? Avatar.getAvatarUrl(avatarId) : null }
  107. id = { id }
  108. key = { id }
  109. name = { name } />
  110. ));
  111. }
  112. /**
  113. * Renders a React Element for informing the conference is currently locked.
  114. *
  115. * @private
  116. * @returns {ReactElement}
  117. */
  118. _renderLockedMessage() {
  119. return (
  120. <p
  121. className = 'form-control__hint form-control_full-width'
  122. id = 'contactListroomLocked'>
  123. <span className = 'icon-security-locked' />
  124. <span>{ this.props.t('roomLocked') }</span>
  125. </p>
  126. );
  127. }
  128. /**
  129. * Renders a React Element for informing the conference is currently not
  130. * locked.
  131. *
  132. * @private
  133. * @returns {ReactElement}
  134. */
  135. _renderUnlockedMessage() {
  136. return (
  137. <p
  138. className = 'form-control__hint form-control_full-width'
  139. id = 'contactListroomUnlocked'>
  140. <span className = 'icon-security' />
  141. <span>{ this.props.t('roomUnlocked') }</span>
  142. </p>
  143. );
  144. }
  145. }
  146. /**
  147. * Maps (parts of) the Redux state to the associated {@code ContactListPanel}'s
  148. * props.
  149. *
  150. * @param {Object} state - The Redux state.
  151. * @private
  152. * @returns {{
  153. * _locked: boolean,
  154. * _participants: Array
  155. * }}
  156. */
  157. function _mapStateToProps(state) {
  158. return {
  159. _locked: state['features/base/conference'].locked,
  160. _participants: getParticipants(state)
  161. };
  162. }
  163. export default translate(connect(_mapStateToProps)(ContactListPanel));