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';
|
2023-11-28 22:18:56 +08:00
|
|
|
import ChatContainer from '/imports/ui/components/chat/chat-graphql/component';
|
2024-05-01 20:39:03 +08:00
|
|
|
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';
|
2023-11-29 19:55:53 +08:00
|
|
|
import GuestUsersManagementPanel from '/imports/ui/components/waiting-users/waiting-users-graphql/component';
|
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,
|
|
|
|
};
|
|
|
|
|
|
|
|
const SidebarContent = (props) => {
|
|
|
|
const {
|
|
|
|
top,
|
2024-06-11 21:05:08 +08:00
|
|
|
left = null,
|
|
|
|
right = null,
|
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,
|
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,
|
2023-11-30 21:24:25 +08:00
|
|
|
amIModerator,
|
2021-05-18 04:25:07 +08:00
|
|
|
} = 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: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
|
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} />}
|
2023-11-29 19:55:53 +08:00
|
|
|
{sidebarContentPanel === PANELS.WAITING_USERS && <GuestUsersManagementPanel />}
|
2022-12-14 21:46:49 +08:00
|
|
|
{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}
|
|
|
|
/>
|
2022-12-14 21:46:49 +08:00
|
|
|
</Styled.Poll>
|
|
|
|
)}
|
2021-05-18 04:25:07 +08:00
|
|
|
</Resizable>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
SidebarContent.propTypes = propTypes;
|
|
|
|
export default SidebarContent;
|