Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

PresenceLabel.js 1.9KB

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