bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/nav-bar/settings-dropdown/component.jsx

275 lines
8.5 KiB
React
Raw Normal View History

import React, { PureComponent } from 'react';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
2017-12-16 14:41:54 +08:00
import _ from 'lodash';
import PropTypes from 'prop-types';
2017-04-19 03:06:51 +08:00
import { withModalMounter } from '/imports/ui/components/modal/service';
2019-01-12 08:20:04 +08:00
import EndMeetingConfirmationContainer from '/imports/ui/components/end-meeting-confirmation/container';
2019-02-21 06:57:35 +08:00
import MeetingEndedComponent from '/imports/ui/components/meeting-ended/component';
2016-12-08 23:40:11 +08:00
import AboutContainer from '/imports/ui/components/about/container';
import SettingsMenuContainer from '/imports/ui/components/settings/container';
2016-09-02 04:19:37 +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';
import DropdownListSeparator from '/imports/ui/components/dropdown/list/separator/component';
2018-04-27 01:24:25 +08:00
import ShortcutHelpComponent from '/imports/ui/components/shortcut-help/component';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
2018-01-08 14:17:18 +08:00
import { styles } from '../styles';
2017-10-06 20:50:01 +08:00
2016-09-22 03:49:31 +08:00
const intlMessages = defineMessages({
optionsLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.optionsLabel',
2017-04-10 23:50:03 +08:00
description: 'Options button label',
2016-09-22 03:49:31 +08:00
},
fullscreenLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.fullscreenLabel',
2017-04-10 23:50:03 +08:00
description: 'Make fullscreen option label',
2016-09-22 03:49:31 +08:00
},
settingsLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.settingsLabel',
2017-04-10 23:50:03 +08:00
description: 'Open settings option label',
2016-09-22 03:49:31 +08:00
},
2016-12-08 05:14:14 +08:00
aboutLabel: {
id: 'app.navBar.settingsDropdown.aboutLabel',
2017-04-10 23:50:03 +08:00
description: 'About option label',
2016-12-08 05:14:14 +08:00
},
aboutDesc: {
id: 'app.navBar.settingsDropdown.aboutDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes about option',
2016-12-08 05:14:14 +08:00
},
2016-09-22 03:49:31 +08:00
leaveSessionLabel: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.leaveSessionLabel',
2017-04-10 23:50:03 +08:00
description: 'Leave session button label',
2016-09-22 03:49:31 +08:00
},
fullscreenDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.fullscreenDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes fullscreen option',
},
settingsDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.settingsDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes settings option',
},
leaveSessionDesc: {
2016-09-27 05:55:33 +08:00
id: 'app.navBar.settingsDropdown.leaveSessionDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes leave session option',
},
2017-08-11 00:05:51 +08:00
exitFullscreenDesc: {
id: 'app.navBar.settingsDropdown.exitFullscreenDesc',
2017-04-10 23:50:03 +08:00
description: 'Describes exit fullscreen option',
2017-02-14 00:21:53 +08:00
},
2017-08-11 00:05:51 +08:00
exitFullscreenLabel: {
id: 'app.navBar.settingsDropdown.exitFullscreenLabel',
2017-04-10 23:50:03 +08:00
description: 'Exit fullscreen option label',
2017-02-14 00:21:53 +08:00
},
hotkeysLabel: {
id: 'app.navBar.settingsDropdown.hotkeysLabel',
2018-05-03 11:33:28 +08:00
description: 'Hotkeys options label',
},
hotkeysDesc: {
id: 'app.navBar.settingsDropdown.hotkeysDesc',
2018-05-03 11:33:28 +08:00
description: 'Describes hotkeys option',
},
helpLabel: {
id: 'app.navBar.settingsDropdown.helpLabel',
description: 'Help options label',
},
helpDesc: {
id: 'app.navBar.settingsDropdown.helpDesc',
description: 'Describes help option',
},
2019-01-12 08:20:04 +08:00
endMeetingLabel: {
id: 'app.navBar.settingsDropdown.endMeetingLabel',
description: 'End meeting options label',
},
endMeetingDesc: {
id: 'app.navBar.settingsDropdown.endMeetingDesc',
description: 'Describes settings option closing the current meeting',
},
2016-09-22 03:49:31 +08:00
});
const propTypes = {
intl: intlShape.isRequired,
handleToggleFullscreen: PropTypes.func.isRequired,
mountModal: PropTypes.func.isRequired,
isFullScreen: PropTypes.bool,
isAndroid: PropTypes.bool,
amIModerator: PropTypes.bool,
shortcuts: PropTypes.string,
};
const defaultProps = {
isFullScreen: false,
isAndroid: false,
amIModerator: false,
shortcuts: '',
};
class SettingsDropdown extends PureComponent {
constructor(props) {
super(props);
this.state = {
isSettingOpen: false,
};
this.onActionsShow = this.onActionsShow.bind(this);
this.onActionsHide = this.onActionsHide.bind(this);
2017-12-16 14:41:54 +08:00
}
onActionsShow() {
this.setState({
isSettingOpen: true,
});
}
onActionsHide() {
this.setState({
isSettingOpen: false,
});
}
getFullscreenItem() {
const {
intl,
isFullScreen,
isAndroid,
handleToggleFullscreen,
} = this.props;
2018-05-09 05:37:58 +08:00
let fullscreenLabel = intl.formatMessage(intlMessages.fullscreenLabel);
let fullscreenDesc = intl.formatMessage(intlMessages.fullscreenDesc);
let fullscreenIcon = 'fullscreen';
2016-09-02 04:19:37 +08:00
2018-05-09 05:37:58 +08:00
if (isFullScreen) {
fullscreenLabel = intl.formatMessage(intlMessages.exitFullscreenLabel);
fullscreenDesc = intl.formatMessage(intlMessages.exitFullscreenDesc);
fullscreenIcon = 'exit_fullscreen';
}
2018-05-09 05:37:58 +08:00
if (!isAndroid) return null;
return (
2018-12-06 01:42:31 +08:00
<DropdownListItem
key="list-item-fullscreen"
2018-12-06 01:42:31 +08:00
icon={fullscreenIcon}
label={fullscreenLabel}
description={fullscreenDesc}
2019-01-12 08:20:04 +08:00
onClick={handleToggleFullscreen}
2018-12-06 01:42:31 +08:00
/>
);
}
2019-02-21 06:57:35 +08:00
leaveSession() {
const { mountModal } = this.props;
const LOGOUT_CODE = '430';
// we don't check askForFeedbackOnLogout here,
// it is checked in meeting-ended component
mountModal(<MeetingEndedComponent code={LOGOUT_CODE} />);
}
renderMenuItems() {
const {
intl, mountModal, amIModerator,
} = this.props;
2019-02-21 00:01:40 +08:00
const { showHelpButton: helpButton, helpLink } = Meteor.settings.public.app;
return _.compact([
this.getFullscreenItem(),
(<DropdownListItem
key="list-item-settings"
icon="settings"
label={intl.formatMessage(intlMessages.settingsLabel)}
description={intl.formatMessage(intlMessages.settingsDesc)}
onClick={() => mountModal(<SettingsMenuContainer />)}
/>),
(<DropdownListItem
key="list-item-about"
icon="about"
label={intl.formatMessage(intlMessages.aboutLabel)}
description={intl.formatMessage(intlMessages.aboutDesc)}
onClick={() => mountModal(<AboutContainer />)}
/>),
!helpButton ? null
: (
<DropdownListItem
key="list-item-help"
icon="help"
label={intl.formatMessage(intlMessages.helpLabel)}
description={intl.formatMessage(intlMessages.helpDesc)}
2019-02-21 00:01:40 +08:00
onClick={() => window.open(`${helpLink}`)}
/>
),
(<DropdownListItem
key="list-item-shortcuts"
icon="shortcuts"
label={intl.formatMessage(intlMessages.hotkeysLabel)}
description={intl.formatMessage(intlMessages.hotkeysDesc)}
onClick={() => mountModal(<ShortcutHelpComponent />)}
/>),
(<DropdownListSeparator key={_.uniqueId('list-separator-')} />),
!amIModerator ? null
: (
<DropdownListItem
key="list-item-end-meeting"
icon="application"
label={intl.formatMessage(intlMessages.endMeetingLabel)}
description={intl.formatMessage(intlMessages.endMeetingDesc)}
onClick={() => mountModal(<EndMeetingConfirmationContainer />)}
/>
),
(<DropdownListItem
key="list-item-logout"
icon="logout"
label={intl.formatMessage(intlMessages.leaveSessionLabel)}
description={intl.formatMessage(intlMessages.leaveSessionDesc)}
2019-02-21 06:57:35 +08:00
onClick={() => this.leaveSession()}
/>),
]);
2017-12-16 14:41:54 +08:00
}
2017-02-14 00:21:53 +08:00
2017-12-16 14:41:54 +08:00
render() {
const {
intl,
shortcuts: OPEN_OPTIONS_AK,
} = this.props;
2017-02-14 00:21:53 +08:00
2019-01-12 08:20:04 +08:00
const { isSettingOpen } = this.state;
2016-09-02 04:19:37 +08:00
return (
2017-06-03 03:25:02 +08:00
<Dropdown
autoFocus
2019-01-18 03:33:58 +08:00
keepOpen={isSettingOpen}
2017-06-03 03:25:02 +08:00
onShow={this.onActionsShow}
onHide={this.onActionsHide}
>
2018-05-02 08:02:45 +08:00
<DropdownTrigger tabIndex={0} accessKey={OPEN_OPTIONS_AK}>
2016-09-02 04:19:37 +08:00
<Button
label={intl.formatMessage(intlMessages.optionsLabel)}
2016-09-02 04:19:37 +08:00
icon="more"
2017-06-03 03:25:02 +08:00
ghost
circle
hideLabel
2018-12-06 01:42:31 +08:00
className={styles.btn}
// FIXME: Without onClick react proptypes keep warning
// even after the DropdownTrigger inject an onClick handler
onClick={() => null}
2016-09-02 04:19:37 +08:00
/>
</DropdownTrigger>
<DropdownContent placement="bottom right">
<DropdownList>
{this.renderMenuItems()}
</DropdownList>
2016-09-02 04:19:37 +08:00
</DropdownContent>
</Dropdown>
);
}
}
SettingsDropdown.propTypes = propTypes;
SettingsDropdown.defaultProps = defaultProps;
export default withShortcutHelper(withModalMounter(injectIntl(SettingsDropdown)), 'openOptions');