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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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.document';
  25. icon = IconShareDoc;
  26. label = 'toolbar.documentOpen';
  27. toggledLabel = 'toolbar.documentClose';
  28. /**
  29. * Dynamically retrieves tooltip based on sharing state.
  30. */
  31. get tooltip() {
  32. if (this._isToggled()) {
  33. return 'toolbar.documentClose';
  34. }
  35. return 'toolbar.documentOpen';
  36. }
  37. /**
  38. * Required by linter due to AbstractButton overwritten prop being writable.
  39. *
  40. * @param {string} _value - The value.
  41. */
  42. set tooltip(_value) {
  43. // Unused.
  44. }
  45. /**
  46. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  47. *
  48. * @private
  49. * @returns {void}
  50. */
  51. _handleClick() {
  52. const { _editing, dispatch } = this.props;
  53. sendAnalytics(createToolbarEvent(
  54. 'toggle.etherpad',
  55. {
  56. enable: !_editing
  57. }));
  58. dispatch(toggleDocument());
  59. dispatch(setOverflowMenuVisible(false));
  60. }
  61. /**
  62. * Indicates whether this button is in toggled state or not.
  63. *
  64. * @override
  65. * @protected
  66. * @returns {boolean}
  67. */
  68. _isToggled() {
  69. return this.props._editing;
  70. }
  71. }
  72. /**
  73. * Maps part of the redux state to the component's props.
  74. *
  75. * @param {Object} state - The redux store/state.
  76. * @param {Object} ownProps - The properties explicitly passed to the component
  77. * instance.
  78. * @returns {Object}
  79. */
  80. function _mapStateToProps(state: Object, ownProps: Object) {
  81. const { documentUrl, editing } = state['features/etherpad'];
  82. const { visible = Boolean(documentUrl) } = ownProps;
  83. return {
  84. _editing: editing,
  85. visible
  86. };
  87. }
  88. export default translate(connect(_mapStateToProps)(SharedDocumentButton));