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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 '../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. return value;
  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, handleClick } = this.props;
  52. if (handleClick) {
  53. handleClick();
  54. return;
  55. }
  56. sendAnalytics(createToolbarEvent(
  57. 'toggle.etherpad',
  58. {
  59. enable: !_editing
  60. }));
  61. dispatch(toggleDocument());
  62. }
  63. /**
  64. * Indicates whether this button is in toggled state or not.
  65. *
  66. * @override
  67. * @protected
  68. * @returns {boolean}
  69. */
  70. _isToggled() {
  71. return this.props._editing;
  72. }
  73. }
  74. /**
  75. * Maps part of the redux state to the component's props.
  76. *
  77. * @param {Object} state - The redux store/state.
  78. * @param {Object} ownProps - The properties explicitly passed to the component
  79. * instance.
  80. * @returns {Object}
  81. */
  82. function _mapStateToProps(state: Object, ownProps: Object) {
  83. const { documentUrl, editing } = state['features/etherpad'];
  84. const { visible = Boolean(documentUrl) } = ownProps;
  85. return {
  86. _editing: editing,
  87. visible
  88. };
  89. }
  90. export default translate(connect(_mapStateToProps)(SharedDocumentButton));