import React, { Component } from 'react'; import PropTypes from 'prop-types'; 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'; import NoteContainer from '/imports/ui/components/note/container'; 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'; const intlMessages = defineMessages({ chatLabel: { id: 'app.chat.label', description: 'Aria-label for Chat Section', }, noteLabel: { id: 'app.note.label', description: 'Aria-label for Note Section', }, userListLabel: { id: 'app.userList.label', description: 'Aria-label for Userlist Nav', }, }); const propTypes = { intl: PropTypes.shape({ formatMessage: PropTypes.func.isRequired, }).isRequired, enableResize: PropTypes.bool.isRequired, openPanel: PropTypes.string.isRequired, }; // 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; const NOTE_MAX_WIDTH = 800; 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-'); this.noteKey = _.uniqueId('note-'); this.state = { chatWidth: 340, userlistWidth: 180, noteWidth: NOTE_MIN_WIDTH, }; } renderUserList() { const { intl, enableResize, } = this.props; return (
); } renderUserListResizable() { const { userlistWidth } = this.state; const resizableEnableOptions = { top: false, right: true, bottom: false, left: false, topRight: false, bottomRight: false, bottomLeft: false, topLeft: false, }; return ( { this.resizableUserList = node; }} enable={resizableEnableOptions} key={this.userlistKey} size={{ width: userlistWidth }} onResizeStop={(e, direction, ref, d) => { this.setState({ userlistWidth: userlistWidth + d.width, }); }} > {this.renderUserList()} ); } renderChat() { const { intl, enableResize } = this.props; return (
); } renderChatResizable() { const { chatWidth } = this.state; const resizableEnableOptions = { top: false, right: true, bottom: false, left: false, topRight: false, bottomRight: false, bottomLeft: false, topLeft: false, }; return ( { this.resizableChat = node; }} enable={resizableEnableOptions} key={this.chatKey} size={{ width: chatWidth }} onResizeStop={(e, direction, ref, d) => { this.setState({ chatWidth: chatWidth + d.width, }); }} > {this.renderChat()} ); } renderNote() { const { intl, enableResize } = this.props; return (
); } renderNoteResizable() { const { noteWidth } = this.state; const resizableEnableOptions = { top: false, right: true, bottom: false, left: false, topRight: false, bottomRight: false, bottomLeft: false, topLeft: false, }; return ( { this.resizableNote = node; }} enable={resizableEnableOptions} key={this.noteKey} size={{ width: noteWidth }} onResizeStop={(e, direction, ref, d) => { this.setState({ noteWidth: noteWidth + d.width, }); }} > {this.renderNote()} ); } renderPoll() { return (
); } renderBreakoutRoom() { return (
); } render() { const { enableResize, openPanel } = this.props; if (openPanel === '') return null; const panels = [this.renderUserList()]; const resizablePanels = [ this.renderUserListResizable(),
, ]; if (openPanel === 'chat') { if (enableResize) { resizablePanels.push(this.renderChatResizable()); } else { panels.push(this.renderChat()); } } if (openPanel === 'note') { if (enableResize) { resizablePanels.push(this.renderNoteResizable()); } else { panels.push(this.renderNote()); } } if (openPanel === 'poll') { if (enableResize) { resizablePanels.push(this.renderPoll()); } else { panels.push(this.renderPoll()); } } if (openPanel === 'breakoutroom') { if (enableResize) { resizablePanels.push(this.renderBreakoutRoom()); } else { panels.push(this.renderBreakoutRoom()); } } return enableResize ? resizablePanels : panels; } } export default injectIntl(PanelManager); PanelManager.propTypes = propTypes;