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

ChatCounter.js 1.5KB

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