bigbluebutton-Github/bigbluebutton-html5/imports/ui/components/polling/component.jsx

102 lines
3.1 KiB
React
Raw Normal View History

2018-10-24 22:17:13 +08:00
import React, { Component } from 'react';
import PropTypes from 'prop-types';
2016-06-30 06:00:06 +08:00
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 Tooltip from '/imports/ui/components/tooltip/component';
2018-01-08 14:17:18 +08:00
import { styles } from './styles.scss';
2016-05-06 02:50:18 +08:00
2017-04-25 10:08:18 +08:00
const intlMessages = defineMessages({
pollingTitleLabel: {
id: 'app.polling.pollingTitle',
},
pollAnswerLabel: {
id: 'app.polling.pollAnswerLabel',
},
pollAnswerDesc: {
id: 'app.polling.pollAnswerDesc',
2017-04-25 10:08:18 +08:00
},
});
2018-10-24 22:17:13 +08:00
class Polling extends Component {
constructor(props) {
super(props);
2018-10-24 22:17:13 +08:00
this.play = this.play.bind(this);
}
componentDidMount() {
this.play();
}
play() {
this.alert = new Audio(`${Meteor.settings.public.app.basename}/resources/sounds/Poll.mp3`);
this.alert.play();
}
render() {
const { intl, poll, handleVote } = this.props;
return (
<div className={styles.overlay}>
<div className={styles.pollingContainer} role="alert">
<div className={styles.pollingTitle}>
{intl.formatMessage(intlMessages.pollingTitleLabel)}
</div>
<div className={styles.pollingAnswers}>
{poll.answers.map(pollAnswer => (
2018-10-24 22:17:13 +08:00
<div
key={pollAnswer.id}
className={styles.pollButtonWrapper}
2018-10-24 22:17:13 +08:00
>
<Tooltip
key={pollAnswer.id}
title={pollAnswer.key}
>
<Button
className={styles.pollingButton}
color="primary"
size="md"
label={pollAnswer.key}
key={pollAnswer.key}
onClick={() => handleVote(poll.pollId, pollAnswer)}
aria-labelledby={`pollAnswerLabel${pollAnswer.key}`}
aria-describedby={`pollAnswerDesc${pollAnswer.key}`}
/>
</Tooltip>
<div
className={styles.hidden}
id={`pollAnswerLabel${pollAnswer.key}`}
>
{intl.formatMessage(intlMessages.pollAnswerLabel, { 0: pollAnswer.key })}
</div>
<div
className={styles.hidden}
id={`pollAnswerDesc${pollAnswer.key}`}
>
{intl.formatMessage(intlMessages.pollAnswerDesc, { 0: pollAnswer.key })}
</div>
2018-10-24 22:17:13 +08:00
</div>
))}
</div>
2018-10-24 22:17:13 +08:00
</div>
</div>);
}
}
2017-04-25 10:08:18 +08:00
export default injectIntl(injectWbResizeEvent(Polling));
Polling.propTypes = {
intl: PropTypes.shape({
formatMessage: PropTypes.func.isRequired,
}).isRequired,
handleVote: PropTypes.func.isRequired,
poll: PropTypes.shape({
pollId: PropTypes.string.isRequired,
2018-03-13 00:29:22 +08:00
answers: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number.isRequired,
key: PropTypes.string.isRequired,
}).isRequired).isRequired,
}).isRequired,
};