migrate activateTimer action

This commit is contained in:
Ramón Souza 2024-01-16 11:19:11 -03:00
parent be8f4572da
commit 05225427a2
6 changed files with 41 additions and 49 deletions

View File

@ -1,5 +1,4 @@
import { Meteor } from 'meteor/meteor';
import activateTimer from './methods/activateTimer';
import deactivateTimer from './methods/deactivateTimer';
import resetTimer from './methods/resetTimer';
import startTimer from './methods/startTimer';
@ -11,7 +10,6 @@ import setTrack from './methods/setTrack';
import timerEnded from './methods/endTimer';
Meteor.methods({
activateTimer,
deactivateTimer,
resetTimer,
startTimer,

View File

@ -1,23 +0,0 @@
import { check } from 'meteor/check';
import RedisPubSub from '/imports/startup/server/redis';
import Logger from '/imports/startup/server/logger';
import { extractCredentials } from '/imports/api/common/server/helpers';
import { getInitialState } from '../helpers';
export default function activateTimer() {
const REDIS_CONFIG = Meteor.settings.private.redis;
const CHANNEL = REDIS_CONFIG.channels.toAkkaApps;
const EVENT_NAME = 'ActivateTimerReqMsg';
try {
const { meetingId, requesterUserId } = extractCredentials(this.userId);
check(meetingId, String);
check(requesterUserId, String);
const payload = getInitialState();
RedisPubSub.publishUserMessage(CHANNEL, EVENT_NAME, meetingId, requesterUserId, payload);
} catch (err) {
Logger.error(`Activating timer: ${err}`);
}
}

View File

@ -165,9 +165,9 @@ class ActionsDropdown extends PureComponent {
}
handleTimerClick() {
const { isTimerActive, layoutContextDispatch } = this.props;
const { isTimerActive, activateTimer } = this.props;
if (!isTimerActive) {
TimerService.activateTimer(layoutContextDispatch);
activateTimer();
} else {
TimerService.deactivateTimer();
}

View File

@ -2,7 +2,7 @@ import React, { useContext } from 'react';
import PresentationUploaderService from '/imports/ui/components/presentation/presentation-uploader/service';
import ActionsDropdown from './component';
import { layoutSelectInput, layoutDispatch, layoutSelect } from '../../layout/context';
import { SMALL_VIEWPORT_BREAKPOINT } from '../../layout/enums';
import { SMALL_VIEWPORT_BREAKPOINT, ACTIONS, PANELS } from '../../layout/enums';
import { isCameraAsContentEnabled, isTimerFeatureEnabled } from '/imports/ui/services/features';
import { PluginsContext } from '/imports/ui/components/components-data/plugin-context/context';
import { useSubscription, useMutation } from '@apollo/client';
@ -10,8 +10,12 @@ import {
PROCESSED_PRESENTATIONS_SUBSCRIPTION,
} from '/imports/ui/components/whiteboard/queries';
import { SET_PRESENTER } from '/imports/ui/core/graphql/mutations/userMutations';
import { TIMER_ACTIVATE } from '../../timer/mutations';
import Auth from '/imports/ui/services/auth';
const TIMER_CONFIG = Meteor.settings.public.timer;
const MILLI_IN_MINUTE = 60000;
const ActionsDropdownContainer = (props) => {
const sidebarContent = layoutSelectInput((i) => i.sidebarContent);
const sidebarNavigation = layoutSelectInput((i) => i.sidebarNavigation);
@ -29,11 +33,29 @@ const ActionsDropdownContainer = (props) => {
const presentations = presentationData?.pres_presentation || [];
const [setPresenter] = useMutation(SET_PRESENTER);
const [timerActivate] = useMutation(TIMER_ACTIVATE);
const handleTakePresenter = () => {
setPresenter({ variables: { userId: Auth.userID } });
};
const activateTimer = () => {
const stopwatch = true;
const running = false;
const time = TIMER_CONFIG.time * MILLI_IN_MINUTE;
timerActivate({ variables: { stopwatch, running, time } });
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.TIMER,
});
};
return (
<ActionsDropdown
{...{
@ -49,6 +71,7 @@ const ActionsDropdownContainer = (props) => {
setPresentation: PresentationUploaderService.setPresentation,
isCameraAsContentEnabled: isCameraAsContentEnabled(),
handleTakePresenter,
activateTimer,
...props,
}}
/>

View File

@ -0,0 +1,15 @@
import { gql } from '@apollo/client';
export const TIMER_ACTIVATE = gql`
mutation timerActivate($stopwatch: Boolean!, $running: Boolean!, $time: Int!) {
timerActivate(
stopwatch: $stopwatch,
running: $running,
time: $time
)
}
`;
export default {
TIMER_ACTIVATE,
};

View File

@ -91,26 +91,6 @@ const setTimer = (time) => makeCall('setTimer', time);
const resetTimer = () => makeCall('resetTimer');
const activateTimer = (layoutContextDispatch) => {
makeCall('activateTimer');
//Set an observer to switch to timer tab as soon as the timer is activated
const handle =Timer.find({ meetingId: Auth.meetingID }).observeChanges({
changed(id, timer) {
if (timer.active === true) {
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_IS_OPEN,
value: true,
});
layoutContextDispatch({
type: ACTIONS.SET_SIDEBAR_CONTENT_PANEL,
value: PANELS.TIMER,
});
}
handle.stop();
}
});
};
const deactivateTimer = () => makeCall('deactivateTimer');
const timerEnded = () => makeCall('timerEnded');
@ -323,7 +303,6 @@ export default {
setMinutes,
setSeconds,
resetTimer,
activateTimer,
deactivateTimer,
fetchTimeOffset,
setTrack,