Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ChatCounter.tsx 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  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. interface IProps {
  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. * @augments Component
  24. */
  25. class ChatCounter extends Component<IProps> {
  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: IReduxState) {
  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);