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

78 lines
2.8 KiB
React
Raw Normal View History

2021-05-01 22:59:20 +08:00
import React, { useContext } from 'react';
import { makeCall } from '/imports/ui/services/api';
2018-09-24 06:20:20 +08:00
import { withTracker } from 'meteor/react-meteor-data';
import Presentations from '/imports/api/presentations';
2021-06-09 21:49:59 +08:00
import PresentationService from '/imports/ui/components/presentation/service';
2019-03-15 03:34:53 +08:00
import Poll from '/imports/ui/components/poll/component';
2021-05-18 04:25:07 +08:00
import { Session } from 'meteor/session';
import Service from './service';
2021-05-01 22:59:20 +08:00
import Auth from '/imports/ui/services/auth';
import { UsersContext } from '../components-data/users-context/context';
import { layoutDispatch, layoutSelectInput } from '../layout/context';
const CHAT_CONFIG = Meteor.settings.public.chat;
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_id;
2021-05-01 22:59:20 +08:00
const PollContainer = ({ ...props }) => {
2021-09-11 04:48:52 +08:00
const layoutContextDispatch = layoutDispatch();
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const { sidebarContentPanel } = sidebarContent;
2021-05-01 22:59:20 +08:00
const usingUsersContext = useContext(UsersContext);
const { users } = usingUsersContext;
2021-11-24 00:43:49 +08:00
const amIPresenter = users[Auth.meetingID][Auth.userID].presenter;
2021-05-01 22:59:20 +08:00
const isPollSecret = Session.get('secretPoll') || false;
Meteor.subscribe('current-poll', isPollSecret, amIPresenter);
2021-05-01 22:59:20 +08:00
const usernames = {};
Object.values(users[Auth.meetingID]).forEach((user) => {
usernames[user.userId] = { userId: user.userId, name: user.name };
});
2021-11-24 00:43:49 +08:00
return (
<Poll
{...{ layoutContextDispatch, sidebarContentPanel, ...props }}
2021-11-24 00:43:49 +08:00
usernames={usernames}
amIPresenter={amIPresenter}
/>
);
2021-05-01 22:59:20 +08:00
};
2018-09-24 06:20:20 +08:00
export default withTracker(() => {
const currentPresentation = Presentations.findOne({
current: true,
}, { fields: { podId: 1 } }) || {};
2021-06-09 21:49:59 +08:00
const currentSlide = PresentationService.getCurrentSlide(currentPresentation.podId);
const pollId = currentSlide ? currentSlide.id : PUBLIC_CHAT_KEY;
const { pollTypes } = Service;
const startPoll = (type, secretPoll, question = '', isMultipleResponse) => makeCall('startPoll', pollTypes, type, pollId, secretPoll, question, isMultipleResponse);
const startCustomPoll = (type, secretPoll, question = '', isMultipleResponse, answers) => makeCall('startPoll', pollTypes, type, pollId, secretPoll, question, isMultipleResponse, answers);
2018-09-24 06:20:20 +08:00
const stopPoll = () => makeCall('stopPoll');
2018-09-24 06:20:20 +08:00
return {
currentSlide,
pollTypes,
2018-09-24 06:20:20 +08:00
startPoll,
startCustomPoll,
stopPoll,
publishPoll: Service.publishPoll,
currentPoll: Service.currentPoll(),
isDefaultPoll: Service.isDefaultPoll,
checkPollType: Service.checkPollType,
resetPollPanel: Session.get('resetPollPanel') || false,
2019-05-23 02:00:44 +08:00
pollAnswerIds: Service.pollAnswerIds,
isMeteorConnected: Meteor.status().connected,
validateInput: Service.validateInput,
removeEmptyLineSpaces: Service.removeEmptyLineSpaces,
getSplittedQuestionAndOptions: Service.getSplittedQuestionAndOptions,
2018-09-24 06:20:20 +08:00
};
})(PollContainer);