import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { throttle } from 'lodash';
import { defineMessages, injectIntl, intlShape } from 'react-intl';
import Modal from 'react-modal';
import cx from 'classnames';
import Resizable from 're-resizable';
import browser from 'browser-detect';
import ToastContainer from '../toast/container';
import ModalContainer from '../modal/container';
import NotificationsBarContainer from '../notifications-bar/container';
import AudioContainer from '../audio/container';
import ChatAlertContainer from '../chat/alert/container';
import { styles } from './styles';
const MOBILE_MEDIA = 'only screen and (max-width: 40em)';
const USERLIST_COMPACT_WIDTH = 50;
const intlMessages = defineMessages({
userListLabel: {
id: 'app.userList.label',
description: 'Aria-label for Userlist Nav',
},
chatLabel: {
id: 'app.chat.label',
description: 'Aria-label for Chat Section',
},
mediaLabel: {
id: 'app.media.label',
description: 'Aria-label for Media Section',
},
actionsBarLabel: {
id: 'app.actionsBar.label',
description: 'Aria-label for ActionsBar Section',
},
});
const propTypes = {
fontSize: PropTypes.string,
navbar: PropTypes.element,
sidebar: PropTypes.element,
media: PropTypes.element,
actionsbar: PropTypes.element,
closedCaption: PropTypes.element,
userList: PropTypes.element,
chat: PropTypes.element,
locale: PropTypes.string,
intl: intlShape.isRequired,
};
const defaultProps = {
fontSize: '16px',
navbar: null,
sidebar: null,
media: null,
actionsbar: null,
closedCaption: null,
userList: null,
chat: null,
locale: 'en',
};
class App extends Component {
constructor() {
super();
this.state = {
compactUserList: false,
enableResize: !window.matchMedia(MOBILE_MEDIA).matches,
};
this.handleWindowResize = throttle(this.handleWindowResize).bind(this);
}
componentDidMount() {
const { locale } = this.props;
Modal.setAppElement('#app');
document.getElementsByTagName('html')[0].lang = locale;
document.getElementsByTagName('html')[0].style.fontSize = this.props.fontSize;
const BROWSER_RESULTS = browser();
const body = document.getElementsByTagName('body')[0];
if (BROWSER_RESULTS && BROWSER_RESULTS.name) {
body.classList.add(`browser-${BROWSER_RESULTS.name}`);
}
if (BROWSER_RESULTS && BROWSER_RESULTS.os) {
body.classList.add(`os-${BROWSER_RESULTS.os.split(' ').shift().toLowerCase()}`);
}
this.handleWindowResize();
window.addEventListener('resize', this.handleWindowResize, false);
}
componentWillUnmount() {
window.removeEventListener('resize', this.handleWindowResize, false);
}
handleWindowResize() {
const { enableResize } = this.state;
const shouldEnableResize = !window.matchMedia(MOBILE_MEDIA).matches;
if (enableResize === shouldEnableResize) return;
this.setState({ enableResize: shouldEnableResize });
}
renderNavBar() {
const { navbar } = this.props;
if (!navbar) return null;
return (