bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/sidebar-content/component.jsx

142 lines
4.1 KiB
React
Raw Normal View History

2021-05-18 04:25:07 +08:00
import React, { useState, useEffect } from 'react';
import PropTypes from 'prop-types';
import Resizable from 're-resizable';
import { ACTIONS, PANELS } from '../layout/enums';
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 BreakoutRoomContainer from '/imports/ui/components/breakout-room/container';
import WaitingUsersPanel from '/imports/ui/components/waiting-users/container';
2021-05-29 02:55:12 +08:00
import { styles } from '/imports/ui/components/app/styles';
2021-05-18 04:25:07 +08:00
const propTypes = {
top: PropTypes.number.isRequired,
2021-07-27 04:28:05 +08:00
left: PropTypes.number,
right: PropTypes.number,
2021-05-18 04:25:07 +08:00
zIndex: PropTypes.number.isRequired,
minWidth: PropTypes.number.isRequired,
width: PropTypes.number.isRequired,
maxWidth: PropTypes.number.isRequired,
height: PropTypes.number.isRequired,
isResizable: PropTypes.bool.isRequired,
resizableEdge: PropTypes.objectOf(PropTypes.bool).isRequired,
contextDispatch: PropTypes.func.isRequired,
};
2021-07-27 04:28:05 +08:00
const defaultProps = {
left: null,
right: null,
};
2021-05-18 04:25:07 +08:00
const SidebarContent = (props) => {
const {
top,
left,
2021-07-27 04:28:05 +08:00
right,
2021-05-18 04:25:07 +08:00
zIndex,
minWidth,
width,
maxWidth,
minHeight,
2021-05-18 04:25:07 +08:00
height,
maxHeight,
2021-05-18 04:25:07 +08:00
isResizable,
resizableEdge,
contextDispatch,
sidebarContentPanel,
} = props;
const [resizableWidth, setResizableWidth] = useState(width);
const [resizableHeight, setResizableHeight] = useState(height);
2021-05-18 04:25:07 +08:00
const [isResizing, setIsResizing] = useState(false);
const [resizeStartWidth, setResizeStartWidth] = useState(0);
const [resizeStartHeight, setResizeStartHeight] = useState(0);
2021-05-18 04:25:07 +08:00
useEffect(() => {
2021-06-29 21:39:12 +08:00
if (!isResizing) {
setResizableWidth(width);
setResizableHeight(height);
}
}, [width, height]);
2021-05-18 04:25:07 +08:00
useEffect(() => {
2021-06-29 21:39:12 +08:00
}, [resizeStartWidth, resizeStartHeight]);
2021-06-29 21:39:12 +08:00
const setSidebarContentSize = (dWidth, dHeight) => {
2021-05-18 04:25:07 +08:00
const newWidth = resizeStartWidth + dWidth;
const newHeight = resizeStartHeight + dHeight;
2021-05-18 04:25:07 +08:00
setResizableWidth(newWidth);
setResizableHeight(newHeight);
2021-05-18 04:25:07 +08:00
contextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_SIZE,
value: {
width: newWidth,
height: newHeight,
2021-05-18 04:25:07 +08:00
browserWidth: window.innerWidth,
browserHeight: window.innerHeight,
},
});
};
const smallSidebar = width < (maxWidth / 2);
2021-05-18 04:25:07 +08:00
return (
<Resizable
minWidth={minWidth}
maxWidth={maxWidth}
minHeight={minHeight}
maxHeight={maxHeight}
2021-05-18 04:25:07 +08:00
size={{
width,
height,
}}
enable={{
top: isResizable && resizableEdge.top,
left: isResizable && resizableEdge.left,
bottom: isResizable && resizableEdge.bottom,
right: isResizable && resizableEdge.right,
}}
handleWrapperClass="resizeSidebarContentWrapper"
onResizeStart={() => {
setIsResizing(true);
setResizeStartWidth(resizableWidth);
setResizeStartHeight(resizableHeight);
2021-05-18 04:25:07 +08:00
}}
onResize={(...[, , , delta]) => setSidebarContentSize(delta.width, delta.height)}
2021-05-18 04:25:07 +08:00
onResizeStop={() => {
setIsResizing(false);
setResizeStartWidth(0);
setResizeStartHeight(0);
2021-05-18 04:25:07 +08:00
}}
style={{
position: 'absolute',
top,
left,
2021-07-27 04:28:05 +08:00
right,
2021-05-18 04:25:07 +08:00
zIndex,
width,
height,
}}
>
{sidebarContentPanel === PANELS.CHAT && <ChatContainer />}
{sidebarContentPanel === PANELS.SHARED_NOTES && <NoteContainer />}
{sidebarContentPanel === PANELS.CAPTIONS && <CaptionsContainer />}
2021-05-29 02:55:12 +08:00
{sidebarContentPanel === PANELS.POLL
&& (
2021-06-18 02:38:05 +08:00
<div className={styles.poll} style={{ minWidth, top: '0' }} id="pollPanel">
<PollContainer smallSidebar={smallSidebar} />
2021-05-29 02:55:12 +08:00
</div>
)}
2021-05-18 04:25:07 +08:00
{sidebarContentPanel === PANELS.BREAKOUT && <BreakoutRoomContainer />}
{sidebarContentPanel === PANELS.WAITING_USERS && <WaitingUsersPanel />}
</Resizable>
);
};
SidebarContent.propTypes = propTypes;
2021-07-27 04:28:05 +08:00
SidebarContent.defaultProps = defaultProps;
2021-05-18 04:25:07 +08:00
export default SidebarContent;