Skip to content

Commit

Permalink
Allow switching between singe-option and multiple-option polls (masto…
Browse files Browse the repository at this point in the history
  • Loading branch information
ClearlyClaire authored and hiyuki2578 committed Oct 2, 2019
1 parent 7842aa9 commit 3196c5b
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions app/javascript/mastodon/features/compose/components/poll_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Option extends React.PureComponent {
isPollMultiple: PropTypes.bool,
onChange: PropTypes.func.isRequired,
onRemove: PropTypes.func.isRequired,
onToggleMultiple: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
};

Expand All @@ -37,13 +38,24 @@ class Option extends React.PureComponent {
this.props.onRemove(this.props.index);
};

handleToggleMultiple = e => {
this.props.onToggleMultiple();
e.preventDefault();
e.stopPropagation();
};

render () {
const { isPollMultiple, title, index, intl } = this.props;

return (
<li>
<label className='poll__text editable'>
<span className={classNames('poll__input', { checkbox: isPollMultiple })} />
<span
className={classNames('poll__input', { checkbox: isPollMultiple })}
onClick={this.handleToggleMultiple}
role='button'
tabIndex='0'
/>

<input
type='text'
Expand Down Expand Up @@ -86,6 +98,10 @@ class PollForm extends ImmutablePureComponent {
this.props.onChangeSettings(e.target.value, this.props.isMultiple);
};

handleToggleMultiple = () => {
this.props.onChangeSettings(this.props.expiresIn, !this.props.isMultiple);
};

render () {
const { options, expiresIn, isMultiple, onChangeOption, onRemoveOption, intl } = this.props;

Expand All @@ -96,7 +112,7 @@ class PollForm extends ImmutablePureComponent {
return (
<div className='compose-form__poll-wrapper'>
<ul>
{options.map((title, i) => <Option title={title} key={i} index={i} onChange={onChangeOption} onRemove={onRemoveOption} isPollMultiple={isMultiple} />)}
{options.map((title, i) => <Option title={title} key={i} index={i} onChange={onChangeOption} onRemove={onRemoveOption} isPollMultiple={isMultiple} onToggleMultiple={this.handleToggleMultiple} />)}
</ul>

<div className='poll__footer'>
Expand Down

0 comments on commit 3196c5b

Please sign in to comment.