2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
2016-09-22 03:49:31 +08:00
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
2016-12-06 03:16:52 +08:00
|
|
|
import cx from 'classnames';
|
2017-12-16 14:41:54 +08:00
|
|
|
import _ from 'lodash';
|
2017-04-19 03:06:51 +08:00
|
|
|
import { withModalMounter } from '/imports/ui/components/modal/service';
|
2018-06-22 00:19:42 +08:00
|
|
|
|
2017-04-19 03:06:51 +08:00
|
|
|
|
2017-08-12 04:32:33 +08:00
|
|
|
import LogoutConfirmationContainer from '/imports/ui/components/logout-confirmation/container';
|
2016-12-08 23:40:11 +08:00
|
|
|
import AboutContainer from '/imports/ui/components/about/container';
|
2016-11-24 04:01:09 +08:00
|
|
|
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';
|
2016-09-07 03:10:18 +08:00
|
|
|
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';
|
2016-09-07 03:10:18 +08:00
|
|
|
|
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({
|
2016-09-23 04:51:00 +08:00
|
|
|
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
|
|
|
},
|
2016-09-23 04:51:00 +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',
|
2016-09-23 04:51:00 +08:00
|
|
|
},
|
|
|
|
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',
|
2016-09-23 04:51:00 +08:00
|
|
|
},
|
|
|
|
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',
|
2016-09-23 04:51:00 +08:00
|
|
|
},
|
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
|
|
|
},
|
2018-05-03 10:20:38 +08:00
|
|
|
hotkeysLabel: {
|
|
|
|
id: 'app.navBar.settingsDropdown.hotkeysLabel',
|
2018-05-03 11:33:28 +08:00
|
|
|
description: 'Hotkeys options label',
|
2018-05-03 10:20:38 +08:00
|
|
|
},
|
|
|
|
hotkeysDesc: {
|
|
|
|
id: 'app.navBar.settingsDropdown.hotkeysDesc',
|
2018-05-03 11:33:28 +08:00
|
|
|
description: 'Describes hotkeys option',
|
2018-05-03 10:20:38 +08:00
|
|
|
},
|
2016-09-22 03:49:31 +08:00
|
|
|
});
|
|
|
|
|
2018-05-02 08:02:45 +08:00
|
|
|
const SHORTCUTS_CONFIG = Meteor.settings.public.app.shortcuts;
|
|
|
|
const OPEN_OPTIONS_AK = SHORTCUTS_CONFIG.openOptions.accesskey;
|
|
|
|
|
2016-09-27 05:55:33 +08:00
|
|
|
class SettingsDropdown extends Component {
|
2016-09-07 03:10:18 +08:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2017-05-25 06:42:02 +08:00
|
|
|
|
|
|
|
this.state = {
|
|
|
|
isSettingOpen: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onActionsShow = this.onActionsShow.bind(this);
|
|
|
|
this.onActionsHide = this.onActionsHide.bind(this);
|
2017-12-16 14:41:54 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillMount() {
|
2018-06-23 02:45:46 +08:00
|
|
|
const { intl, mountModal, isAndroid } = this.props;
|
2018-06-23 01:20:45 +08:00
|
|
|
const { fullscreenLabel, fullscreenDesc, fullscreenIcon } = this.checkFullscreen(this.props);
|
2018-06-22 00:19:42 +08:00
|
|
|
|
2018-06-23 01:20:45 +08:00
|
|
|
this.menuItems = [(<DropdownListItem
|
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon={fullscreenIcon}
|
|
|
|
label={fullscreenLabel}
|
|
|
|
description={fullscreenDesc}
|
|
|
|
onClick={this.props.handleToggleFullscreen}
|
|
|
|
/>),
|
2017-12-16 14:41:54 +08:00
|
|
|
(<DropdownListItem
|
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon="settings"
|
|
|
|
label={intl.formatMessage(intlMessages.settingsLabel)}
|
|
|
|
description={intl.formatMessage(intlMessages.settingsDesc)}
|
|
|
|
onClick={() => mountModal(<SettingsMenuContainer />)}
|
|
|
|
/>),
|
|
|
|
(<DropdownListItem
|
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon="about"
|
|
|
|
label={intl.formatMessage(intlMessages.aboutLabel)}
|
|
|
|
description={intl.formatMessage(intlMessages.aboutDesc)}
|
|
|
|
onClick={() => mountModal(<AboutContainer />)}
|
|
|
|
/>),
|
2018-04-27 01:24:25 +08:00
|
|
|
(<DropdownListItem
|
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon="about"
|
2018-05-03 10:20:38 +08:00
|
|
|
label={intl.formatMessage(intlMessages.hotkeysLabel)}
|
|
|
|
description={intl.formatMessage(intlMessages.hotkeysDesc)}
|
2018-04-27 01:24:25 +08:00
|
|
|
onClick={() => mountModal(<ShortcutHelpComponent />)}
|
|
|
|
/>),
|
2017-12-16 14:41:54 +08:00
|
|
|
(<DropdownListSeparator key={_.uniqueId('list-separator-')} />),
|
|
|
|
(<DropdownListItem
|
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon="logout"
|
|
|
|
label={intl.formatMessage(intlMessages.leaveSessionLabel)}
|
|
|
|
description={intl.formatMessage(intlMessages.leaveSessionDesc)}
|
|
|
|
onClick={() => mountModal(<LogoutConfirmationContainer />)}
|
|
|
|
/>),
|
|
|
|
];
|
2018-06-20 01:58:20 +08:00
|
|
|
|
2018-06-23 01:20:45 +08:00
|
|
|
// Removes fullscreen button if not on Android
|
2018-06-23 02:45:46 +08:00
|
|
|
if (!isAndroid) {
|
|
|
|
this.menuItems.shift();
|
2018-06-19 04:23:20 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
|
// Alters fullscreen button's label
|
2018-06-22 00:19:42 +08:00
|
|
|
if (this.props.isAndroid) {
|
2018-06-19 04:23:20 +08:00
|
|
|
this.alterMenu(nextProps);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
onActionsShow() {
|
|
|
|
this.setState({
|
|
|
|
isSettingOpen: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
onActionsHide() {
|
|
|
|
this.setState({
|
|
|
|
isSettingOpen: false,
|
|
|
|
});
|
2017-05-25 06:42:02 +08:00
|
|
|
}
|
|
|
|
|
2018-05-09 05:37:58 +08:00
|
|
|
checkFullscreen(nextProps) {
|
|
|
|
const { intl, isFullScreen } = nextProps;
|
2017-05-25 06:42:02 +08:00
|
|
|
|
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) {
|
2018-05-09 00:04:15 +08:00
|
|
|
fullscreenLabel = intl.formatMessage(intlMessages.exitFullscreenLabel);
|
|
|
|
fullscreenDesc = intl.formatMessage(intlMessages.exitFullscreenDesc);
|
|
|
|
fullscreenIcon = 'exit_fullscreen';
|
|
|
|
}
|
2018-05-09 05:37:58 +08:00
|
|
|
return {
|
|
|
|
fullscreenLabel,
|
|
|
|
fullscreenDesc,
|
|
|
|
fullscreenIcon,
|
|
|
|
};
|
|
|
|
}
|
2017-02-14 00:21:53 +08:00
|
|
|
|
2018-05-09 05:37:58 +08:00
|
|
|
alterMenu(props) {
|
|
|
|
const { fullscreenLabel, fullscreenDesc, fullscreenIcon } = this.checkFullscreen(props);
|
|
|
|
|
|
|
|
const newFullScreenButton = (<DropdownListItem
|
2018-05-09 00:04:15 +08:00
|
|
|
key={_.uniqueId('list-item-')}
|
|
|
|
icon={fullscreenIcon}
|
|
|
|
label={fullscreenLabel}
|
|
|
|
description={fullscreenDesc}
|
|
|
|
onClick={this.props.handleToggleFullscreen}
|
2018-05-09 05:37:58 +08:00
|
|
|
/>);
|
2018-06-19 04:23:20 +08:00
|
|
|
this.menuItems = this.menuItems.slice(1);
|
|
|
|
this.menuItems.unshift(newFullScreenButton);
|
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 } = this.props;
|
2017-02-14 00:21:53 +08:00
|
|
|
|
2016-09-02 04:19:37 +08:00
|
|
|
return (
|
2017-06-03 03:25:02 +08:00
|
|
|
<Dropdown
|
2017-06-28 03:41:12 +08:00
|
|
|
autoFocus
|
2017-06-03 03:25:02 +08:00
|
|
|
isOpen={this.state.isSettingOpen}
|
|
|
|
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
|
2016-09-23 04:51:00 +08:00
|
|
|
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
|
2016-12-06 03:16:52 +08:00
|
|
|
className={cx(styles.btn, styles.btnSettings)}
|
2016-09-07 03:10:18 +08:00
|
|
|
|
|
|
|
// 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>
|
2016-09-07 03:10:18 +08:00
|
|
|
<DropdownContent placement="bottom right">
|
|
|
|
<DropdownList>
|
2017-12-16 14:41:54 +08:00
|
|
|
{
|
2018-06-19 04:23:20 +08:00
|
|
|
this.menuItems
|
2017-12-15 23:39:59 +08:00
|
|
|
}
|
2016-09-07 03:10:18 +08:00
|
|
|
</DropdownList>
|
2016-09-02 04:19:37 +08:00
|
|
|
</DropdownContent>
|
|
|
|
</Dropdown>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-09-22 03:49:31 +08:00
|
|
|
|
2017-04-19 03:06:51 +08:00
|
|
|
export default withModalMounter(injectIntl(SettingsDropdown));
|