您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

SharedDocumentButton.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. // @flow
  2. import { createToolbarEvent, sendAnalytics } from '../../analytics';
  3. import { translate } from '../../base/i18n';
  4. import { IconShareDoc } from '../../base/icons';
  5. import { connect } from '../../base/redux';
  6. import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
  7. import { navigate } from '../../conference/components/native/ConferenceNavigationContainerRef';
  8. import { screen } from '../../conference/components/native/routes';
  9. type Props = AbstractButtonProps & {
  10. /**
  11. * Whether the shared document is being edited or not.
  12. */
  13. _editing: boolean
  14. };
  15. /**
  16. * Implements an {@link AbstractButton} to open the chat screen on mobile.
  17. */
  18. class SharedDocumentButton extends AbstractButton<Props, *> {
  19. accessibilityLabel = 'toolbar.accessibilityLabel.document';
  20. icon = IconShareDoc;
  21. label = 'toolbar.documentOpen';
  22. toggledLabel = 'toolbar.documentClose';
  23. /**
  24. * Dynamically retrieves tooltip based on sharing state.
  25. */
  26. get tooltip() {
  27. if (this._isToggled()) {
  28. return 'toolbar.documentClose';
  29. }
  30. return 'toolbar.documentOpen';
  31. }
  32. /**
  33. * Required by linter due to AbstractButton overwritten prop being writable.
  34. *
  35. * @param {string} value - The value.
  36. */
  37. set tooltip(value) {
  38. return value;
  39. }
  40. /**
  41. * Handles clicking / pressing the button, and opens / closes the appropriate dialog.
  42. *
  43. * @private
  44. * @returns {void}
  45. */
  46. _handleClick() {
  47. const { _editing, handleClick } = this.props;
  48. if (handleClick) {
  49. handleClick();
  50. return;
  51. }
  52. sendAnalytics(createToolbarEvent(
  53. 'toggle.etherpad',
  54. {
  55. enable: !_editing
  56. }));
  57. navigate(screen.conference.sharedDocument);
  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));