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

115 lines
3.2 KiB
React
Raw Normal View History

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';
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-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';
const CHAT_CONFIG = window.meetingClientSettings.public.chat;
2024-03-15 20:30:55 +08:00
const PUBLIC_CHAT_KEY = CHAT_CONFIG.public_group_id;
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,
});
layoutContextDispatch({
type: ACTIONS.SET_ID_CHAT_OPEN,
value: PUBLIC_CHAT_KEY,
});
2024-02-15 22:40:26 +08:00
};
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-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;
2022-06-22 21:17:59 +08:00
Meteor.subscribe('current-poll', isPollSecret, amIPresenter);
const { pollTypes } = Service;
2018-09-24 06:20:20 +08:00
return {
2022-06-22 04:40:48 +08:00
isPollSecret,
currentSlideId,
pollTypes,
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);
2024-01-11 21:37:53 +08:00
export default PollCreationPanelContainer;