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

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