2017-06-04 10:40:14 +08:00
|
|
|
import React, { Component } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-06-05 02:44:23 +08:00
|
|
|
import { throttle } from 'lodash';
|
2017-11-02 04:11:35 +08:00
|
|
|
import { defineMessages, injectIntl, intlShape } from 'react-intl';
|
2017-07-06 23:30:50 +08:00
|
|
|
import Modal from 'react-modal';
|
2017-09-22 22:24:24 +08:00
|
|
|
import cx from 'classnames';
|
2018-04-29 01:53:20 +08:00
|
|
|
import Resizable from 're-resizable';
|
2018-06-08 01:51:00 +08:00
|
|
|
import browser from 'browser-detect';
|
2017-10-13 02:53:33 +08:00
|
|
|
import ToastContainer from '../toast/container';
|
2017-04-19 03:06:51 +08:00
|
|
|
import ModalContainer from '../modal/container';
|
2016-08-10 00:28:16 +08:00
|
|
|
import NotificationsBarContainer from '../notifications-bar/container';
|
2017-03-28 04:40:44 +08:00
|
|
|
import AudioContainer from '../audio/container';
|
2018-08-10 01:02:18 +08:00
|
|
|
import ChatAlertContainer from '../chat/alert/container';
|
2018-01-08 14:17:18 +08:00
|
|
|
import { styles } from './styles';
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2018-06-05 02:44:23 +08:00
|
|
|
const MOBILE_MEDIA = 'only screen and (max-width: 40em)';
|
2018-06-05 03:11:11 +08:00
|
|
|
const USERLIST_COMPACT_WIDTH = 50;
|
2018-06-05 02:44:23 +08:00
|
|
|
|
2017-03-28 03:49:46 +08:00
|
|
|
const intlMessages = defineMessages({
|
|
|
|
userListLabel: {
|
2017-09-23 01:51:47 +08:00
|
|
|
id: 'app.userList.label',
|
2017-04-10 23:50:03 +08:00
|
|
|
description: 'Aria-label for Userlist Nav',
|
2017-03-28 03:49:46 +08:00
|
|
|
},
|
|
|
|
chatLabel: {
|
2017-09-23 01:23:25 +08:00
|
|
|
id: 'app.chat.label',
|
2017-04-19 03:42:55 +08:00
|
|
|
description: 'Aria-label for Chat Section',
|
2017-03-28 03:49:46 +08:00
|
|
|
},
|
|
|
|
mediaLabel: {
|
2017-08-11 00:05:51 +08:00
|
|
|
id: 'app.media.label',
|
2017-04-19 03:42:55 +08:00
|
|
|
description: 'Aria-label for Media Section',
|
2017-03-28 03:49:46 +08:00
|
|
|
},
|
2017-08-11 00:05:51 +08:00
|
|
|
actionsBarLabel: {
|
|
|
|
id: 'app.actionsBar.label',
|
2017-04-19 03:42:55 +08:00
|
|
|
description: 'Aria-label for ActionsBar Section',
|
2017-03-28 03:49:46 +08:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
const propTypes = {
|
2017-03-17 03:57:45 +08:00
|
|
|
fontSize: PropTypes.string,
|
2016-04-29 03:02:51 +08:00
|
|
|
navbar: PropTypes.element,
|
|
|
|
sidebar: PropTypes.element,
|
|
|
|
media: PropTypes.element,
|
|
|
|
actionsbar: PropTypes.element,
|
2017-10-26 07:11:06 +08:00
|
|
|
closedCaption: PropTypes.element,
|
|
|
|
userList: PropTypes.element,
|
|
|
|
chat: PropTypes.element,
|
2017-09-22 22:24:24 +08:00
|
|
|
locale: PropTypes.string,
|
2017-11-02 04:11:35 +08:00
|
|
|
intl: intlShape.isRequired,
|
2017-03-17 03:57:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
const defaultProps = {
|
|
|
|
fontSize: '16px',
|
2017-09-22 22:24:24 +08:00
|
|
|
navbar: null,
|
|
|
|
sidebar: null,
|
|
|
|
media: null,
|
|
|
|
actionsbar: null,
|
2017-10-26 07:11:06 +08:00
|
|
|
closedCaption: null,
|
|
|
|
userList: null,
|
|
|
|
chat: null,
|
2017-09-22 22:24:24 +08:00
|
|
|
locale: 'en',
|
2016-04-29 03:02:51 +08:00
|
|
|
};
|
|
|
|
|
2017-03-28 03:49:46 +08:00
|
|
|
class App extends Component {
|
2017-10-26 07:11:06 +08:00
|
|
|
constructor() {
|
|
|
|
super();
|
2017-03-10 03:50:21 +08:00
|
|
|
|
2016-09-15 01:48:50 +08:00
|
|
|
this.state = {
|
2018-06-05 02:44:23 +08:00
|
|
|
compactUserList: false,
|
|
|
|
enableResize: !window.matchMedia(MOBILE_MEDIA).matches,
|
2016-09-15 01:48:50 +08:00
|
|
|
};
|
2018-06-05 02:44:23 +08:00
|
|
|
|
|
|
|
this.handleWindowResize = throttle(this.handleWindowResize).bind(this);
|
2017-02-25 04:19:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2017-10-26 07:11:06 +08:00
|
|
|
const { locale } = this.props;
|
2017-07-04 22:32:22 +08:00
|
|
|
|
2017-07-06 23:30:50 +08:00
|
|
|
Modal.setAppElement('#app');
|
2017-07-04 22:32:22 +08:00
|
|
|
document.getElementsByTagName('html')[0].lang = locale;
|
2017-03-17 03:57:45 +08:00
|
|
|
document.getElementsByTagName('html')[0].style.fontSize = this.props.fontSize;
|
2018-06-05 02:44:23 +08:00
|
|
|
|
2018-06-08 01:51:00 +08:00
|
|
|
const BROWSER_RESULTS = browser();
|
|
|
|
const body = document.getElementsByTagName('body')[0];
|
2018-08-01 23:10:21 +08:00
|
|
|
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()}`);
|
|
|
|
}
|
2018-06-08 01:51:00 +08:00
|
|
|
|
2018-06-05 02:44:23 +08:00
|
|
|
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;
|
2018-06-08 01:51:00 +08:00
|
|
|
if (enableResize === shouldEnableResize) return;
|
2018-06-05 02:44:23 +08:00
|
|
|
|
|
|
|
this.setState({ enableResize: shouldEnableResize });
|
2016-09-15 01:48:50 +08:00
|
|
|
}
|
|
|
|
|
2018-09-15 01:50:18 +08:00
|
|
|
renderPoll() {
|
|
|
|
const { poll } = this.props;
|
|
|
|
|
|
|
|
if (!poll) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.poll}>
|
|
|
|
{poll}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-05-04 22:48:53 +08:00
|
|
|
renderNavBar() {
|
2016-04-29 03:02:51 +08:00
|
|
|
const { navbar } = this.props;
|
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
if (!navbar) return null;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
return (
|
|
|
|
<header className={styles.navbar}>
|
|
|
|
{navbar}
|
|
|
|
</header>
|
|
|
|
);
|
2016-04-29 03:02:51 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
renderSidebar() {
|
|
|
|
const { sidebar } = this.props;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
if (!sidebar) return null;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
return (
|
2017-05-16 05:45:44 +08:00
|
|
|
<aside className={styles.sidebar}>
|
2017-03-17 00:52:43 +08:00
|
|
|
{sidebar}
|
2017-05-16 05:45:44 +08:00
|
|
|
</aside>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderClosedCaption() {
|
|
|
|
const { closedCaption } = this.props;
|
|
|
|
|
|
|
|
if (!closedCaption) return null;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.closedCaptionBox}>
|
|
|
|
{closedCaption}
|
2017-05-13 03:17:08 +08:00
|
|
|
</div>
|
2017-03-17 00:52:43 +08:00
|
|
|
);
|
2016-04-29 03:02:51 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 04:40:46 +08:00
|
|
|
renderUserList() {
|
2018-04-24 09:53:27 +08:00
|
|
|
const { intl, chatIsOpen } = this.props;
|
2017-09-22 22:24:24 +08:00
|
|
|
let { userList } = this.props;
|
2016-09-15 01:48:50 +08:00
|
|
|
const { compactUserList } = this.state;
|
2016-08-25 02:56:06 +08:00
|
|
|
|
2017-09-22 22:24:24 +08:00
|
|
|
if (!userList) return null;
|
2017-03-17 03:57:45 +08:00
|
|
|
|
2017-06-03 03:25:02 +08:00
|
|
|
const userListStyle = {};
|
2016-09-15 01:48:50 +08:00
|
|
|
userListStyle[styles.compact] = compactUserList;
|
2017-03-17 03:57:45 +08:00
|
|
|
userList = React.cloneElement(userList, {
|
|
|
|
compact: compactUserList,
|
|
|
|
});
|
|
|
|
|
2018-06-05 02:44:23 +08:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
className={cx(styles.userList, userListStyle)}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.userListLabel)}
|
|
|
|
aria-hidden={chatIsOpen}
|
|
|
|
>
|
|
|
|
{userList}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderUserListResizable() {
|
2018-06-05 02:56:09 +08:00
|
|
|
const { userList } = this.props;
|
|
|
|
|
2018-06-07 00:12:43 +08:00
|
|
|
// Variables for resizing user-list.
|
|
|
|
const USERLIST_MIN_WIDTH_PX = 100;
|
|
|
|
const USERLIST_MAX_WIDTH_PX = 240;
|
|
|
|
const USERLIST_DEFAULT_WIDTH_RELATIVE = 18;
|
|
|
|
|
2018-06-09 03:00:13 +08:00
|
|
|
// decide whether using pixel or percentage unit as a default width for userList
|
2018-06-07 00:12:43 +08:00
|
|
|
const USERLIST_DEFAULT_WIDTH = (window.innerWidth * (USERLIST_DEFAULT_WIDTH_RELATIVE / 100.0)) < USERLIST_MAX_WIDTH_PX ? `${USERLIST_DEFAULT_WIDTH_RELATIVE}%` : USERLIST_MAX_WIDTH_PX;
|
|
|
|
|
2018-06-05 02:56:09 +08:00
|
|
|
if (!userList) return null;
|
|
|
|
|
2018-06-09 03:37:43 +08:00
|
|
|
const resizableEnableOptions = {
|
|
|
|
top: false,
|
|
|
|
right: true,
|
|
|
|
bottom: false,
|
|
|
|
left: false,
|
|
|
|
topRight: false,
|
|
|
|
bottomRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
topLeft: false,
|
|
|
|
};
|
|
|
|
|
2017-03-17 03:57:45 +08:00
|
|
|
return (
|
2018-04-29 01:53:20 +08:00
|
|
|
<Resizable
|
2018-06-06 03:08:49 +08:00
|
|
|
defaultSize={{ width: USERLIST_DEFAULT_WIDTH }}
|
2018-05-26 01:10:13 +08:00
|
|
|
minWidth={USERLIST_MIN_WIDTH_PX}
|
2018-05-25 03:02:47 +08:00
|
|
|
maxWidth={USERLIST_MAX_WIDTH_PX}
|
2018-04-29 09:59:45 +08:00
|
|
|
ref={(node) => { this.resizableUserList = node; }}
|
|
|
|
className={styles.resizableUserList}
|
2018-06-09 03:37:43 +08:00
|
|
|
enable={resizableEnableOptions}
|
2018-06-05 02:44:23 +08:00
|
|
|
onResize={(e, direction, ref) => {
|
2018-06-05 03:11:11 +08:00
|
|
|
const { compactUserList } = this.state;
|
2018-06-05 03:43:54 +08:00
|
|
|
const shouldBeCompact = ref.clientWidth <= USERLIST_COMPACT_WIDTH;
|
2018-06-05 03:11:11 +08:00
|
|
|
if (compactUserList === shouldBeCompact) return;
|
|
|
|
this.setState({ compactUserList: shouldBeCompact });
|
2018-04-30 05:23:50 +08:00
|
|
|
}}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
2018-06-05 02:44:23 +08:00
|
|
|
{this.renderUserList()}
|
2018-04-29 01:53:20 +08:00
|
|
|
</Resizable>
|
2017-03-17 03:57:45 +08:00
|
|
|
);
|
2016-05-04 04:40:46 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
renderChat() {
|
2017-03-28 03:49:46 +08:00
|
|
|
const { chat, intl } = this.props;
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
if (!chat) return null;
|
2016-05-04 04:40:46 +08:00
|
|
|
|
2018-06-05 02:44:23 +08:00
|
|
|
return (
|
|
|
|
<section
|
|
|
|
className={styles.chat}
|
|
|
|
aria-label={intl.formatMessage(intlMessages.chatLabel)}
|
|
|
|
>
|
|
|
|
{chat}
|
|
|
|
</section>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
renderChatResizable() {
|
|
|
|
const { chat } = this.props;
|
|
|
|
|
2018-06-07 00:12:43 +08:00
|
|
|
// Variables for resizing chat.
|
2018-09-19 05:25:59 +08:00
|
|
|
const CHAT_MIN_WIDTH = '10%';
|
|
|
|
const CHAT_MAX_WIDTH = '25%';
|
|
|
|
const CHAT_DEFAULT_WIDTH = '15%';
|
2018-06-07 00:12:43 +08:00
|
|
|
|
2018-06-05 02:44:23 +08:00
|
|
|
if (!chat) return null;
|
|
|
|
|
2018-06-09 03:37:43 +08:00
|
|
|
const resizableEnableOptions = {
|
|
|
|
top: false,
|
|
|
|
right: true,
|
|
|
|
bottom: false,
|
|
|
|
left: false,
|
|
|
|
topRight: false,
|
|
|
|
bottomRight: false,
|
|
|
|
bottomLeft: false,
|
|
|
|
topLeft: false,
|
|
|
|
};
|
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
return (
|
2018-04-29 01:53:20 +08:00
|
|
|
<Resizable
|
2018-06-06 03:08:49 +08:00
|
|
|
defaultSize={{ width: CHAT_DEFAULT_WIDTH }}
|
2018-09-19 05:25:59 +08:00
|
|
|
minWidth={CHAT_MIN_WIDTH}
|
|
|
|
maxWidth={CHAT_MAX_WIDTH}
|
2018-04-29 09:59:45 +08:00
|
|
|
ref={(node) => { this.resizableChat = node; }}
|
|
|
|
className={styles.resizableChat}
|
2018-06-09 03:37:43 +08:00
|
|
|
enable={resizableEnableOptions}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
2018-06-05 02:44:23 +08:00
|
|
|
{this.renderChat()}
|
2018-04-29 01:53:20 +08:00
|
|
|
</Resizable>
|
2017-03-17 00:52:43 +08:00
|
|
|
);
|
2016-05-04 04:40:46 +08:00
|
|
|
}
|
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
renderMedia() {
|
2018-04-29 09:59:45 +08:00
|
|
|
const {
|
|
|
|
media, intl, chatIsOpen, userlistIsOpen,
|
|
|
|
} = this.props;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
if (!media) return null;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
return (
|
2017-03-28 03:49:46 +08:00
|
|
|
<section
|
|
|
|
className={styles.media}
|
2017-06-03 03:25:02 +08:00
|
|
|
aria-label={intl.formatMessage(intlMessages.mediaLabel)}
|
2018-04-24 22:43:11 +08:00
|
|
|
aria-hidden={userlistIsOpen || chatIsOpen}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
|
|
|
{media}
|
|
|
|
{this.renderClosedCaption()}
|
2017-03-17 00:52:43 +08:00
|
|
|
</section>
|
|
|
|
);
|
2016-07-23 08:12:31 +08:00
|
|
|
}
|
|
|
|
|
2016-05-04 22:48:53 +08:00
|
|
|
renderActionsBar() {
|
2018-04-29 09:59:45 +08:00
|
|
|
const {
|
|
|
|
actionsbar, intl, userlistIsOpen, chatIsOpen,
|
|
|
|
} = this.props;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2017-03-17 00:52:43 +08:00
|
|
|
if (!actionsbar) return null;
|
2016-04-29 03:02:51 +08:00
|
|
|
|
2016-05-12 04:43:07 +08:00
|
|
|
return (
|
2017-03-28 03:49:46 +08:00
|
|
|
<section
|
|
|
|
className={styles.actionsbar}
|
2017-08-11 00:05:51 +08:00
|
|
|
aria-label={intl.formatMessage(intlMessages.actionsBarLabel)}
|
2018-04-24 22:43:11 +08:00
|
|
|
aria-hidden={userlistIsOpen || chatIsOpen}
|
2017-06-03 03:25:02 +08:00
|
|
|
>
|
|
|
|
{actionsbar}
|
2017-03-17 00:52:43 +08:00
|
|
|
</section>
|
2016-05-12 04:43:07 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2017-01-14 07:57:29 +08:00
|
|
|
render() {
|
2018-06-05 02:44:23 +08:00
|
|
|
const { params, userlistIsOpen } = this.props;
|
|
|
|
const { enableResize } = this.state;
|
2016-07-29 03:48:26 +08:00
|
|
|
|
2016-04-29 03:02:51 +08:00
|
|
|
return (
|
2016-05-03 06:42:54 +08:00
|
|
|
<main className={styles.main}>
|
2016-08-10 00:28:16 +08:00
|
|
|
<NotificationsBarContainer />
|
2016-05-03 06:42:54 +08:00
|
|
|
<section className={styles.wrapper}>
|
|
|
|
<div className={styles.content}>
|
2016-05-04 22:48:53 +08:00
|
|
|
{this.renderNavBar()}
|
2016-04-29 03:02:51 +08:00
|
|
|
{this.renderMedia()}
|
2016-05-04 22:48:53 +08:00
|
|
|
{this.renderActionsBar()}
|
2016-04-29 03:02:51 +08:00
|
|
|
</div>
|
2018-06-05 02:44:23 +08:00
|
|
|
{enableResize ? this.renderUserListResizable() : this.renderUserList()}
|
|
|
|
{userlistIsOpen && enableResize ? <div className={styles.userlistPad} /> : null}
|
|
|
|
{enableResize ? this.renderChatResizable() : this.renderChat()}
|
2018-09-15 01:50:18 +08:00
|
|
|
{this.renderPoll()}
|
2017-05-16 05:45:44 +08:00
|
|
|
{this.renderSidebar()}
|
2016-04-29 03:02:51 +08:00
|
|
|
</section>
|
2017-04-19 03:06:51 +08:00
|
|
|
<ModalContainer />
|
2017-03-28 04:40:44 +08:00
|
|
|
<AudioContainer />
|
2017-10-13 02:53:33 +08:00
|
|
|
<ToastContainer />
|
2018-08-10 01:02:18 +08:00
|
|
|
<ChatAlertContainer currentChatID={params.chatID} />
|
2016-04-29 03:02:51 +08:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
App.propTypes = propTypes;
|
2017-03-17 03:57:45 +08:00
|
|
|
App.defaultProps = defaultProps;
|
2018-06-05 03:11:11 +08:00
|
|
|
|
2017-03-28 03:49:46 +08:00
|
|
|
export default injectIntl(App);
|