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.

PresenceLabel.js 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { getParticipantById } from '../../base/participants';
  4. /**
  5. * React {@code Component} for displaying the current presence status of a
  6. * participant.
  7. *
  8. * @extends Component
  9. */
  10. class PresenceLabel extends Component {
  11. /**
  12. * The default values for {@code PresenceLabel} component's property types.
  13. *
  14. * @static
  15. */
  16. static defaultProps = {
  17. _presence: ''
  18. };
  19. /**
  20. * {@code PresenceLabel} component's property types.
  21. *
  22. * @static
  23. */
  24. static propTypes = {
  25. /**
  26. * The current present status associated with the passed in
  27. * participantID prop.
  28. */
  29. _presence: React.PropTypes.string,
  30. /**
  31. * The ID of the participant whose presence status shoul display.
  32. */
  33. participantID: React.PropTypes.string
  34. };
  35. /**
  36. * Implements React's {@link Component#render()}.
  37. *
  38. * @inheritdoc
  39. * @returns {ReactElement}
  40. */
  41. render() {
  42. const { _presence } = this.props;
  43. return (
  44. <div
  45. className
  46. = { `presence-label ${_presence ? '' : 'no-presence'}` }>
  47. { _presence }
  48. </div>
  49. );
  50. }
  51. }
  52. /**
  53. * Maps (parts of) the Redux state to the associated {@code PresenceLabel}'s
  54. * props.
  55. *
  56. * @param {Object} state - The Redux state.
  57. * @param {Object} ownProps - The React Component props passed to the associated
  58. * instance of {@code PresenceLabel}.
  59. * @private
  60. * @returns {{
  61. * _presence: (string|undefined)
  62. * }}
  63. */
  64. function _mapStateToProps(state, ownProps) {
  65. const participant
  66. = getParticipantById(
  67. state['features/base/participants'], ownProps.participantID);
  68. return {
  69. _presence: participant && participant.presence
  70. };
  71. }
  72. export default connect(_mapStateToProps)(PresenceLabel);