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.

ChatCounter.web.js 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from 'react-redux';
  4. import { getUnreadCount } from '../functions';
  5. /**
  6. * The type of the React {@code Component} props of {@link ChatCounter}.
  7. */
  8. type Props = {
  9. /**
  10. * The value of to display as a count.
  11. */
  12. _count: number
  13. };
  14. /**
  15. * Implements a React {@link Component} which displays a count of the number of
  16. * unread chat messages.
  17. *
  18. * @extends Component
  19. */
  20. class ChatCounter extends Component<Props> {
  21. /**
  22. * Implements React's {@link Component#render()}.
  23. *
  24. * @inheritdoc
  25. * @returns {ReactElement}
  26. */
  27. render() {
  28. return (
  29. <span className = 'badge-round'>
  30. <span>
  31. { this.props._count || null }
  32. </span>
  33. </span>
  34. );
  35. }
  36. }
  37. /**
  38. * Maps (parts of) the Redux state to the associated {@code ChatCounter}'s
  39. * props.
  40. *
  41. * @param {Object} state - The Redux state.
  42. * @private
  43. * @returns {{
  44. * _count: number
  45. * }}
  46. */
  47. function _mapStateToProps(state) {
  48. return {
  49. _count: getUnreadCount(state)
  50. };
  51. }
  52. export default connect(_mapStateToProps)(ChatCounter);