Skip to content

Commit

Permalink
remove conditionally called hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
KDSBrowne committed Mar 27, 2024
1 parent f684b7d commit ef6fa49
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
23 changes: 11 additions & 12 deletions bigbluebutton-html5/imports/ui/components/whiteboard/component.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,6 @@ export default Whiteboard = React.memo(function Whiteboard(props) {

clearTldrawCache();

if (!currentPresentationPage) return null;

const [tlEditor, setTlEditor] = React.useState(null);
const [zoom, setZoom] = React.useState(HUNDRED_PERCENT);
const [isMounting, setIsMounting] = React.useState(true);
Expand Down Expand Up @@ -376,6 +374,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
const currPageNum = parseInt(curPageIdRef.current);
const shapeSelected = tlEditorRef.current.selectedShapes.length > 0;
const changeSlide = (direction) => {
if (!currentPresentationPage) return;
let newSlideNum = currPageNum + direction;
const outOfBounds = direction > 0
? newSlideNum > currentPresentationPage?.totalPages
Expand Down Expand Up @@ -612,24 +611,24 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
}, [fitToWidth, isPresenter]);

React.useEffect(() => {
if (currentPresentationPage.scaledViewBoxWidth && !initialViewBoxWidth) {
setInitialViewBoxWidth(currentPresentationPage.scaledViewBoxWidth);
if (currentPresentationPage && currentPresentationPage?.scaledViewBoxWidth && !initialViewBoxWidth) {
setInitialViewBoxWidth(currentPresentationPage?.scaledViewBoxWidth);
}

if (!isPresenter && tlEditorRef.current && initialViewBoxWidth) {
if (!isPresenter && tlEditorRef.current && initialViewBoxWidth && currentPresentationPage) {
const viewerFitToWidth = determineViewerFitToWidth(
currentPresentationPage
);

// Calculate the effective zoom based on the change in viewBoxWidth
const effectiveZoom = calculateEffectiveZoom(
initialViewBoxWidth,
currentPresentationPage.scaledViewBoxWidth
currentPresentationPage?.scaledViewBoxWidth
);

const zoomFitSlide = calculateZoomValue(
currentPresentationPage.scaledWidth,
currentPresentationPage.scaledHeight,
currentPresentationPage?.scaledWidth,
currentPresentationPage?.scaledHeight,
true
);
const zoomCamera = (zoomFitSlide * effectiveZoom) / HUNDRED_PERCENT;
Expand Down Expand Up @@ -903,13 +902,13 @@ export default Whiteboard = React.memo(function Whiteboard(props) {

const panned = prevCam.x !== nextCam.x || prevCam.y !== nextCam.y;

if (panned && isPresenter) {
if (panned && isPresenter && currentPresentationPage) {
let viewedRegionW = SlideCalcUtil.calcViewedRegionWidth(
editor?.viewportPageBounds.width,
editor?.viewportPageBounds?.width,
currentPresentationPage?.scaledWidth
);
let viewedRegionH = SlideCalcUtil.calcViewedRegionHeight(
editor?.viewportPageBounds.height,
editor?.viewportPageBounds?.height,
currentPresentationPage?.scaledHeight
);

Expand Down Expand Up @@ -1006,7 +1005,7 @@ export default Whiteboard = React.memo(function Whiteboard(props) {
next?.id?.includes("camera") &&
(prev.x !== next.x || prev.y !== next.y);
const zoomed = next?.id?.includes("camera") && prev.z !== next.z;
if (panned) {
if (panned && currentPresentationPage) {
// // limit bounds
if (
editor?.viewportPageBounds?.maxX >
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const useMouseEvents = ({ whiteboardRef, tlEditorRef, isWheelZoomRef, initialZoo
const handleMouseWheel = (event) => {
event.preventDefault();
event.stopPropagation();
if (!tlEditorRef.current || !isPresenter) {
if (!tlEditorRef.current || !isPresenter || !currentPresentationPage) {
return;
}

Expand Down

0 comments on commit ef6fa49

Please sign in to comment.