bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/polling/container.jsx

61 lines
1.8 KiB
React
Raw Normal View History

2016-05-06 02:50:18 +08:00
import React from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
import { withTracker } from 'meteor/react-meteor-data';
2018-10-10 23:49:58 +08:00
import Users from '/imports/api/users';
import Auth from '/imports/ui/services/auth';
2017-10-06 20:50:01 +08:00
import PollingService from './service';
import PollService from '/imports/ui/components/poll/service';
import PollingComponent from './component';
2022-03-09 02:05:24 +08:00
import { isPollingEnabled } from '/imports/ui/services/features';
2016-05-06 02:50:18 +08:00
const propTypes = {
pollExists: PropTypes.bool.isRequired,
presentationIsFullscreen: PropTypes.bool.isRequired,
2017-10-06 20:50:01 +08:00
};
const PollingContainer = ({ pollExists, presentationIsFullscreen, ...props }) => {
const currentUser = Users.findOne({ userId: Auth.userID }, { fields: { presenter: 1 } });
2022-03-09 02:05:24 +08:00
const showPolling = pollExists && !currentUser.presenter && isPollingEnabled();
2019-07-02 22:54:37 +08:00
if (showPolling) {
if (presentationIsFullscreen) {
return createPortal(
<PollingComponent {...props} />,
document.getElementById('presentation-polling-placeholder'),
);
}
return (
<PollingComponent {...props} />
);
}
return null;
};
PollingContainer.propTypes = propTypes;
export default withTracker(() => {
const {
pollExists, handleVote, poll, handleTypedVote,
} = PollingService.mapPolls();
2021-11-27 00:30:56 +08:00
const { pollTypes } = PollService;
const presentationIsFullscreen = Session.get('presentationIsFullscreen');
2021-11-27 00:30:56 +08:00
2022-03-09 02:05:24 +08:00
if (poll && poll?.pollType) {
2021-11-27 00:30:56 +08:00
const isResponse = poll.pollType === pollTypes.Response;
Meteor.subscribe('polls', isResponse);
}
2019-05-23 02:00:44 +08:00
return ({
pollExists,
handleVote,
handleTypedVote,
2019-05-23 02:00:44 +08:00
poll,
pollAnswerIds: PollService.pollAnswerIds,
2021-11-27 00:30:56 +08:00
pollTypes,
isDefaultPoll: PollService.isDefaultPoll,
isMeteorConnected: Meteor.status().connected,
presentationIsFullscreen,
2019-05-23 02:00:44 +08:00
});
})(PollingContainer);