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.

SharedDocumentButton.web.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. // @flow
  2. import type { Dispatch } from 'redux';
  3. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  4. import { translate } from '../../base/i18n';
  5. import { IconShareDoc } from '../../base/icons';
  6. import { connect } from '../../base/redux';
  7. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
  8. import { toggleDocument } from '../../etherpad/actions';
  9. import { setOverflowMenuVisible } from '../../toolbox/actions.web';
  10. type Props = AbstractButtonProps & {
  11. /**
  12. * Whether the shared document is being edited or not.
  13. */
  14. _editing: boolean,
  15. /**
  16. * Redux dispatch function.
  17. */
  18. dispatch: Dispatch<any>,
  19. };
  20. /**
  21. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  22. */
  23. class SharedDocumentButton extends AbstractButton<Props, *> {
  24. accessibilityLabel = 'toolbar.accessibilityLabel.documentOpen';
  25. toggledAccessibilityLabel = 'toolbar.accessibilityLabel.documentClose';
  26. icon = IconShareDoc;
  27. label = 'toolbar.documentOpen';
  28. toggledLabel = 'toolbar.documentClose';
  29. tooltip = 'toolbar.documentOpen';
  30. toggledTooltip = 'toolbar.documentClose';
  31. /**
  32. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  33. *
  34. * @private
  35. * @returns {void}
  36. */
  37. _handleClick() {
  38. const { _editing, dispatch } = this.props;
  39. sendAnalytics(createToolbarEvent(
  40. 'toggle.etherpad',
  41. {
  42. enable: !_editing
  43. }));
  44. dispatch(toggleDocument());
  45. dispatch(setOverflowMenuVisible(false));
  46. }
  47. /**
  48. * Indicates whether this button is in toggled state or not.
  49. *
  50. * @override
  51. * @protected
  52. * @returns {boolean}
  53. */
  54. _isToggled() {
  55. return this.props._editing;
  56. }
  57. }
  58. /**
  59. * Maps part of the redux state to the component's props.
  60. *
  61. * @param {Object} state - The redux store/state.
  62. * @param {Object} ownProps - The properties explicitly passed to the component
  63. * instance.
  64. * @returns {Object}
  65. */
  66. function _mapStateToProps(state: Object, ownProps: Object) {
  67. const { documentUrl, editing } = state['features/etherpad'];
  68. const { visible = Boolean(documentUrl) } = ownProps;
  69. return {
  70. _editing: editing,
  71. visible
  72. };
  73. }
  74. export default translate(connect(_mapStateToProps)(SharedDocumentButton));