2021-05-01 22:59:20 +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';
|
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';
|
2019-09-07 04:28:02 +08:00
|
|
|
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';
|
2022-01-22 03:20:21 +08:00
|
|
|
import { layoutDispatch, layoutSelectInput } from '../layout/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-05-01 22:59:20 +08:00
|
|
|
const PollContainer = ({ ...props }) => {
|
2021-09-11 04:48:52 +08:00
|
|
|
const layoutContextDispatch = layoutDispatch();
|
2022-01-22 03:20:21 +08:00
|
|
|
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
|
|
|
|
const { sidebarContentPanel } = sidebarContent;
|
2021-09-10 21:16:44 +08:00
|
|
|
|
2021-05-01 22:59:20 +08:00
|
|
|
const usingUsersContext = useContext(UsersContext);
|
|
|
|
const { users } = usingUsersContext;
|
2022-06-08 03:54:09 +08:00
|
|
|
|
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
|
2022-01-22 03:20:21 +08:00
|
|
|
{...{ layoutContextDispatch, sidebarContentPanel, ...props }}
|
2021-11-24 00:43:49 +08:00
|
|
|
usernames={usernames}
|
|
|
|
/>
|
|
|
|
);
|
2021-05-01 22:59:20 +08:00
|
|
|
};
|
2018-09-24 06:20:20 +08:00
|
|
|
|
2022-06-22 21:17:59 +08:00
|
|
|
export default withTracker(({ amIPresenter }) => {
|
2022-06-22 04:40:48 +08:00
|
|
|
const isPollSecret = Session.get('secretPoll') || false;
|
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
|
|
|
|
2022-06-22 21:17:59 +08:00
|
|
|
Meteor.subscribe('current-poll', isPollSecret, amIPresenter);
|
|
|
|
|
2021-06-09 21:49:59 +08:00
|
|
|
const currentSlide = PresentationService.getCurrentSlide(currentPresentation.podId);
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2020-07-20 22:34:46 +08:00
|
|
|
const pollId = currentSlide ? currentSlide.id : PUBLIC_CHAT_KEY;
|
|
|
|
|
2021-07-03 03:58:33 +08:00
|
|
|
const { pollTypes } = Service;
|
2020-07-20 22:34:46 +08:00
|
|
|
|
2021-09-17 20:12:43 +08:00
|
|
|
const startPoll = (type, secretPoll, question = '', isMultipleResponse) => makeCall('startPoll', pollTypes, type, pollId, secretPoll, question, isMultipleResponse);
|
2020-07-20 22:34:46 +08:00
|
|
|
|
2021-09-17 20:12:43 +08:00
|
|
|
const startCustomPoll = (type, secretPoll, question = '', isMultipleResponse, answers) => makeCall('startPoll', pollTypes, type, pollId, secretPoll, question, isMultipleResponse, 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 {
|
2022-06-22 04:40:48 +08:00
|
|
|
isPollSecret,
|
2018-09-24 06:20:20 +08:00
|
|
|
currentSlide,
|
2021-07-03 03:58:33 +08:00
|
|
|
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(),
|
2021-05-27 01:52:55 +08:00
|
|
|
isDefaultPoll: Service.isDefaultPoll,
|
|
|
|
checkPollType: Service.checkPollType,
|
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,
|
2022-04-29 04:18:35 +08:00
|
|
|
validateInput: Service.validateInput,
|
|
|
|
removeEmptyLineSpaces: Service.removeEmptyLineSpaces,
|
|
|
|
getSplittedQuestionAndOptions: Service.getSplittedQuestionAndOptions,
|
2018-09-24 06:20:20 +08:00
|
|
|
};
|
|
|
|
})(PollContainer);
|