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.

ChatButton.tsx 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import React from 'react';
  2. import { connect } from 'react-redux';
  3. import { createToolbarEvent } from '../../../analytics/AnalyticsEvents';
  4. import { sendAnalytics } from '../../../analytics/functions';
  5. import { IReduxState } from '../../../app/types';
  6. import { translate } from '../../../base/i18n/functions';
  7. import { IconMessage } from '../../../base/icons/svg';
  8. import AbstractButton, { IProps as AbstractButtonProps } from '../../../base/toolbox/components/AbstractButton';
  9. import { closeOverflowMenuIfOpen } from '../../../toolbox/actions.web';
  10. import { toggleChat } from '../../actions.web';
  11. import ChatCounter from './ChatCounter';
  12. /**
  13. * The type of the React {@code Component} props of {@link ChatButton}.
  14. */
  15. interface IProps extends AbstractButtonProps {
  16. /**
  17. * Whether or not the chat feature is currently displayed.
  18. */
  19. _chatOpen: boolean;
  20. }
  21. /**
  22. * Implementation of a button for accessing chat pane.
  23. */
  24. class ChatButton extends AbstractButton<IProps> {
  25. accessibilityLabel = 'toolbar.accessibilityLabel.openChat';
  26. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.closeChat';
  27. icon = IconMessage;
  28. label = 'toolbar.openChat';
  29. toggledLabel = 'toolbar.closeChat';
  30. tooltip = 'toolbar.openChat';
  31. toggledTooltip = 'toolbar.closeChat';
  32. /**
  33. * Indicates whether this button is in toggled state or not.
  34. *
  35. * @override
  36. * @protected
  37. * @returns {boolean}
  38. */
  39. _isToggled() {
  40. return this.props._chatOpen;
  41. }
  42. /**
  43. * Overrides AbstractButton's {@link Component#render()}.
  44. *
  45. * @override
  46. * @protected
  47. * @returns {boReact$Nodeolean}
  48. */
  49. render() {
  50. return (
  51. <div
  52. className = 'toolbar-button-with-badge'
  53. key = 'chatcontainer'>
  54. {super.render()}
  55. <ChatCounter />
  56. </div>
  57. );
  58. }
  59. /**
  60. * Handles clicking the button, and toggles the chat.
  61. *
  62. * @private
  63. * @returns {void}
  64. */
  65. _handleClick() {
  66. const { dispatch } = this.props;
  67. sendAnalytics(createToolbarEvent(
  68. 'toggle.chat',
  69. {
  70. enable: !this.props._chatOpen
  71. }));
  72. dispatch(closeOverflowMenuIfOpen());
  73. dispatch(toggleChat());
  74. }
  75. }
  76. /**
  77. * Function that maps parts of Redux state tree into component props.
  78. *
  79. * @param {Object} state - Redux state.
  80. * @returns {Object}
  81. */
  82. const mapStateToProps = (state: IReduxState) => {
  83. return {
  84. _chatOpen: state['features/chat'].isOpen
  85. };
  86. };
  87. export default translate(connect(mapStateToProps)(ChatButton));