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

193 lines
5.4 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 styles from './styles.scss';
import Button from '../button/component';
import RecordingIndicator from './recording-indicator/component';
2017-02-14 00:21:53 +08:00
import SettingsDropdownContainer from './settings-dropdown/container';
import Icon from '/imports/ui/components/icon/component';
import BreakoutJoinConfirmation from '/imports/ui/components/breakout-join-confirmation/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-05-03 23:06:28 +08:00
import { withModalMounter } from '/imports/ui/components/modal/service';
import { defineMessages, injectIntl } from 'react-intl';
const intlMessages = defineMessages({
toggleUserListLabel: {
id: 'app.navBar.userListToggleBtnLabel',
2017-04-10 23:50:03 +08:00
description: 'Toggle button label',
},
newMessages: {
id: 'app.navbar.toggleUserList.newMessages',
2017-04-26 22:08:47 +08:00
description: 'label for toggleUserList btn when showing red notification',
},
});
2016-04-29 03:02:51 +08:00
const propTypes = {
presentationTitle: PropTypes.string.isRequired,
hasUnreadMessages: PropTypes.bool.isRequired,
2016-06-29 02:50:44 +08:00
beingRecorded: PropTypes.bool.isRequired,
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,
2016-04-29 03:02:51 +08:00
};
2017-05-03 23:06:28 +08:00
const openBreakoutJoinConfirmation = (breakoutURL, breakoutName, mountModal) =>
mountModal(<BreakoutJoinConfirmation
2017-06-03 03:25:02 +08:00
breakoutURL={breakoutURL}
breakoutName={breakoutName}
/>);
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);
}
componendDidMount() {
2016-11-25 03:22:04 +08:00
document.title = this.props.presentationTitle;
}
handleToggleUserList() {
2016-07-21 22:24:50 +08:00
this.props.toggleUserList();
2016-04-29 03:02:51 +08:00
}
2016-11-14 19:57:10 +08:00
inviteUserToBreakout(breakout, breakoutURL) {
2017-05-03 23:06:28 +08:00
const {
mountModal,
} = this.props;
2016-11-14 19:57:10 +08:00
this.setState({ didSendBreakoutInvite: true }, () => {
2017-05-03 23:06:28 +08:00
openBreakoutJoinConfirmation.call(this, breakoutURL, breakout.name, mountModal);
2016-11-14 19:57:10 +08:00
});
}
2016-04-29 03:02:51 +08:00
render() {
const { hasUnreadMessages, beingRecorded, isExpanded, intl } = this.props;
2016-06-18 06:15:11 +08:00
2017-06-03 03:25:02 +08:00
const toggleBtnClasses = {};
toggleBtnClasses[styles.btn] = true;
toggleBtnClasses[styles.btnWithNotificationDot] = hasUnreadMessages;
2016-04-29 03:02:51 +08:00
return (
2016-05-21 00:29:55 +08:00
<div className={styles.navbar}>
<div className={styles.left}>
<Button
onClick={this.handleToggleUserList}
2017-06-03 03:25:02 +08:00
ghost
circle
hideLabel
label={intl.formatMessage(intlMessages.toggleUserListLabel)}
icon={'user'}
className={cx(toggleBtnClasses)}
2017-03-28 02:10:24 +08:00
aria-expanded={isExpanded}
aria-describedby="newMessage"
/>
<div
id="newMessage"
2017-06-03 03:25:02 +08:00
aria-label={hasUnreadMessages ? intl.formatMessage(intlMessages.newMessages) : null}
/>
2016-05-21 00:29:55 +08:00
</div>
2017-03-15 23:24:57 +08:00
<div className={styles.center} role="banner">
{this.renderPresentationTitle()}
2017-06-03 03:25:02 +08:00
<RecordingIndicator beingRecorded={beingRecorded} />
2016-05-21 00:29:55 +08:00
</div>
<div className={styles.right}>
2017-02-14 00:21:53 +08:00
<SettingsDropdownContainer />
2016-05-21 00:29:55 +08:00
</div>
2016-04-29 03:02:51 +08:00
</div>
);
}
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>
);
}
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>
{breakouts.map(breakout => this.renderBreakoutItem(breakout))}
</DropdownList>
</DropdownContent>
</Dropdown>
);
}
2016-11-14 19:57:10 +08:00
componentDidUpdate() {
2016-11-29 03:48:02 +08:00
const {
breakouts,
getBreakoutJoinURL,
isBreakoutRoom,
2016-11-29 03:48:02 +08:00
} = this.props;
2017-06-03 03:25:02 +08:00
breakouts.forEach((breakout) => {
2016-11-14 19:57:10 +08:00
if (!breakout.users) {
return;
}
2016-11-29 03:48:02 +08:00
const breakoutURL = getBreakoutJoinURL(breakout);
if (!this.state.didSendBreakoutInvite && !isBreakoutRoom) {
2016-11-14 19:57:10 +08:00
this.inviteUserToBreakout(breakout, breakoutURL);
}
});
if (!breakouts.length && this.state.didSendBreakoutInvite) {
this.setState({ didSendBreakoutInvite: false });
}
}
renderBreakoutItem(breakout) {
2016-11-29 03:48:02 +08:00
const {
getBreakoutJoinURL,
2017-05-03 23:06:28 +08:00
mountModal,
2016-11-29 03:48:02 +08:00
} = this.props;
const breakoutName = breakout.name;
2016-11-29 03:48:02 +08:00
const breakoutURL = getBreakoutJoinURL(breakout);
return (
<DropdownListItem
className={styles.actionsHeader}
key={_.uniqueId('action-header')}
label={breakoutName}
2017-05-03 23:06:28 +08:00
onClick={openBreakoutJoinConfirmation.bind(this, breakoutURL, breakoutName, mountModal)}
2016-12-09 00:20:47 +08:00
/>
);
}
2016-04-29 03:02:51 +08:00
}
NavBar.propTypes = propTypes;
NavBar.defaultProps = defaultProps;
2017-05-03 23:06:28 +08:00
export default withModalMounter(injectIntl(NavBar));