import React, { Component } from 'react'; import PropTypes from 'prop-types'; import Button from '/imports/ui/components/button/component'; import injectWbResizeEvent from '/imports/ui/components/presentation/resize-wrapper/component'; import { defineMessages, injectIntl } from 'react-intl'; import cx from 'classnames'; import { styles } from './styles.scss'; import AudioService from '/imports/ui/components/audio/service'; import {Meteor} from "meteor/meteor"; const MAX_INPUT_CHARS = 45; const intlMessages = defineMessages({ pollingTitleLabel: { id: 'app.polling.pollingTitle', }, pollAnswerLabel: { id: 'app.polling.pollAnswerLabel', }, pollAnswerDesc: { id: 'app.polling.pollAnswerDesc', }, pollQestionTitle: { id: 'app.polling.pollQuestionTitle', }, submitLabel: { id: 'app.polling.submitLabel', }, submitAriaLabel: { id: 'app.polling.submitAriaLabel', }, responsePlaceholder: { id: 'app.polling.responsePlaceholder', }, }); const validateInput = (i) => { let _input = i; if (/^\s/.test(_input)) _input = ''; return _input; }; class Polling extends Component { constructor(props) { super(props); this.state = { typedAns: '', }; this.play = this.play.bind(this); this.handleUpdateResponseInput = this.handleUpdateResponseInput.bind(this); this.handleMessageKeyDown = this.handleMessageKeyDown.bind(this); } componentDidMount() { this.play(); } play() { AudioService.playAlertSound(`${Meteor.settings.public.app.cdn + Meteor.settings.public.app.basename + Meteor.settings.public.app.instanceId}` + '/resources/sounds/Poll.mp3'); } handleUpdateResponseInput(e) { this.responseInput.value = validateInput(e.target.value); this.setState({ typedAns: this.responseInput.value }); } handleMessageKeyDown(e) { const { poll, handleTypedVote, } = this.props; const { typedAns, } = this.state; if (e.keyCode === 13) { handleTypedVote(poll.pollId, typedAns); } } render() { const { isMeteorConnected, intl, poll, handleVote, handleTypedVote, pollAnswerIds, } = this.props; const { typedAns, } = this.state; if (!poll) return null; const { stackOptions, answers, question } = poll; const pollAnswerStyles = { [styles.pollingAnswers]: true, [styles.removeColumns]: answers.length === 1, [styles.stacked]: stackOptions, }; return (