bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/panel-manager/component.jsx

277 lines
6.5 KiB
React
Raw Normal View History

2018-11-20 07:29:48 +08:00
import React, { Component } from 'react';
2018-12-18 23:15:51 +08:00
import PropTypes from 'prop-types';
2018-11-20 07:29:48 +08:00
import BreakoutRoomContainer from '/imports/ui/components/breakout-room/container';
import UserListContainer from '/imports/ui/components/user-list/container';
import ChatContainer from '/imports/ui/components/chat/container';
2018-12-13 04:10:27 +08:00
import NoteContainer from '/imports/ui/components/note/container';
2018-11-20 07:29:48 +08:00
import PollContainer from '/imports/ui/components/poll/container';
import { defineMessages, injectIntl } from 'react-intl';
import Resizable from 're-resizable';
import { styles } from '/imports/ui/components/app/styles';
import _ from 'lodash';
2018-11-20 07:29:48 +08:00
const intlMessages = defineMessages({
chatLabel: {
id: 'app.chat.label',
description: 'Aria-label for Chat Section',
},
2018-12-13 04:10:27 +08:00
noteLabel: {
id: 'app.note.label',
description: 'Aria-label for Note Section',
},
2018-11-20 07:29:48 +08:00
userListLabel: {
id: 'app.userList.label',
description: 'Aria-label for Userlist Nav',
},
});
2018-12-18 23:15:51 +08:00
const propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
enableResize: PropTypes.bool.isRequired,
openPanel: PropTypes.string.isRequired,
};
2018-12-19 09:33:19 +08:00
// Variables for resizing user-list.
const USERLIST_MIN_WIDTH_PX = 150;
const USERLIST_MAX_WIDTH_PX = 240;
// Variables for resizing chat.
const CHAT_MIN_WIDTH = 150;
const CHAT_MAX_WIDTH = 350;
// Variables for resizing shared notes.
const NOTE_MIN_WIDTH = 340;
2018-12-13 04:10:27 +08:00
const NOTE_MAX_WIDTH = 800;
2018-11-20 07:29:48 +08:00
class PanelManager extends Component {
constructor() {
super();
this.padKey = _.uniqueId('resize-pad-');
this.userlistKey = _.uniqueId('userlist-');
this.breakoutroomKey = _.uniqueId('breakoutroom-');
this.chatKey = _.uniqueId('chat-');
this.pollKey = _.uniqueId('poll-');
2018-12-13 04:10:27 +08:00
this.noteKey = _.uniqueId('note-');
2018-12-19 09:33:19 +08:00
this.state = {
chatWidth: 340,
userlistWidth: 180,
noteWidth: NOTE_MIN_WIDTH,
2018-12-19 09:33:19 +08:00
};
2018-11-20 07:29:48 +08:00
}
renderUserList() {
const {
intl,
enableResize,
2018-11-20 07:29:48 +08:00
} = this.props;
return (
<div
className={styles.userList}
2018-11-20 07:29:48 +08:00
aria-label={intl.formatMessage(intlMessages.userListLabel)}
key={enableResize ? null : this.userlistKey}
2018-11-20 07:29:48 +08:00
>
<UserListContainer />
</div>
);
}
renderUserListResizable() {
2018-12-19 09:33:19 +08:00
const { userlistWidth } = this.state;
2018-11-20 07:29:48 +08:00
const resizableEnableOptions = {
top: false,
right: true,
bottom: false,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
};
return (
<Resizable
minWidth={USERLIST_MIN_WIDTH_PX}
maxWidth={USERLIST_MAX_WIDTH_PX}
ref={(node) => { this.resizableUserList = node; }}
enable={resizableEnableOptions}
key={this.userlistKey}
2018-12-19 09:33:19 +08:00
size={{ width: userlistWidth }}
onResizeStop={(e, direction, ref, d) => {
this.setState({
userlistWidth: userlistWidth + d.width,
});
}}
2018-11-20 07:29:48 +08:00
>
{this.renderUserList()}
</Resizable>
);
}
renderChat() {
const { intl, enableResize } = this.props;
2018-11-20 07:29:48 +08:00
return (
<section
className={styles.chat}
aria-label={intl.formatMessage(intlMessages.chatLabel)}
key={enableResize ? null : this.chatKey}
2018-11-20 07:29:48 +08:00
>
<ChatContainer />
</section>
);
}
renderChatResizable() {
2018-12-19 09:33:19 +08:00
const { chatWidth } = this.state;
2018-11-20 07:29:48 +08:00
const resizableEnableOptions = {
top: false,
right: true,
bottom: false,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
};
return (
<Resizable
minWidth={CHAT_MIN_WIDTH}
maxWidth={CHAT_MAX_WIDTH}
ref={(node) => { this.resizableChat = node; }}
enable={resizableEnableOptions}
key={this.chatKey}
2018-12-19 09:33:19 +08:00
size={{ width: chatWidth }}
onResizeStop={(e, direction, ref, d) => {
this.setState({
chatWidth: chatWidth + d.width,
});
}}
2018-11-20 07:29:48 +08:00
>
{this.renderChat()}
</Resizable>
);
}
2018-12-13 04:10:27 +08:00
renderNote() {
const { intl, enableResize } = this.props;
return (
<section
className={styles.note}
aria-label={intl.formatMessage(intlMessages.noteLabel)}
key={enableResize ? null : this.noteKey}
>
<NoteContainer />
</section>
);
}
renderNoteResizable() {
const { noteWidth } = this.state;
const resizableEnableOptions = {
top: false,
right: true,
bottom: false,
left: false,
topRight: false,
bottomRight: false,
bottomLeft: false,
topLeft: false,
};
return (
<Resizable
minWidth={NOTE_MIN_WIDTH}
maxWidth={NOTE_MAX_WIDTH}
ref={(node) => { this.resizableNote = node; }}
enable={resizableEnableOptions}
key={this.noteKey}
size={{ width: noteWidth }}
onResizeStop={(e, direction, ref, d) => {
this.setState({
noteWidth: noteWidth + d.width,
});
}}
>
{this.renderNote()}
</Resizable>
);
}
2018-11-20 07:29:48 +08:00
renderPoll() {
return (
<div className={styles.poll} key={this.pollKey}>
2018-11-20 07:29:48 +08:00
<PollContainer />
</div>
);
}
renderBreakoutRoom() {
return (
<div className={styles.breakoutRoom} key={this.breakoutroomKey}>
<BreakoutRoomContainer />
2018-11-20 07:29:48 +08:00
</div>
);
}
render() {
const { enableResize, openPanel } = this.props;
if (openPanel === '') return null;
const panels = [this.renderUserList()];
const resizablePanels = [
this.renderUserListResizable(),
<div className={styles.userlistPad} key={this.padKey} />,
];
if (openPanel === 'chat') {
2018-12-18 23:54:20 +08:00
if (enableResize) {
resizablePanels.push(this.renderChatResizable());
} else {
panels.push(this.renderChat());
}
2018-11-20 07:29:48 +08:00
}
2018-12-13 04:10:27 +08:00
if (openPanel === 'note') {
if (enableResize) {
resizablePanels.push(this.renderNoteResizable());
} else {
panels.push(this.renderNote());
}
}
if (openPanel === 'poll') {
2018-12-18 23:54:20 +08:00
if (enableResize) {
resizablePanels.push(this.renderPoll());
} else {
panels.push(this.renderPoll());
}
}
if (openPanel === 'breakoutroom') {
2018-12-18 23:54:20 +08:00
if (enableResize) {
resizablePanels.push(this.renderBreakoutRoom());
} else {
panels.push(this.renderBreakoutRoom());
}
}
return enableResize
? resizablePanels
: panels;
2018-11-20 07:29:48 +08:00
}
}
export default injectIntl(PanelManager);
2018-12-18 23:15:51 +08:00
PanelManager.propTypes = propTypes;