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

229 lines
7.0 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
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';
2021-11-05 02:11:42 +08:00
import Styled from './styles';
import RecordingIndicator from './recording-indicator/container';
import TalkingIndicatorContainer from '/imports/ui/components/nav-bar/talking-indicator/container';
import ConnectionStatusButton from '/imports/ui/components/connection-status/button/container';
import ConnectionStatusService from '/imports/ui/components/connection-status/service';
2018-02-23 01:30:12 +08:00
import SettingsDropdownContainer from './settings-dropdown/container';
import browserInfo from '/imports/utils/browserInfo';
import deviceInfo from '/imports/utils/deviceInfo';
import _ from "lodash";
import {alertScreenReader} from '/imports/utils/dom-utils';
2021-05-18 04:25:07 +08:00
import { PANELS, ACTIONS } from '../layout/enums';
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',
},
newMsgAria: {
id: 'app.navBar.toggleUserList.newMsgAria',
description: 'label for new message screen reader alert',
},
});
2016-04-29 03:02:51 +08:00
const propTypes = {
presentationTitle: PropTypes.string,
hasUnreadMessages: PropTypes.bool,
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,
shortcuts: '',
2016-04-29 03:02:51 +08:00
};
class NavBar extends Component {
2021-05-18 04:25:07 +08:00
constructor(props) {
super(props);
this.state = {
acs: props.activeChats,
}
2021-05-18 04:25:07 +08:00
this.handleToggleUserList = this.handleToggleUserList.bind(this);
2019-01-16 21:08:20 +08:00
}
2019-01-04 02:14:35 +08:00
componentDidMount() {
2019-01-09 06:17:11 +08:00
const {
shortcuts: TOGGLE_USERLIST_AK,
2019-01-09 06:17:11 +08:00
} = this.props;
const { isFirefox } = browserInfo;
const { isMacos } = deviceInfo;
// accessKey U does not work on firefox for macOS for some unknown reason
if (isMacos && isFirefox && TOGGLE_USERLIST_AK === 'U') {
document.addEventListener('keyup', (event) => {
const { key, code } = event;
const eventKey = key?.toUpperCase();
const eventCode = code;
if (event?.altKey && (eventKey === TOGGLE_USERLIST_AK || eventCode === `Key${TOGGLE_USERLIST_AK}`)) {
this.handleToggleUserList();
}
});
}
2019-01-04 02:14:35 +08:00
}
componentDidUpdate(prevProps, prevState) {
if (!_.isEqual(prevProps.activeChats, this.props.activeChats)) {
this.setState({ acs: this.props.activeChats})
}
}
2019-01-04 02:14:35 +08:00
componentWillUnmount() {
2019-01-04 05:09:00 +08:00
clearInterval(this.interval);
2019-01-04 02:14:35 +08:00
}
2021-05-18 04:25:07 +08:00
handleToggleUserList() {
const {
sidebarNavigation,
sidebarContent,
2021-08-05 19:03:24 +08:00
layoutContextDispatch,
2021-05-18 04:25:07 +08:00
} = this.props;
if (sidebarNavigation.isOpen) {
if (sidebarContent.isOpen) {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: false,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.NONE,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_ID_CHAT_OPEN,
value: '',
});
}
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN,
value: false,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_PANEL,
value: PANELS.NONE,
});
} else {
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_IS_OPEN,
value: true,
});
2021-08-05 19:03:24 +08:00
layoutContextDispatch({
2021-05-18 04:25:07 +08:00
type: ACTIONS.SET_SIDEBAR_NAVIGATION_PANEL,
value: PANELS.USERLIST,
});
}
}
2017-10-11 06:08:51 +08:00
render() {
2018-05-02 08:02:45 +08:00
const {
hasUnreadMessages,
hasUnreadNotes,
activeChats,
intl,
shortcuts: TOGGLE_USERLIST_AK,
2019-01-04 02:14:35 +08:00
mountModal,
presentationTitle,
2019-08-15 04:49:16 +08:00
amIModerator,
2021-05-18 04:25:07 +08:00
style,
main,
sidebarNavigation,
2018-05-02 08:02:45 +08:00
} = this.props;
2017-10-11 06:08:51 +08:00
const hasNotification = hasUnreadMessages || hasUnreadNotes;
2017-10-11 06:08:51 +08:00
let ariaLabel = intl.formatMessage(intlMessages.toggleUserListAria);
ariaLabel += hasNotification ? (` ${intl.formatMessage(intlMessages.newMessages)}`) : '';
2021-05-18 04:25:07 +08:00
const isExpanded = sidebarNavigation.isOpen;
const { acs } = this.state;
activeChats.map((c, i) => {
if (c?.unreadCounter > 0 && c?.unreadCounter !== acs[i]?.unreadCounter) {
alertScreenReader(`${intl.formatMessage(intlMessages.newMsgAria, { 0: c.name })}`)
}
});
2017-10-11 06:08:51 +08:00
return (
2021-11-05 02:11:42 +08:00
<Styled.Navbar
2021-05-18 04:25:07 +08:00
style={
main === 'new'
? {
position: 'absolute',
top: style.top,
left: style.left,
height: style.height,
width: style.width,
}
: {
position: 'relative',
height: style.height,
width: '100%',
}
}
>
2021-11-05 02:11:42 +08:00
<Styled.Top>
<Styled.Left>
2021-11-05 01:30:47 +08:00
{isExpanded && document.dir === 'ltr'
2021-12-10 22:55:37 +08:00
&& <Styled.ArrowLeft iconName="left_arrow" />}
2021-11-05 01:30:47 +08:00
{!isExpanded && document.dir === 'rtl'
2021-12-10 22:55:37 +08:00
&& <Styled.ArrowLeft iconName="left_arrow" />}
<Styled.NavbarToggleButton
2021-05-18 04:25:07 +08:00
onClick={this.handleToggleUserList}
ghost
circle
hideLabel
data-test={hasNotification ? 'hasUnreadMessages' : null}
2021-08-27 21:49:20 +08:00
label={intl.formatMessage(intlMessages.toggleUserListLabel)}
tooltipLabel={intl.formatMessage(intlMessages.toggleUserListLabel)}
aria-label={ariaLabel}
icon="user"
aria-expanded={isExpanded}
accessKey={TOGGLE_USERLIST_AK}
2021-11-05 02:11:42 +08:00
hasNotification={hasNotification}
/>
2021-12-10 22:55:37 +08:00
{!isExpanded && document.dir === 'ltr'
&& <Styled.ArrowRight iconName="right_arrow" />}
{isExpanded && document.dir === 'rtl'
&& <Styled.ArrowRight iconName="right_arrow" />}
2021-11-05 02:11:42 +08:00
</Styled.Left>
<Styled.Center>
<Styled.PresentationTitle>{presentationTitle}</Styled.PresentationTitle>
<RecordingIndicator
mountModal={mountModal}
amIModerator={amIModerator}
/>
2021-11-05 02:11:42 +08:00
</Styled.Center>
<Styled.Right>
{ConnectionStatusService.isEnabled() ? <ConnectionStatusButton /> : null}
<SettingsDropdownContainer amIModerator={amIModerator} />
2021-11-05 02:11:42 +08:00
</Styled.Right>
</Styled.Top>
<Styled.Bottom>
<TalkingIndicatorContainer amIModerator={amIModerator} />
2021-11-05 02:11:42 +08:00
</Styled.Bottom>
</Styled.Navbar>
2017-10-11 06:08:51 +08:00
);
}
2016-04-29 03:02:51 +08:00
}
NavBar.propTypes = propTypes;
NavBar.defaultProps = defaultProps;
export default withShortcutHelper(withModalMounter(injectIntl(NavBar)), 'toggleUserList');