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

230 lines
6.6 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
2017-03-10 03:50:21 +08:00
import _ from 'lodash';
import cx from 'classnames';
import Icon from '/imports/ui/components/icon/component';
import BreakoutJoinConfirmation from '/imports/ui/components/breakout-join-confirmation/container';
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-05-03 23:06:28 +08:00
import { withModalMounter } from '/imports/ui/components/modal/service';
import withShortcutHelper from '/imports/ui/components/shortcut-help/service';
import { defineMessages, injectIntl } from 'react-intl';
2018-02-23 01:30:12 +08:00
import { styles } from './styles.scss';
import Button from '../button/component';
import RecordingIndicator from './recording-indicator/component';
import SettingsDropdownContainer from './settings-dropdown/container';
const intlMessages = defineMessages({
toggleUserListLabel: {
id: 'app.navBar.userListToggleBtnLabel',
2017-04-10 23:50:03 +08:00
description: 'Toggle button label',
},
toggleUserListAria: {
id: 'app.navBar.toggleUserList.ariaLabel',
description: 'description of the lists inside the userlist',
},
newMessages: {
2017-08-11 00:05:51 +08:00
id: 'app.navBar.toggleUserList.newMessages',
2017-04-26 22:08:47 +08:00
description: 'label for toggleUserList btn when showing red notification',
},
2018-02-16 21:47:55 +08:00
recordingSession: {
id: 'app.navBar.recording',
description: 'label for when the session is being recorded',
},
recordingIndicatorOn: {
id: 'app.navBar.recording.on',
description: 'label for indicator when the session is being recorded',
},
recordingIndicatorOff: {
id: 'app.navBar.recording.off',
description: 'label for indicator when the session is not being recorded',
},
});
2016-04-29 03:02:51 +08:00
const propTypes = {
presentationTitle: PropTypes.string,
hasUnreadMessages: PropTypes.bool,
beingRecorded: PropTypes.object,
shortcuts: PropTypes.string,
2016-04-29 03:02:51 +08:00
};
const defaultProps = {
presentationTitle: 'Default Room Title',
2016-04-29 03:02:51 +08:00
hasUnreadMessages: false,
2016-06-29 02:50:44 +08:00
beingRecorded: false,
shortcuts: '',
2016-04-29 03:02:51 +08:00
};
const openBreakoutJoinConfirmation = (breakout, breakoutName, mountModal) =>
2017-05-03 23:06:28 +08:00
mountModal(<BreakoutJoinConfirmation
breakout={breakout}
2017-06-03 03:25:02 +08:00
breakoutName={breakoutName}
/>);
2018-05-02 08:02:45 +08:00
const closeBreakoutJoinConfirmation = mountModal =>
mountModal(null);
class NavBar extends Component {
2016-04-29 03:02:51 +08:00
constructor(props) {
super(props);
this.state = {
isActionsOpen: false,
2016-11-14 19:57:10 +08:00
didSendBreakoutInvite: false,
};
this.handleToggleUserList = this.handleToggleUserList.bind(this);
}
2017-10-23 23:47:14 +08:00
componentDidUpdate(oldProps) {
2017-10-11 06:08:51 +08:00
const {
breakouts,
isBreakoutRoom,
mountModal,
2017-10-11 06:08:51 +08:00
} = this.props;
2017-10-23 23:47:14 +08:00
const hadBreakouts = oldProps.breakouts.length;
const hasBreakouts = breakouts.length;
2017-10-24 00:15:55 +08:00
if (!hasBreakouts && hadBreakouts) {
closeBreakoutJoinConfirmation(mountModal);
2017-10-24 00:15:55 +08:00
}
2017-10-11 06:08:51 +08:00
breakouts.forEach((breakout) => {
if (!breakout.users) {
return;
}
2017-10-23 23:47:14 +08:00
2017-10-11 06:08:51 +08:00
if (!this.state.didSendBreakoutInvite && !isBreakoutRoom) {
this.inviteUserToBreakout(breakout);
2017-10-11 06:08:51 +08:00
}
});
if (!breakouts.length && this.state.didSendBreakoutInvite) {
2017-10-23 23:47:14 +08:00
this.setState({ didSendBreakoutInvite: false });
2017-10-11 06:08:51 +08:00
}
}
handleToggleUserList() {
this.props.toggleUserList();
}
inviteUserToBreakout(breakout) {
2017-05-03 23:06:28 +08:00
const {
mountModal,
} = this.props;
2016-11-14 19:57:10 +08:00
this.setState({ didSendBreakoutInvite: true }, () => {
openBreakoutJoinConfirmation.call(this, breakout, breakout.name, mountModal);
2016-11-14 19:57:10 +08:00
});
}
renderPresentationTitle() {
2016-11-29 03:48:02 +08:00
const {
2017-03-15 05:06:52 +08:00
breakouts,
isBreakoutRoom,
2017-03-15 05:06:52 +08:00
presentationTitle,
2016-11-29 03:48:02 +08:00
} = this.props;
2017-04-26 22:57:40 +08:00
if (isBreakoutRoom || !breakouts.length) {
return (
<h1 className={styles.presentationTitle}>{presentationTitle}</h1>
);
}
const breakoutItems = breakouts.map(breakout => this.renderBreakoutItem(breakout));
return (
<Dropdown isOpen={this.state.isActionsOpen}>
<DropdownTrigger>
2016-12-06 03:26:08 +08:00
<h1 className={cx(styles.presentationTitle, styles.dropdownBreakout)}>
2017-06-03 03:25:02 +08:00
{presentationTitle} <Icon iconName="down-arrow" />
</h1>
</DropdownTrigger>
<DropdownContent
2017-06-03 03:25:02 +08:00
placement="bottom"
>
<DropdownList>
{breakoutItems}
</DropdownList>
</DropdownContent>
</Dropdown>
);
}
renderBreakoutItem(breakout) {
2016-11-29 03:48:02 +08:00
const {
2017-05-03 23:06:28 +08:00
mountModal,
2016-11-29 03:48:02 +08:00
} = this.props;
const breakoutName = breakout.name;
return (
<DropdownListItem
className={styles.actionsHeader}
key={_.uniqueId('action-header')}
label={breakoutName}
onClick={openBreakoutJoinConfirmation.bind(this, breakout, breakoutName, mountModal)}
2016-12-09 00:20:47 +08:00
/>
);
}
2018-05-02 08:02:45 +08:00
2017-10-11 06:08:51 +08:00
render() {
2018-05-02 08:02:45 +08:00
const {
hasUnreadMessages,
beingRecorded,
isExpanded,
intl,
shortcuts: TOGGLE_USERLIST_AK,
2018-05-02 08:02:45 +08:00
} = this.props;
2017-10-11 06:08:51 +08:00
const recordingMessage = beingRecorded.recording ? 'recordingIndicatorOn' : 'recordingIndicatorOff';
2017-10-11 06:08:51 +08:00
const toggleBtnClasses = {};
toggleBtnClasses[styles.btn] = true;
toggleBtnClasses[styles.btnWithNotificationDot] = hasUnreadMessages;
let ariaLabel = intl.formatMessage(intlMessages.toggleUserListAria);
ariaLabel += hasUnreadMessages ? (` ${intl.formatMessage(intlMessages.newMessages)}`) : '';
2017-10-11 06:08:51 +08:00
return (
<div className={styles.navbar}>
<div className={styles.left}>
<Button
2018-01-09 10:43:34 +08:00
data-test="userListToggleButton"
2017-10-11 06:08:51 +08:00
onClick={this.handleToggleUserList}
ghost
circle
hideLabel
label={intl.formatMessage(intlMessages.toggleUserListLabel)}
aria-label={ariaLabel}
2018-02-23 01:30:12 +08:00
icon="user"
2017-10-11 06:08:51 +08:00
className={cx(toggleBtnClasses)}
aria-expanded={isExpanded}
2018-05-02 08:02:45 +08:00
accessKey={TOGGLE_USERLIST_AK}
2017-10-11 06:08:51 +08:00
/>
</div>
2018-02-23 01:30:12 +08:00
<div className={styles.center}>
2017-10-11 06:08:51 +08:00
{this.renderPresentationTitle()}
2018-02-28 22:10:00 +08:00
{beingRecorded.record ?
<span className={styles.presentationTitleSeparator}>|</span>
: null}
<RecordingIndicator
{...beingRecorded}
title={intl.formatMessage(intlMessages[recordingMessage])}
/>
2017-10-11 06:08:51 +08:00
</div>
<div className={styles.right}>
<SettingsDropdownContainer />
</div>
</div>
);
}
2016-04-29 03:02:51 +08:00
}
NavBar.propTypes = propTypes;
NavBar.defaultProps = defaultProps;
export default withShortcutHelper(withModalMounter(injectIntl(NavBar)), 'toggleUserList');