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.

ParticipantsCount.js 2.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // @flow
  2. import React, { PureComponent } from 'react';
  3. import type { Dispatch } from 'redux';
  4. import { openDialog } from '../../../base/dialog';
  5. import { IconUserGroups } from '../../../base/icons';
  6. import { Label } from '../../../base/label';
  7. import { COLORS } from '../../../base/label/constants';
  8. import { getParticipantCount } from '../../../base/participants';
  9. import { connect } from '../../../base/redux';
  10. import { SpeakerStats } from '../../../speaker-stats';
  11. /**
  12. * The type of the React {@code Component} props of {@link ParticipantsCount}.
  13. */
  14. type Props = {
  15. /**
  16. * Number of the conference participants.
  17. */
  18. count: number,
  19. /**
  20. * Conference data.
  21. */
  22. conference: Object,
  23. /**
  24. * Invoked to open Speaker stats.
  25. */
  26. dispatch: Dispatch<any>,
  27. };
  28. /**
  29. * ParticipantsCount react component.
  30. * Displays the number of participants and opens Speaker stats on click.
  31. *
  32. * @class ParticipantsCount
  33. */
  34. class ParticipantsCount extends PureComponent<Props> {
  35. /**
  36. * Initializes a new ParticipantsCount instance.
  37. *
  38. * @param {Object} props - The read-only properties with which the new
  39. * instance is to be initialized.
  40. */
  41. constructor(props: Props) {
  42. super(props);
  43. this._onClick = this._onClick.bind(this);
  44. }
  45. _onClick: () => void;
  46. /**
  47. * Callback invoked to display {@code SpeakerStats}.
  48. *
  49. * @private
  50. * @returns {void}
  51. */
  52. _onClick() {
  53. const { dispatch, conference } = this.props;
  54. dispatch(openDialog(SpeakerStats, { conference }));
  55. }
  56. /**
  57. * Implements React's {@link PureComponent#render()}.
  58. *
  59. * @inheritdoc
  60. * @returns {ReactElement}
  61. */
  62. render() {
  63. const { count } = this.props;
  64. if (count <= 2) {
  65. return null;
  66. }
  67. return (
  68. <Label
  69. color = { COLORS.white }
  70. icon = { IconUserGroups }
  71. onClick = { this._onClick }
  72. text = { count } />
  73. );
  74. }
  75. }
  76. /**
  77. * Maps (parts of) the Redux state to the associated props for the
  78. * {@code ParticipantsCount} component.
  79. *
  80. * @param {Object} state - The Redux state.
  81. * @private
  82. * @returns {Props}
  83. */
  84. function mapStateToProps(state) {
  85. return {
  86. conference: state['features/base/conference'].conference,
  87. count: getParticipantCount(state)
  88. };
  89. }
  90. export default connect(mapStateToProps)(ParticipantsCount);