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

167 lines
4.9 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/chat-graphql/component';
import NotesContainer from '/imports/ui/components/notes/component';
2021-05-18 04:25:07 +08:00
import PollContainer from '/imports/ui/components/poll/container';
2024-05-01 03:14:22 +08:00
import BreakoutRoomContainer from '../breakout-room/breakout-room/component';
2024-04-30 23:45:05 +08:00
import TimerContainer from '/imports/ui/components/timer/panel/component';
import GuestUsersManagementPanel from '/imports/ui/components/waiting-users/waiting-users-graphql/component';
2021-10-28 00:21:57 +08:00
import Styled from './styles';
import ErrorBoundary from '/imports/ui/components/common/error-boundary/component';
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,
minHeight,
2021-05-18 04:25:07 +08:00
height,
maxHeight,
2021-05-18 04:25:07 +08:00
isResizable,
resizableEdge,
contextDispatch,
sidebarContentPanel,
2022-06-22 21:17:59 +08:00
amIPresenter,
2023-02-01 01:52:17 +08:00
isSharedNotesPinned,
2023-10-11 20:10:02 +08:00
currentSlideId,
amIModerator,
2021-05-18 04:25:07 +08:00
} = 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
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);
const pollDisplay = sidebarContentPanel === PANELS.POLL ? 'inherit' : 'none';
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,
}}
handleStyles={{
left: { height: '100vh' },
right: { height: '100vh' },
}}
2021-05-18 04:25:07 +08:00
>
{sidebarContentPanel === PANELS.CHAT
2023-06-06 00:42:24 +08:00
&& (
<ErrorBoundary
Fallback={FallbackView}
>
<ChatContainer width={width} />
</ErrorBoundary>
)}
2023-02-01 01:52:17 +08:00
{!isSharedNotesPinned && (
<NotesContainer
isToSharedNotesBeShow={sidebarContentPanel === PANELS.SHARED_NOTES}
/>
)}
2021-05-18 04:25:07 +08:00
{sidebarContentPanel === PANELS.BREAKOUT && <BreakoutRoomContainer />}
2024-01-18 03:00:02 +08:00
{sidebarContentPanel === PANELS.TIMER && <TimerContainer isModerator={amIModerator} />}
{sidebarContentPanel === PANELS.WAITING_USERS && <GuestUsersManagementPanel />}
{sidebarContentPanel === PANELS.POLL && (
2023-06-06 00:42:24 +08:00
<Styled.Poll
style={{ minWidth, top: '0', display: pollDisplay }}
id="pollPanel"
>
2023-10-11 20:10:02 +08:00
<PollContainer
smallSidebar={smallSidebar}
amIPresenter={amIPresenter}
currentSlideId={currentSlideId}
/>
</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;