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

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