2021-04-19 21:58:33 +08:00
|
|
|
import React, { useContext } from 'react';
|
2018-09-24 06:57:03 +08:00
|
|
|
import { makeCall } from '/imports/ui/services/api';
|
2018-09-24 06:20:20 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
2018-09-24 06:57:03 +08:00
|
|
|
import Presentations from '/imports/api/presentations';
|
|
|
|
import PresentationAreaService from '/imports/ui/components/presentation/service';
|
2019-03-15 03:34:53 +08:00
|
|
|
import Poll from '/imports/ui/components/poll/component';
|
2019-09-07 04:28:02 +08:00
|
|
|
import Service from './service';
|
2021-04-19 21:58:33 +08:00
|
|
|
import Auth from '/imports/ui/services/auth';
|
|
|
|
import { UsersContext } from '../components-data/users-context/context';
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2020-07-20 22:34:46 +08:00
|
|
|
const CHAT_CONFIG = Meteor.settings.public.chat;
|
|
|
|
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_id;
|
|
|
|
|
2021-04-19 21:58:33 +08:00
|
|
|
const PollContainer = ({ ...props }) => {
|
|
|
|
const usingUsersContext = useContext(UsersContext);
|
|
|
|
const { users } = usingUsersContext;
|
|
|
|
|
|
|
|
const usernames = {};
|
|
|
|
|
|
|
|
Object.values(users[Auth.meetingID]).forEach((user) => {
|
|
|
|
usernames[user.userId] = { userId: user.userId, name: user.name };
|
|
|
|
});
|
|
|
|
|
|
|
|
return <Poll {...props} usernames={usernames} />;
|
|
|
|
};
|
2018-09-24 06:20:20 +08:00
|
|
|
|
2019-03-09 04:46:25 +08:00
|
|
|
export default withTracker(() => {
|
2020-02-07 04:47:28 +08:00
|
|
|
Meteor.subscribe('current-poll');
|
2018-10-29 23:27:50 +08:00
|
|
|
|
2018-09-24 06:57:03 +08:00
|
|
|
const currentPresentation = Presentations.findOne({
|
|
|
|
current: true,
|
2019-08-22 20:05:06 +08:00
|
|
|
}, { fields: { podId: 1 } }) || {};
|
2018-09-24 06:57:03 +08:00
|
|
|
|
|
|
|
const currentSlide = PresentationAreaService.getCurrentSlide(currentPresentation.podId);
|
|
|
|
|
2020-07-20 22:34:46 +08:00
|
|
|
const pollId = currentSlide ? currentSlide.id : PUBLIC_CHAT_KEY;
|
|
|
|
|
2020-09-21 20:07:36 +08:00
|
|
|
const startPoll = (type, question = '') => makeCall('startPoll', type, pollId, question);
|
2020-07-20 22:34:46 +08:00
|
|
|
|
2020-09-21 20:07:36 +08:00
|
|
|
const startCustomPoll = (type, question = '', answers) => makeCall('startPoll', type, pollId, question, answers);
|
2018-09-24 06:20:20 +08:00
|
|
|
|
2020-07-20 22:34:46 +08:00
|
|
|
const stopPoll = () => makeCall('stopPoll');
|
2018-09-24 06:20:20 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
currentSlide,
|
2019-08-30 00:26:07 +08:00
|
|
|
amIPresenter: Service.amIPresenter(),
|
2018-11-01 03:13:19 +08:00
|
|
|
pollTypes: Service.pollTypes,
|
2018-09-24 06:20:20 +08:00
|
|
|
startPoll,
|
|
|
|
startCustomPoll,
|
2020-07-20 22:34:46 +08:00
|
|
|
stopPoll,
|
2018-11-01 03:13:19 +08:00
|
|
|
publishPoll: Service.publishPoll,
|
|
|
|
currentPoll: Service.currentPoll(),
|
2019-03-28 23:58:10 +08:00
|
|
|
resetPollPanel: Session.get('resetPollPanel') || false,
|
2019-05-23 02:00:44 +08:00
|
|
|
pollAnswerIds: Service.pollAnswerIds,
|
2019-06-28 00:46:14 +08:00
|
|
|
isMeteorConnected: Meteor.status().connected,
|
2018-09-24 06:20:20 +08:00
|
|
|
};
|
|
|
|
})(PollContainer);
|