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.

ContactListItem.web.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /* global APP */
  2. import PropTypes from 'prop-types';
  3. import React, { Component } from 'react';
  4. import UIEvents from '../../../../service/UI/UIEvents';
  5. import { Avatar } from '../../base/participants';
  6. /**
  7. * Implements a React {@code Component} for showing a participant's avatar and
  8. * name and emits an event when it has been clicked.
  9. *
  10. * @extends Component
  11. */
  12. class ContactListItem extends Component {
  13. /**
  14. * Default values for {@code ContactListItem} component's properties.
  15. *
  16. * @static
  17. */
  18. static propTypes = {
  19. /**
  20. * The link to the participant's avatar image.
  21. */
  22. avatarURI: PropTypes.string,
  23. /**
  24. * An id attribute to set on the root of {@code ContactListItem}. Used
  25. * by the torture tests.
  26. */
  27. id: PropTypes.string,
  28. /**
  29. * The participant's display name.
  30. */
  31. name: PropTypes.string
  32. };
  33. /**
  34. * Initializes new {@code ContactListItem} instance.
  35. *
  36. * @param {Object} props - The read-only properties with which the new
  37. * instance is to be initialized.
  38. */
  39. constructor(props) {
  40. super(props);
  41. // Bind event handler so it is only bound once for every instance.
  42. this._onClick = this._onClick.bind(this);
  43. }
  44. /**
  45. * Implements React's {@link Component#render()}.
  46. *
  47. * @inheritdoc
  48. * @returns {ReactElement}
  49. */
  50. render() {
  51. return (
  52. <li
  53. className = 'clickable contact-list-item'
  54. id = { this.props.id }
  55. onClick = { this._onClick }>
  56. { this.props.avatarURI ? this._renderAvatar() : null }
  57. <p className = 'contact-list-item-name'>
  58. { this.props.name }
  59. </p>
  60. </li>
  61. );
  62. }
  63. /**
  64. * Emits an event notifying the contact list item for the passed in
  65. * participant ID has been clicked.
  66. *
  67. * @private
  68. * @returns {void}
  69. */
  70. _onClick() {
  71. // FIXME move this call to a pinning action, which is what's happening
  72. // on the listener end, when the listener is properly hooked into redux.
  73. APP.UI.emitEvent(UIEvents.CONTACT_CLICKED, this.props.id);
  74. }
  75. /**
  76. * Renders the React Element for displaying the participant's avatar image.
  77. *
  78. * @private
  79. * @returns {ReactElement}
  80. */
  81. _renderAvatar() {
  82. return (
  83. <Avatar
  84. className = 'icon-avatar avatar'
  85. uri = { this.props.avatarURI } />
  86. );
  87. }
  88. }
  89. export default ContactListItem;