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';
|
2021-10-16 03:07:13 +08:00
|
|
|
import NotesContainer from '/imports/ui/components/notes/container';
|
2021-05-18 04:25:07 +08:00
|
|
|
import PollContainer from '/imports/ui/components/poll/container';
|
2021-10-16 03:07:13 +08:00
|
|
|
import CaptionsContainer from '/imports/ui/components/captions/container';
|
2021-05-18 04:25:07 +08:00
|
|
|
import BreakoutRoomContainer from '/imports/ui/components/breakout-room/container';
|
|
|
|
import WaitingUsersPanel from '/imports/ui/components/waiting-users/container';
|
2021-10-28 00:21:57 +08:00
|
|
|
import Styled from './styles';
|
2022-02-15 22:11:03 +08:00
|
|
|
import ErrorBoundary from '/imports/ui/components/common/error-boundary/component';
|
2022-02-15 22:29:38 +08:00
|
|
|
import FallbackView from '/imports/ui/components/common/fallback-errors/fallback-view/component';
|
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,
|
2021-06-29 21:31:44 +08:00
|
|
|
minHeight,
|
2021-05-18 04:25:07 +08:00
|
|
|
height,
|
2021-06-29 21:31:44 +08:00
|
|
|
maxHeight,
|
2021-05-18 04:25:07 +08:00
|
|
|
isResizable,
|
|
|
|
resizableEdge,
|
|
|
|
contextDispatch,
|
|
|
|
sidebarContentPanel,
|
|
|
|
} = props;
|
|
|
|
|
|
|
|
const [resizableWidth, setResizableWidth] = useState(width);
|
2021-06-29 21:31:44 +08:00
|
|
|
const [resizableHeight, setResizableHeight] = useState(height);
|
2021-05-18 04:25:07 +08:00
|
|
|
const [isResizing, setIsResizing] = useState(false);
|
|
|
|
const [resizeStartWidth, setResizeStartWidth] = useState(0);
|
2021-06-29 21:31:44 +08:00
|
|
|
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
|
|
|
|
2021-06-29 21:31:44 +08:00
|
|
|
useEffect(() => {
|
2021-06-29 21:39:12 +08:00
|
|
|
}, [resizeStartWidth, resizeStartHeight]);
|
2021-06-29 21:31:44 +08:00
|
|
|
|
2021-06-29 21:39:12 +08:00
|
|
|
const setSidebarContentSize = (dWidth, dHeight) => {
|
2021-05-18 04:25:07 +08:00
|
|
|
const newWidth = resizeStartWidth + dWidth;
|
2021-06-29 21:31:44 +08:00
|
|
|
const newHeight = resizeStartHeight + dHeight;
|
2021-05-18 04:25:07 +08:00
|
|
|
|
|
|
|
setResizableWidth(newWidth);
|
2021-06-29 21:31:44 +08:00
|
|
|
setResizableHeight(newHeight);
|
2021-05-18 04:25:07 +08:00
|
|
|
|
|
|
|
contextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_SIZE,
|
|
|
|
value: {
|
|
|
|
width: newWidth,
|
2021-06-29 21:31:44 +08:00
|
|
|
height: newHeight,
|
2021-05-18 04:25:07 +08:00
|
|
|
browserWidth: window.innerWidth,
|
|
|
|
browserHeight: window.innerHeight,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-10-02 04:12:55 +08:00
|
|
|
const smallSidebar = width < (maxWidth / 2);
|
2021-11-25 20:43:14 +08:00
|
|
|
const pollDisplay = sidebarContentPanel === PANELS.POLL ? 'inherit' : 'none';
|
2021-10-02 04:12:55 +08:00
|
|
|
|
2021-05-18 04:25:07 +08:00
|
|
|
return (
|
|
|
|
<Resizable
|
|
|
|
minWidth={minWidth}
|
|
|
|
maxWidth={maxWidth}
|
2021-06-29 21:31:44 +08:00
|
|
|
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);
|
2021-06-29 21:31:44 +08:00
|
|
|
setResizeStartHeight(resizableHeight);
|
2021-05-18 04:25:07 +08:00
|
|
|
}}
|
2021-06-29 21:31:44 +08:00
|
|
|
onResize={(...[, , , delta]) => setSidebarContentSize(delta.width, delta.height)}
|
2021-05-18 04:25:07 +08:00
|
|
|
onResizeStop={() => {
|
|
|
|
setIsResizing(false);
|
|
|
|
setResizeStartWidth(0);
|
2021-06-29 21:31:44 +08:00
|
|
|
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,
|
|
|
|
}}
|
2022-04-12 00:48:46 +08:00
|
|
|
handleStyles={{
|
|
|
|
left: { height: '100vh' },
|
|
|
|
right: { height: '100vh' },
|
|
|
|
}}
|
2021-05-18 04:25:07 +08:00
|
|
|
>
|
2022-01-19 02:27:54 +08:00
|
|
|
{sidebarContentPanel === PANELS.CHAT
|
|
|
|
&& (
|
|
|
|
<ErrorBoundary
|
|
|
|
Fallback={FallbackView}
|
|
|
|
>
|
|
|
|
<ChatContainer />
|
|
|
|
</ErrorBoundary>
|
|
|
|
)}
|
2021-10-16 03:07:13 +08:00
|
|
|
{sidebarContentPanel === PANELS.SHARED_NOTES && <NotesContainer />}
|
2021-05-18 04:25:07 +08:00
|
|
|
{sidebarContentPanel === PANELS.CAPTIONS && <CaptionsContainer />}
|
|
|
|
{sidebarContentPanel === PANELS.BREAKOUT && <BreakoutRoomContainer />}
|
|
|
|
{sidebarContentPanel === PANELS.WAITING_USERS && <WaitingUsersPanel />}
|
2021-11-25 20:43:14 +08:00
|
|
|
<Styled.Poll style={{ minWidth, top: '0', display: pollDisplay }} id="pollPanel">
|
|
|
|
<PollContainer smallSidebar={smallSidebar} />
|
|
|
|
</Styled.Poll>
|
2021-05-18 04:25:07 +08:00
|
|
|
</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;
|