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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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';
  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. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  29. *
  30. * @private
  31. * @returns {void}
  32. */
  33. _handleClick() {
  34. sendAnalytics(createToolbarEvent(
  35. 'toggle.etherpad',
  36. {
  37. enable: !this.props._editing
  38. }));
  39. this.props.dispatch(toggleDocument());
  40. }
  41. /**
  42. * Indicates whether this button is in toggled state or not.
  43. *
  44. * @override
  45. * @protected
  46. * @returns {boolean}
  47. */
  48. _isToggled() {
  49. return this.props._editing;
  50. }
  51. }
  52. /**
  53. * Maps part of the redux state to the component's props.
  54. *
  55. * @param {Object} state - The redux store/state.
  56. * @param {Object} ownProps - The properties explicitly passed to the component
  57. * instance.
  58. * @returns {Object}
  59. */
  60. function _mapStateToProps(state: Object, ownProps: Object) {
  61. const { documentUrl, editing } = state['features/etherpad'];
  62. const { visible = Boolean(documentUrl) } = ownProps;
  63. return {
  64. _editing: editing,
  65. visible
  66. };
  67. }
  68. export default translate(connect(_mapStateToProps)(SharedDocumentButton));