diff options
author | ThibG <thib@sitedethib.com> | 2019-04-22 14:56:14 +0200 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-04-22 14:56:14 +0200 |
commit | 0e78862b617bf5501b38d8ea7704fa53dd5912cf (patch) | |
tree | 95511c469103a04bccaa596323540af3c62285df | |
parent | d763d39d2628bef123cdc801b2a3a3922b7e37f2 (diff) |
Allow switching between singe-option and multiple-option polls (#10603)
-rw-r--r-- | app/javascript/mastodon/features/compose/components/poll_form.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/compose/components/poll_form.js b/app/javascript/mastodon/features/compose/components/poll_form.js index 4fb95f3c9..383e37eb6 100644 --- a/app/javascript/mastodon/features/compose/components/poll_form.js +++ b/app/javascript/mastodon/features/compose/components/poll_form.js @@ -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, }; @@ -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' @@ -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; @@ -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'> |