2018-11-06 22:59:53 +08:00
|
|
|
import _ from 'lodash';
|
2019-06-03 22:28:05 +08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-06-04 10:40:14 +08:00
|
|
|
import PropTypes from 'prop-types';
|
2020-05-26 04:00:13 +08:00
|
|
|
import { defineMessages } from 'react-intl';
|
2016-10-18 05:29:00 +08:00
|
|
|
import Button from '/imports/ui/components/button/component';
|
|
|
|
import Dropdown from '/imports/ui/components/dropdown/component';
|
|
|
|
import DropdownTrigger from '/imports/ui/components/dropdown/trigger/component';
|
|
|
|
import DropdownContent from '/imports/ui/components/dropdown/content/component';
|
|
|
|
import DropdownList from '/imports/ui/components/dropdown/list/component';
|
|
|
|
import DropdownListItem from '/imports/ui/components/dropdown/list/item/component';
|
2017-09-30 04:32:31 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2018-11-01 02:51:56 +08:00
|
|
|
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
|
2020-01-25 09:02:36 +08:00
|
|
|
import DropdownListSeparator from '/imports/ui/components/dropdown/list/separator/component';
|
2018-11-30 01:24:02 +08:00
|
|
|
import ExternalVideoModal from '/imports/ui/components/external-video-player/modal/container';
|
2020-08-29 01:23:27 +08:00
|
|
|
import RandomUserSelectContainer from '/imports/ui/components/modal/random-user/container';
|
2020-01-25 09:02:36 +08:00
|
|
|
import cx from 'classnames';
|
|
|
|
import { styles } from '../styles';
|
2018-11-30 01:24:02 +08:00
|
|
|
|
2017-06-07 20:01:18 +08:00
|
|
|
const propTypes = {
|
2019-09-07 04:28:02 +08:00
|
|
|
amIPresenter: PropTypes.bool.isRequired,
|
2020-05-26 04:00:13 +08:00
|
|
|
intl: PropTypes.object.isRequired,
|
2017-06-07 20:01:18 +08:00
|
|
|
mountModal: PropTypes.func.isRequired,
|
2019-09-07 04:28:02 +08:00
|
|
|
amIModerator: PropTypes.bool.isRequired,
|
2019-11-06 05:36:03 +08:00
|
|
|
shortcuts: PropTypes.string,
|
2019-01-11 00:10:45 +08:00
|
|
|
handleTakePresenter: PropTypes.func.isRequired,
|
2019-05-29 22:31:27 +08:00
|
|
|
allowExternalVideo: PropTypes.bool.isRequired,
|
|
|
|
stopExternalVideoShare: PropTypes.func.isRequired,
|
2017-06-07 20:01:18 +08:00
|
|
|
};
|
|
|
|
|
2019-11-06 05:36:03 +08:00
|
|
|
const defaultProps = {
|
|
|
|
shortcuts: '',
|
|
|
|
};
|
|
|
|
|
2016-10-18 05:29:00 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
actionsLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.actionsLabel',
|
2017-04-10 23:50:03 +08:00
|
|
|
description: 'Actions button label',
|
2016-10-18 05:29:00 +08:00
|
|
|
},
|
|
|
|
presentationLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.presentationLabel',
|
2017-04-10 23:50:03 +08:00
|
|
|
description: 'Upload a presentation option label',
|
2016-10-18 05:29:00 +08:00
|
|
|
},
|
|
|
|
presentationDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.presentationDesc',
|
2017-04-11 21:52:30 +08:00
|
|
|
description: 'adds context to upload presentation option',
|
2016-10-18 05:29:00 +08:00
|
|
|
},
|
|
|
|
desktopShareDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.desktopShareDesc',
|
2017-04-11 21:52:30 +08:00
|
|
|
description: 'adds context to desktop share option',
|
2016-10-18 05:29:00 +08:00
|
|
|
},
|
2017-11-06 23:39:55 +08:00
|
|
|
stopDesktopShareDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.stopDesktopShareDesc',
|
|
|
|
description: 'adds context to stop desktop share option',
|
|
|
|
},
|
2018-09-24 06:20:20 +08:00
|
|
|
pollBtnLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.pollBtnLabel',
|
|
|
|
description: 'poll menu toggle button label',
|
|
|
|
},
|
|
|
|
pollBtnDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.pollBtnDesc',
|
|
|
|
description: 'poll menu toggle button description',
|
|
|
|
},
|
2019-01-11 00:10:45 +08:00
|
|
|
takePresenter: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.takePresenter',
|
|
|
|
description: 'Label for take presenter role option',
|
|
|
|
},
|
|
|
|
takePresenterDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.takePresenterDesc',
|
|
|
|
description: 'Description of take presenter role option',
|
|
|
|
},
|
2019-02-16 01:32:03 +08:00
|
|
|
startExternalVideoLabel: {
|
2018-11-30 01:24:02 +08:00
|
|
|
id: 'app.actionsBar.actionsDropdown.shareExternalVideo',
|
2019-02-16 01:32:03 +08:00
|
|
|
description: 'Start sharing external video button',
|
|
|
|
},
|
|
|
|
stopExternalVideoLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.stopShareExternalVideo',
|
|
|
|
description: 'Stop sharing external video button',
|
2018-11-30 01:24:02 +08:00
|
|
|
},
|
2020-08-29 01:23:27 +08:00
|
|
|
selectRandUserLabel: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.selectRandUserLabel',
|
|
|
|
description: 'Label for selecting a random user',
|
|
|
|
},
|
|
|
|
selectRandUserDesc: {
|
|
|
|
id: 'app.actionsBar.actionsDropdown.selectRandUserDesc',
|
|
|
|
description: 'Description for select random user option',
|
|
|
|
},
|
2016-10-18 05:29:00 +08:00
|
|
|
});
|
|
|
|
|
2020-03-10 20:58:14 +08:00
|
|
|
const handlePresentationClick = () => Session.set('showUploadPresentationView', true);
|
2020-02-26 03:29:14 +08:00
|
|
|
|
2019-06-03 22:28:05 +08:00
|
|
|
class ActionsDropdown extends PureComponent {
|
2016-10-18 05:29:00 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-05-04 04:51:17 +08:00
|
|
|
|
2018-01-18 05:51:33 +08:00
|
|
|
this.presentationItemId = _.uniqueId('action-item-');
|
2018-09-24 06:20:20 +08:00
|
|
|
this.pollId = _.uniqueId('action-item-');
|
2019-01-11 00:10:45 +08:00
|
|
|
this.takePresenterId = _.uniqueId('action-item-');
|
2020-08-29 01:23:27 +08:00
|
|
|
this.selectUserRandId = _.uniqueId('action-item-');
|
2018-01-18 05:51:33 +08:00
|
|
|
|
2019-04-03 02:57:29 +08:00
|
|
|
this.handleExternalVideoClick = this.handleExternalVideoClick.bind(this);
|
2020-01-25 09:02:36 +08:00
|
|
|
this.makePresentationItems = this.makePresentationItems.bind(this);
|
2018-11-01 23:03:16 +08:00
|
|
|
}
|
|
|
|
|
2020-08-08 04:43:33 +08:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
const { amIPresenter: wasPresenter } = prevProps;
|
|
|
|
const { amIPresenter: isPresenter, mountModal } = this.props;
|
2017-10-13 06:44:38 +08:00
|
|
|
if (wasPresenter && !isPresenter) {
|
|
|
|
mountModal(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-17 21:34:35 +08:00
|
|
|
getAvailableActions() {
|
|
|
|
const {
|
|
|
|
intl,
|
2019-09-07 04:28:02 +08:00
|
|
|
amIPresenter,
|
2018-11-30 01:24:02 +08:00
|
|
|
allowExternalVideo,
|
2019-01-11 00:10:45 +08:00
|
|
|
handleTakePresenter,
|
2019-02-16 01:32:03 +08:00
|
|
|
isSharingVideo,
|
2019-07-02 22:54:37 +08:00
|
|
|
isPollingEnabled,
|
2021-03-20 02:52:03 +08:00
|
|
|
isSelectRandomUserEnabled,
|
2019-04-25 01:19:35 +08:00
|
|
|
stopExternalVideoShare,
|
2020-08-29 01:23:27 +08:00
|
|
|
mountModal,
|
2018-01-17 21:34:35 +08:00
|
|
|
} = this.props;
|
|
|
|
|
2018-12-18 23:15:51 +08:00
|
|
|
const {
|
|
|
|
pollBtnLabel,
|
|
|
|
pollBtnDesc,
|
|
|
|
presentationLabel,
|
|
|
|
presentationDesc,
|
2019-01-11 00:10:45 +08:00
|
|
|
takePresenter,
|
|
|
|
takePresenterDesc,
|
2018-12-18 23:15:51 +08:00
|
|
|
} = intlMessages;
|
|
|
|
|
|
|
|
const {
|
|
|
|
formatMessage,
|
|
|
|
} = intl;
|
|
|
|
|
2018-01-17 21:34:35 +08:00
|
|
|
return _.compact([
|
2019-09-07 04:28:02 +08:00
|
|
|
(amIPresenter && isPollingEnabled
|
2018-12-18 23:15:51 +08:00
|
|
|
? (
|
|
|
|
<DropdownListItem
|
2019-05-24 05:13:52 +08:00
|
|
|
icon="polling"
|
2020-03-20 22:42:04 +08:00
|
|
|
data-test="polling"
|
2018-12-18 23:15:51 +08:00
|
|
|
label={formatMessage(pollBtnLabel)}
|
|
|
|
description={formatMessage(pollBtnDesc)}
|
|
|
|
key={this.pollId}
|
|
|
|
onClick={() => {
|
2019-03-28 23:58:10 +08:00
|
|
|
if (Session.equals('pollInitiated', true)) {
|
|
|
|
Session.set('resetPollPanel', true);
|
2019-03-15 03:34:53 +08:00
|
|
|
}
|
2018-12-18 23:15:51 +08:00
|
|
|
Session.set('openPanel', 'poll');
|
|
|
|
Session.set('forcePollOpen', true);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
)
|
2019-07-03 02:03:33 +08:00
|
|
|
: null),
|
2019-09-07 04:28:02 +08:00
|
|
|
(!amIPresenter
|
2019-07-03 02:03:33 +08:00
|
|
|
? (
|
2019-01-12 03:15:31 +08:00
|
|
|
<DropdownListItem
|
|
|
|
icon="presentation"
|
|
|
|
label={formatMessage(takePresenter)}
|
|
|
|
description={formatMessage(takePresenterDesc)}
|
|
|
|
key={this.takePresenterId}
|
|
|
|
onClick={() => handleTakePresenter()}
|
|
|
|
/>
|
2019-07-03 02:03:33 +08:00
|
|
|
)
|
|
|
|
: null),
|
2019-09-07 04:28:02 +08:00
|
|
|
(amIPresenter
|
2018-12-10 10:12:42 +08:00
|
|
|
? (
|
|
|
|
<DropdownListItem
|
|
|
|
data-test="uploadPresentation"
|
|
|
|
icon="presentation"
|
2018-12-18 23:15:51 +08:00
|
|
|
label={formatMessage(presentationLabel)}
|
|
|
|
description={formatMessage(presentationDesc)}
|
2018-12-10 10:12:42 +08:00
|
|
|
key={this.presentationItemId}
|
2020-02-26 03:29:14 +08:00
|
|
|
onClick={handlePresentationClick}
|
2018-12-10 10:12:42 +08:00
|
|
|
/>
|
|
|
|
)
|
2018-02-21 02:23:35 +08:00
|
|
|
: null),
|
2019-09-07 04:28:02 +08:00
|
|
|
(amIPresenter && allowExternalVideo
|
2018-12-11 07:07:20 +08:00
|
|
|
? (
|
|
|
|
<DropdownListItem
|
|
|
|
icon="video"
|
2019-02-16 01:32:03 +08:00
|
|
|
label={!isSharingVideo ? intl.formatMessage(intlMessages.startExternalVideoLabel)
|
2019-03-15 03:34:53 +08:00
|
|
|
: intl.formatMessage(intlMessages.stopExternalVideoLabel)}
|
2018-12-11 07:07:20 +08:00
|
|
|
description="External Video"
|
|
|
|
key="external-video"
|
2019-04-25 01:19:35 +08:00
|
|
|
onClick={isSharingVideo ? stopExternalVideoShare : this.handleExternalVideoClick}
|
2018-12-11 07:07:20 +08:00
|
|
|
/>
|
|
|
|
)
|
2019-04-03 02:57:29 +08:00
|
|
|
: null),
|
2021-03-20 02:52:03 +08:00
|
|
|
(amIPresenter && isSelectRandomUserEnabled
|
2020-08-29 01:23:27 +08:00
|
|
|
? (
|
|
|
|
<DropdownListItem
|
|
|
|
icon="user"
|
|
|
|
label={intl.formatMessage(intlMessages.selectRandUserLabel)}
|
|
|
|
description={intl.formatMessage(intlMessages.selectRandUserDesc)}
|
|
|
|
key={this.selectUserRandId}
|
|
|
|
onClick={() => mountModal(<RandomUserSelectContainer isSelectedUser={false} />)}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
: null),
|
2018-01-17 21:34:35 +08:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-25 09:02:36 +08:00
|
|
|
makePresentationItems() {
|
|
|
|
const {
|
|
|
|
presentations,
|
|
|
|
setPresentation,
|
|
|
|
podIds,
|
|
|
|
} = this.props;
|
|
|
|
|
2020-03-10 01:52:49 +08:00
|
|
|
if (!podIds || podIds.length < 1) return [];
|
|
|
|
|
|
|
|
// We still have code for other pods from the Flash client. This intentionally only cares
|
|
|
|
// about the first one because it's the default.
|
|
|
|
const { podId } = podIds[0];
|
2020-01-25 09:02:36 +08:00
|
|
|
|
2021-04-07 22:37:49 +08:00
|
|
|
const presentationItemElements = presentations
|
|
|
|
.sort((a, b) => (a.name.localeCompare(b.name)))
|
|
|
|
.map((p) => {
|
|
|
|
const itemStyles = {};
|
|
|
|
itemStyles[styles.presentationItem] = true;
|
|
|
|
itemStyles[styles.isCurrent] = p.current;
|
2020-01-25 09:02:36 +08:00
|
|
|
|
2021-04-07 22:37:49 +08:00
|
|
|
return (<DropdownListItem
|
|
|
|
className={cx(itemStyles)}
|
|
|
|
icon="file"
|
|
|
|
iconRight={p.current ? 'check' : null}
|
|
|
|
label={p.name}
|
|
|
|
description="uploaded presentation file"
|
|
|
|
key={`uploaded-presentation-${p.id}`}
|
|
|
|
onClick={() => {
|
|
|
|
setPresentation(p.id, podId);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
});
|
2020-01-25 09:02:36 +08:00
|
|
|
|
|
|
|
presentationItemElements.push(<DropdownListSeparator key={_.uniqueId('list-separator-')} />);
|
|
|
|
return presentationItemElements;
|
|
|
|
}
|
|
|
|
|
2019-03-15 03:34:53 +08:00
|
|
|
handleExternalVideoClick() {
|
|
|
|
const { mountModal } = this.props;
|
|
|
|
mountModal(<ExternalVideoModal />);
|
2018-11-30 01:24:02 +08:00
|
|
|
}
|
|
|
|
|
2016-10-18 05:29:00 +08:00
|
|
|
render() {
|
2017-09-13 04:47:06 +08:00
|
|
|
const {
|
|
|
|
intl,
|
2019-09-07 04:28:02 +08:00
|
|
|
amIPresenter,
|
|
|
|
amIModerator,
|
2018-11-01 02:51:56 +08:00
|
|
|
shortcuts: OPEN_ACTIONS_AK,
|
2019-06-27 00:29:34 +08:00
|
|
|
isMeteorConnected,
|
2017-09-13 04:47:06 +08:00
|
|
|
} = this.props;
|
2017-03-24 23:37:33 +08:00
|
|
|
|
2018-01-17 21:34:35 +08:00
|
|
|
const availableActions = this.getAvailableActions();
|
2020-01-25 09:02:36 +08:00
|
|
|
const availablePresentations = this.makePresentationItems();
|
2020-01-27 23:48:35 +08:00
|
|
|
const children = availablePresentations.length > 2 && amIPresenter
|
2020-01-25 09:02:36 +08:00
|
|
|
? availablePresentations.concat(availableActions) : availableActions;
|
2018-01-17 21:34:35 +08:00
|
|
|
|
2019-09-07 04:28:02 +08:00
|
|
|
if ((!amIPresenter && !amIModerator)
|
|
|
|
|| availableActions.length === 0
|
|
|
|
|| !isMeteorConnected) {
|
|
|
|
return null;
|
|
|
|
}
|
2017-03-24 22:49:38 +08:00
|
|
|
|
2016-10-18 05:29:00 +08:00
|
|
|
return (
|
2020-11-07 04:48:06 +08:00
|
|
|
<Dropdown className={styles.dropdown} ref={(ref) => { this._dropdown = ref; }}>
|
2018-05-02 08:02:45 +08:00
|
|
|
<DropdownTrigger tabIndex={0} accessKey={OPEN_ACTIONS_AK}>
|
2016-10-18 05:29:00 +08:00
|
|
|
<Button
|
2017-12-11 21:47:50 +08:00
|
|
|
hideLabel
|
|
|
|
aria-label={intl.formatMessage(intlMessages.actionsLabel)}
|
2016-10-18 05:29:00 +08:00
|
|
|
label={intl.formatMessage(intlMessages.actionsLabel)}
|
2017-12-12 01:09:09 +08:00
|
|
|
icon="plus"
|
2016-10-18 05:29:00 +08:00
|
|
|
color="primary"
|
|
|
|
size="lg"
|
2017-06-03 03:25:02 +08:00
|
|
|
circle
|
2016-10-18 05:29:00 +08:00
|
|
|
onClick={() => null}
|
|
|
|
/>
|
|
|
|
</DropdownTrigger>
|
|
|
|
<DropdownContent placement="top left">
|
2021-04-08 21:01:20 +08:00
|
|
|
<DropdownList className={styles.scrollableList}>
|
2020-01-25 09:02:36 +08:00
|
|
|
{children}
|
2016-10-18 05:29:00 +08:00
|
|
|
</DropdownList>
|
|
|
|
</DropdownContent>
|
|
|
|
</Dropdown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-07 20:01:18 +08:00
|
|
|
ActionsDropdown.propTypes = propTypes;
|
2019-11-06 05:36:03 +08:00
|
|
|
ActionsDropdown.defaultProps = defaultProps;
|
2017-06-07 20:01:18 +08:00
|
|
|
|
2019-02-22 05:01:39 +08:00
|
|
|
export default withShortcutHelper(withModalMounter(ActionsDropdown), 'openActions');
|