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.js 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // @flow
  2. import { CHAT_ENABLED, getFeatureFlag } from '../../../base/flags';
  3. import { IconChat, IconChatUnread } from '../../../base/icons';
  4. import { connect } from '../../../base/redux';
  5. import {
  6. AbstractButton,
  7. type AbstractButtonProps
  8. } from '../../../base/toolbox/components';
  9. import { openChat } from '../../actions.native';
  10. import { getUnreadCount } from '../../functions';
  11. type Props = AbstractButtonProps & {
  12. /**
  13. * The unread message count.
  14. */
  15. _unreadMessageCount: number,
  16. dispatch: Function
  17. };
  18. /**
  19. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  20. */
  21. class ChatButton extends AbstractButton<Props, *> {
  22. accessibilityLabel = 'toolbar.accessibilityLabel.chat';
  23. icon = IconChat;
  24. label = 'toolbar.chat';
  25. toggledIcon = IconChatUnread;
  26. /**
  27. * Handles clicking / pressing the button, and opens the appropriate dialog.
  28. *
  29. * @private
  30. * @returns {void}
  31. */
  32. _handleClick() {
  33. this.props.dispatch(openChat());
  34. }
  35. /**
  36. * Renders the button toggled when there are unread messages.
  37. *
  38. * @protected
  39. * @returns {boolean}
  40. */
  41. _isToggled() {
  42. return Boolean(this.props._unreadMessageCount);
  43. }
  44. }
  45. /**
  46. * Maps part of the redux state to the component's props.
  47. *
  48. * @param {Object} state - The Redux state.
  49. * @param {Object} ownProps - The properties explicitly passed to the component instance.
  50. * @returns {Props}
  51. */
  52. function _mapStateToProps(state, ownProps) {
  53. const enabled = getFeatureFlag(state, CHAT_ENABLED, true);
  54. const { visible = enabled } = ownProps;
  55. return {
  56. _unreadMessageCount: getUnreadCount(state),
  57. visible
  58. };
  59. }
  60. export default connect(_mapStateToProps)(ChatButton);