import React, { useContext } from 'react';
import PropTypes from 'prop-types';
import { useMutation } from '@apollo/client';
import FullscreenService from '/imports/ui/components/common/fullscreen-button/service';
import { useIsInfiniteWhiteboardEnabled, useIsPollingEnabled } from '/imports/ui/services/features';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
import { POLL_CANCEL, POLL_CREATE } from '/imports/ui/components/poll/mutations';
import { PRESENTATION_SET_ZOOM, PRESENTATION_SET_PAGE, PRESENTATION_SET_PAGE_INFINITE_WHITEBOARD } from '../mutations';
import PresentationToolbar from './component';
import Session from '/imports/ui/services/storage/in-memory';
import { useMeetingIsBreakout } from '/imports/ui/components/app/service';
const infiniteWhiteboardIcon = (isinfiniteWhiteboard) => {
if (isinfiniteWhiteboard) {
return (
);
}
return (
);
};
const PresentationToolbarContainer = (props) => {
const pluginsContext = useContext(PluginsContext);
const { pluginsExtensibleAreasAggregatedState } = pluginsContext;
const WHITEBOARD_CONFIG = window.meetingClientSettings.public.whiteboard;
const {
userIsPresenter,
layoutSwapped,
currentSlideNum,
presentationId,
numberOfSlides,
hasPoll,
currentSlide,
currentPresentationPage,
} = props;
const handleToggleFullScreen = (ref) => FullscreenService.toggleFullScreen(ref);
const [stopPoll] = useMutation(POLL_CANCEL);
const [createPoll] = useMutation(POLL_CREATE);
const [presentationSetZoom] = useMutation(PRESENTATION_SET_ZOOM);
const [presentationSetPage] = useMutation(PRESENTATION_SET_PAGE);
const [presentationSetPageInfiniteWhiteboard] = useMutation(PRESENTATION_SET_PAGE_INFINITE_WHITEBOARD);
const resetSlide = () => {
const { pageId, num } = currentPresentationPage;
presentationSetZoom({
variables: {
presentationId,
pageId,
pageNum: num,
xOffset: 0,
yOffset: 0,
widthRatio: 100,
heightRatio: 100,
},
});
};
const endCurrentPoll = () => {
if (hasPoll) stopPoll();
};
const setPresentationPage = (pageId) => {
presentationSetPage({
variables: {
presentationId,
pageId,
},
});
};
const setPresentationPageInfiniteWhiteboard = (infiniteWhiteboard) => {
const pageId = `${presentationId}/${currentSlideNum}`;
presentationSetPageInfiniteWhiteboard({
variables: {
pageId,
infiniteWhiteboard,
},
});
};
const skipToSlide = (slideNum) => {
const slideId = `${presentationId}/${slideNum}`;
setPresentationPage(slideId);
};
const previousSlide = () => {
const prevSlideNum = currentSlideNum - 1;
if (prevSlideNum < 1) {
return;
}
skipToSlide(prevSlideNum);
};
const nextSlide = () => {
const nextSlideNum = currentSlideNum + 1;
if (nextSlideNum > numberOfSlides) {
return;
}
skipToSlide(nextSlideNum);
};
const startPoll = (pollType, pollId, answers = [], question, isMultipleResponse = false) => {
Session.setItem('openPanel', 'poll');
Session.setItem('forcePollOpen', true);
window.dispatchEvent(new Event('panelChanged'));
createPoll({
variables: {
pollType,
pollId: `${pollId}/${new Date().getTime()}`,
secretPoll: false,
question,
isMultipleResponse,
answers,
},
});
};
const isPollingEnabled = useIsPollingEnabled();
const meetingIsBreakout = useMeetingIsBreakout();
const allowInfiniteWhiteboard = useIsInfiniteWhiteboardEnabled();
if (userIsPresenter && !layoutSwapped) {
// Only show controls if user is presenter and layout isn't swapped
const pluginProvidedPresentationToolbarItems = pluginsExtensibleAreasAggregatedState
?.presentationToolbarItems;
return (
);
}
return null;
};
export default PresentationToolbarContainer;
PresentationToolbarContainer.propTypes = {
// Number of current slide being displayed
currentSlideNum: PropTypes.number.isRequired,
// Total number of slides in this presentation
numberOfSlides: PropTypes.number.isRequired,
// Actions required for the presenter toolbar
layoutSwapped: PropTypes.bool,
};