Merge branch 'blank-poll-removal' into 'develop'

Enable empty poll removal by deleting one of its options

Closes #317

See merge request soapbox-pub/soapbox-fe!217
This commit is contained in:
Alex Gleason 2020-09-07 19:27:59 +00:00
commit 2583dc2e52
2 changed files with 13 additions and 4 deletions

View file

@ -38,6 +38,8 @@ class Option extends React.PureComponent {
onSuggestionSelected: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
maxChars: PropTypes.number.isRequired,
onRemovePoll: PropTypes.func.isRequired,
numOptions: PropTypes.number.isRequired,
};
handleOptionTitleChange = e => {
@ -45,10 +47,12 @@ class Option extends React.PureComponent {
};
handleOptionRemove = () => {
this.props.onRemove(this.props.index);
if (this.props.numOptions > 2)
this.props.onRemove(this.props.index);
else
this.props.onRemovePoll();
};
handleToggleMultiple = e => {
this.props.onToggleMultiple();
e.preventDefault();
@ -95,7 +99,7 @@ class Option extends React.PureComponent {
</label>
<div className='poll__cancel'>
<IconButton disabled={index <= 1} title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} />
<IconButton title={intl.formatMessage(messages.remove_option)} icon='times' onClick={this.handleOptionRemove} />
</div>
</li>
);
@ -156,6 +160,7 @@ class PollForm extends ImmutablePureComponent {
isPollMultiple={isMultiple}
onToggleMultiple={this.handleToggleMultiple}
maxChars={maxOptionChars}
numOptions={options.size}
{...other}
/>
))}

View file

@ -1,6 +1,6 @@
import { connect } from 'react-redux';
import PollForm from '../components/poll_form';
import { addPollOption, removePollOption, changePollOption, changePollSettings } from '../../../actions/compose';
import { addPollOption, removePollOption, changePollOption, changePollSettings, removePoll } from '../../../actions/compose';
import {
clearComposeSuggestions,
fetchComposeSuggestions,
@ -43,6 +43,10 @@ const mapDispatchToProps = dispatch => ({
dispatch(selectComposeSuggestion(position, token, accountId, path));
},
onRemovePoll() {
dispatch(removePoll());
},
});
export default connect(mapStateToProps, mapDispatchToProps)(PollForm);