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

79 lines
2.7 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';
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';
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';
2023-12-09 04:24:57 +08:00
import { POLL_PUBLISH_RESULT, POLL_CANCEL } from './mutations';
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-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-09 02:29:05 +08:00
const publishPoll = (pollId) => {
pollPublishResult({
variables: {
pollId,
},
});
};
2021-11-24 00:43:49 +08:00
return (
<Poll
2023-12-09 04:24:57 +08:00
{...{ layoutContextDispatch, sidebarContentPanel, publishPoll, stopPoll, ...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
2023-10-11 20:10:02 +08:00
export default withTracker(({ amIPresenter, currentSlideId }) => {
2022-06-22 04:40:48 +08:00
const isPollSecret = Session.get('secretPoll') || false;
2022-06-22 21:17:59 +08:00
Meteor.subscribe('current-poll', isPollSecret, amIPresenter);
const pollId = currentSlideId || 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
return {
2022-06-22 04:40:48 +08:00
isPollSecret,
currentSlideId,
pollTypes,
2018-09-24 06:20:20 +08:00
startPoll,
startCustomPoll,
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);