您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

ChatCounter.js 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // @flow
  2. import React, { Component } from 'react';
  3. import { connect } from '../../../base/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. * True if the chat window should be rendered.
  15. */
  16. _isOpen: boolean
  17. };
  18. /**
  19. * Implements a React {@link Component} which displays a count of the number of
  20. * unread chat messages.
  21. *
  22. * @extends Component
  23. */
  24. class ChatCounter extends Component<Props> {
  25. /**
  26. * Implements React's {@link Component#render()}.
  27. *
  28. * @inheritdoc
  29. * @returns {ReactElement}
  30. */
  31. render() {
  32. return (
  33. <span className = 'badge-round'>
  34. <span>
  35. {
  36. !this.props._isOpen
  37. && (this.props._count || null)
  38. }
  39. </span>
  40. </span>
  41. );
  42. }
  43. }
  44. /**
  45. * Maps (parts of) the Redux state to the associated {@code ChatCounter}'s
  46. * props.
  47. *
  48. * @param {Object} state - The Redux state.
  49. * @private
  50. * @returns {{
  51. * _count: number
  52. * }}
  53. */
  54. function _mapStateToProps(state) {
  55. const { isOpen } = state['features/chat'];
  56. return {
  57. _count: getUnreadCount(state),
  58. _isOpen: isOpen
  59. };
  60. }
  61. export default connect(_mapStateToProps)(ChatCounter);