2021-05-01 22:59:20 +08:00
|
|
|
import React, { useContext } from 'react';
|
2018-09-24 06:20:20 +08:00
|
|
|
import { withTracker } from 'meteor/react-meteor-data';
|
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';
|
2023-12-09 02:29:05 +08:00
|
|
|
import { useMutation } from '@apollo/client';
|
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';
|
2022-01-22 03:20:21 +08:00
|
|
|
import { layoutDispatch, layoutSelectInput } from '../layout/context';
|
2023-12-11 21:31:13 +08:00
|
|
|
import { POLL_PUBLISH_RESULT, POLL_CANCEL, POLL_CREATE } from './mutations';
|
2024-01-11 21:37:53 +08:00
|
|
|
import PollCreationPanelContainer from './poll-graphql/component';
|
2024-02-15 22:40:26 +08:00
|
|
|
import { ACTIONS, PANELS } from '../layout/enums';
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2024-03-07 01:28:18 +08:00
|
|
|
const CHAT_CONFIG = window.meetingClientSettings.public.chat;
|
2024-03-15 20:30:55 +08:00
|
|
|
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_group_id;
|
2020-07-20 22:34:46 +08:00
|
|
|
|
2023-12-11 21:31:13 +08:00
|
|
|
const PollContainer = (props) => {
|
2021-09-11 04:48:52 +08:00
|
|
|
const layoutContextDispatch = layoutDispatch();
|
2024-02-15 22:40:26 +08:00
|
|
|
const handleChatFormsOpen = () => {
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
|
|
|
|
value: true,
|
|
|
|
});
|
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
|
|
|
|
value: PANELS.CHAT,
|
|
|
|
});
|
2024-02-21 21:18:27 +08:00
|
|
|
layoutContextDispatch({
|
|
|
|
type: ACTIONS.SET_ID_CHAT_OPEN,
|
|
|
|
value: PUBLIC_CHAT_KEY,
|
|
|
|
});
|
2024-02-15 22:40:26 +08:00
|
|
|
};
|
|
|
|
|
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
|
|
|
|
2024-04-09 23:04:14 +08:00
|
|
|
const users = [];
|
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 };
|
|
|
|
});
|
|
|
|
|
2023-12-09 02:29:05 +08:00
|
|
|
const [pollPublishResult] = useMutation(POLL_PUBLISH_RESULT);
|
2023-12-09 04:24:57 +08:00
|
|
|
const [stopPoll] = useMutation(POLL_CANCEL);
|
2023-12-11 21:31:13 +08:00
|
|
|
const [createPoll] = useMutation(POLL_CREATE);
|
|
|
|
|
|
|
|
const { currentSlideId } = props;
|
|
|
|
|
|
|
|
const startPoll = (pollType, secretPoll, question, isMultipleResponse, answers = []) => {
|
|
|
|
const pollId = currentSlideId || PUBLIC_CHAT_KEY;
|
|
|
|
|
|
|
|
createPoll({
|
|
|
|
variables: {
|
|
|
|
pollType,
|
|
|
|
pollId: `${pollId}/${new Date().getTime()}`,
|
|
|
|
secretPoll,
|
|
|
|
question,
|
|
|
|
isMultipleResponse,
|
|
|
|
answers,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
2023-12-09 02:29:05 +08:00
|
|
|
|
|
|
|
const publishPoll = (pollId) => {
|
|
|
|
pollPublishResult({
|
|
|
|
variables: {
|
|
|
|
pollId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2021-11-24 00:43:49 +08:00
|
|
|
return (
|
|
|
|
<Poll
|
2023-12-11 21:31:13 +08:00
|
|
|
{...{
|
|
|
|
layoutContextDispatch,
|
|
|
|
sidebarContentPanel,
|
|
|
|
publishPoll,
|
|
|
|
stopPoll,
|
|
|
|
startPoll,
|
2024-02-15 22:40:26 +08:00
|
|
|
handleChatFormsOpen,
|
2023-12-11 21:31:13 +08:00
|
|
|
...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
|
|
|
|
2024-01-11 21:37:53 +08:00
|
|
|
withTracker(({ amIPresenter, currentSlideId }) => {
|
2022-06-22 04:40:48 +08:00
|
|
|
const isPollSecret = Session.get('secretPoll') || false;
|
2018-09-24 06:57:03 +08:00
|
|
|
|
2022-06-22 21:17:59 +08:00
|
|
|
Meteor.subscribe('current-poll', isPollSecret, amIPresenter);
|
|
|
|
|
2021-07-03 03:58:33 +08:00
|
|
|
const { pollTypes } = Service;
|
2020-07-20 22:34:46 +08:00
|
|
|
|
2018-09-24 06:20:20 +08:00
|
|
|
return {
|
2022-06-22 04:40:48 +08:00
|
|
|
isPollSecret,
|
2023-10-10 03:10:02 +08:00
|
|
|
currentSlideId,
|
2021-07-03 03:58:33 +08:00
|
|
|
pollTypes,
|
2018-11-01 03:13:19 +08:00
|
|
|
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);
|
2024-01-11 21:37:53 +08:00
|
|
|
|
|
|
|
export default PollCreationPanelContainer;
|