Enable empty poll removal by deleting one of its options

Previously, the user had to click on the "poll" icon at the bottom of
the compose form in order to remove a poll. This commit changes how poll
options behave so as to enable an empty poll to be removed through the
deletion of either one of its options.

This closes #317.
This commit is contained in:
Bárbara de Castro Fernandes 2020-09-07 15:39:44 -03:00
parent 106e4006e5
commit 458bdef633
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);