2019-10-04 15:10:19 +00:00
|
|
|
// @flow
|
|
|
|
|
2021-12-01 13:29:55 +00:00
|
|
|
import type { Dispatch } from 'redux';
|
|
|
|
|
2019-10-04 15:10:19 +00:00
|
|
|
import { createToolbarEvent, sendAnalytics } from '../../analytics';
|
|
|
|
import { translate } from '../../base/i18n';
|
|
|
|
import { IconShareDoc } from '../../base/icons';
|
|
|
|
import { connect } from '../../base/redux';
|
2020-07-24 12:14:33 +00:00
|
|
|
import { AbstractButton, type AbstractButtonProps } from '../../base/toolbox/components';
|
2021-12-01 13:29:55 +00:00
|
|
|
import { toggleDocument } from '../../etherpad/actions';
|
2019-10-04 15:10:19 +00:00
|
|
|
|
|
|
|
type Props = AbstractButtonProps & {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the shared document is being edited or not.
|
|
|
|
*/
|
2021-12-01 13:29:55 +00:00
|
|
|
_editing: boolean,
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redux dispatch function.
|
|
|
|
*/
|
|
|
|
dispatch: Dispatch<any>,
|
2019-10-04 15:10:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Implements an {@link AbstractButton} to open the chat screen on mobile.
|
|
|
|
*/
|
|
|
|
class SharedDocumentButton extends AbstractButton<Props, *> {
|
|
|
|
accessibilityLabel = 'toolbar.accessibilityLabel.document';
|
|
|
|
icon = IconShareDoc;
|
|
|
|
label = 'toolbar.documentOpen';
|
|
|
|
toggledLabel = 'toolbar.documentClose';
|
|
|
|
|
2021-07-08 13:42:07 +00:00
|
|
|
/**
|
|
|
|
* Dynamically retrieves tooltip based on sharing state.
|
|
|
|
*/
|
|
|
|
get tooltip() {
|
|
|
|
if (this._isToggled()) {
|
|
|
|
return 'toolbar.documentClose';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'toolbar.documentOpen';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Required by linter due to AbstractButton overwritten prop being writable.
|
|
|
|
*
|
2021-11-04 21:10:43 +00:00
|
|
|
* @param {string} _value - The value.
|
2021-07-08 13:42:07 +00:00
|
|
|
*/
|
2021-11-04 21:10:43 +00:00
|
|
|
set tooltip(_value) {
|
|
|
|
// Unused.
|
2021-07-08 13:42:07 +00:00
|
|
|
}
|
|
|
|
|
2019-10-04 15:10:19 +00:00
|
|
|
/**
|
|
|
|
* Handles clicking / pressing the button, and opens / closes the appropriate dialog.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @returns {void}
|
|
|
|
*/
|
|
|
|
_handleClick() {
|
2022-01-04 11:21:00 +00:00
|
|
|
const { _editing, dispatch } = this.props;
|
2021-09-14 07:07:20 +00:00
|
|
|
|
2019-10-04 15:10:19 +00:00
|
|
|
sendAnalytics(createToolbarEvent(
|
|
|
|
'toggle.etherpad',
|
|
|
|
{
|
2021-09-14 07:07:20 +00:00
|
|
|
enable: !_editing
|
2019-10-04 15:10:19 +00:00
|
|
|
}));
|
2021-10-20 19:29:21 +00:00
|
|
|
|
2021-12-01 13:29:55 +00:00
|
|
|
dispatch(toggleDocument());
|
2019-10-04 15:10:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates whether this button is in toggled state or not.
|
|
|
|
*
|
|
|
|
* @override
|
|
|
|
* @protected
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
_isToggled() {
|
|
|
|
return this.props._editing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Maps part of the redux state to the component's props.
|
|
|
|
*
|
|
|
|
* @param {Object} state - The redux store/state.
|
|
|
|
* @param {Object} ownProps - The properties explicitly passed to the component
|
|
|
|
* instance.
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
|
|
|
function _mapStateToProps(state: Object, ownProps: Object) {
|
|
|
|
const { documentUrl, editing } = state['features/etherpad'];
|
|
|
|
const { visible = Boolean(documentUrl) } = ownProps;
|
|
|
|
|
|
|
|
return {
|
|
|
|
_editing: editing,
|
|
|
|
visible
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default translate(connect(_mapStateToProps)(SharedDocumentButton));
|