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 CaptionsContainer from '/imports/ui/components/captions/pad/container'; import WaitingUsersPanel from '/imports/ui/components/waiting-users/container'; import { defineMessages, injectIntl } from 'react-intl'; import Resizable from 're-resizable'; import { styles } from '/imports/ui/components/app/styles'; import _ from 'lodash'; import { withLayoutConsumer } from '/imports/ui/components/layout/context'; import { USERLIST_MIN_WIDTH, USERLIST_MAX_WIDTH, CHAT_MIN_WIDTH, CHAT_MAX_WIDTH, } from '/imports/ui/components/layout/layout-manager'; 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', }, captionsLabel: { id: 'app.captions.label', description: 'Aria-label for Captions 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, }; const DEFAULT_PANEL_WIDTH = 340; // Variables for resizing user-list. const USERLIST_MIN_WIDTH_PX = USERLIST_MIN_WIDTH; const USERLIST_MAX_WIDTH_PX = USERLIST_MAX_WIDTH; // Variables for resizing poll. const POLL_MIN_WIDTH = 320; const POLL_MAX_WIDTH = 400; // Variables for resizing shared notes. const NOTE_MIN_WIDTH = DEFAULT_PANEL_WIDTH; const NOTE_MAX_WIDTH = 800; // Variables for resizing captions. const CAPTIONS_MIN_WIDTH = DEFAULT_PANEL_WIDTH; const CAPTIONS_MAX_WIDTH = 400; // Variables for resizing waiting users. const WAITING_MIN_WIDTH = DEFAULT_PANEL_WIDTH; const WAITING_MAX_WIDTH = 800; class PanelManager extends Component { constructor(props) { super(props); 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.captionsKey = _.uniqueId('captions-'); this.waitingUsers = _.uniqueId('waitingUsers-'); const { layoutContextState } = props; const { userListSize, chatSize } = layoutContextState; this.state = { chatWidth: chatSize.width, pollWidth: DEFAULT_PANEL_WIDTH, userlistWidth: userListSize.width, noteWidth: DEFAULT_PANEL_WIDTH, captionsWidth: DEFAULT_PANEL_WIDTH, waitingWidth: DEFAULT_PANEL_WIDTH, }; this.setUserListWidth = this.setUserListWidth.bind(this); } shouldComponentUpdate(prevProps) { const { layoutContextState } = this.props; const { layoutContextState: prevLayoutContextState } = prevProps; const { userListSize, chatSize } = layoutContextState; const { userListSize: prevUserListSize, chatSize: prevChatSize } = prevLayoutContextState; if ((layoutContextState !== prevLayoutContextState) && (userListSize.width === prevUserListSize.width && chatSize.width === prevChatSize.width)) return false; return true; } componentDidUpdate(prevProps) { const { chatWidth, userlistWidth } = this.state; const { layoutContextState } = this.props; const { userListSize, chatSize } = layoutContextState; const { layoutContextState: oldLayoutContextState } = prevProps; const { userListSize: oldUserListSize, chatSize: oldChatSize } = oldLayoutContextState; if (userListSize.width !== oldUserListSize.width && userListSize.width !== userlistWidth) { this.setUserListWidth(userListSize.width); } if (chatSize.width !== oldChatSize.width && chatSize.width !== chatWidth) { this.setChatWidth(chatSize.width); } } setUserListWidth(userlistWidth) { this.setState({ userlistWidth }); } setChatWidth(chatWidth) { this.setState({ chatWidth }); } userListResizeStop(addvalue) { const { userlistWidth } = this.state; const { layoutContextDispatch } = this.props; this.setState({ userlistWidth: userlistWidth + addvalue, }); layoutContextDispatch( { type: 'setUserListSize', value: { width: userlistWidth + addvalue, }, }, ); window.dispatchEvent(new Event('userListResizeChanged')); } chatResizeStop(addvalue) { const { chatWidth } = this.state; const { layoutContextDispatch } = this.props; this.setState({ chatWidth: chatWidth + addvalue, }); layoutContextDispatch( { type: 'setChatSize', value: { width: chatWidth + addvalue, }, }, ); window.dispatchEvent(new Event('chatResizeChanged')); } renderUserList() { const { intl, enableResize, openPanel, shouldAriaHide, } = this.props; const ariaHidden = shouldAriaHide() && openPanel !== 'userlist'; return (