Compose: Fix content retention on close, fixes #139

merge-requests/59/head
Alex Gleason 4 years ago
parent 346d84351c
commit e78d8d59b6
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -9,8 +9,18 @@ const messages = defineMessages({
confirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' },
});
const checkComposeContent = compose => {
return [
compose.get('text').length > 0,
compose.get('spoiler_text').length > 0,
compose.get('media_attachments').size > 0,
compose.get('in_reply_to') !== null,
compose.get('poll') !== null,
].some(check => check === true);
};
const mapStateToProps = state => ({
composeText: state.getIn(['compose', 'text']),
hasComposeContent: checkComposeContent(state.get('compose')),
});
const mapDispatchToProps = (dispatch) => ({
@ -30,7 +40,7 @@ class ModalRoot extends React.PureComponent {
onOpenModal: PropTypes.func.isRequired,
onCancelReplyCompose: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
composeText: PropTypes.string,
hasComposeContent: PropTypes.bool,
type: PropTypes.string,
};
@ -48,16 +58,16 @@ class ModalRoot extends React.PureComponent {
}
handleOnClose = () => {
const { onOpenModal, composeText, intl, type, onCancelReplyCompose } = this.props;
const { onOpenModal, hasComposeContent, intl, type, onCancelReplyCompose } = this.props;
if (composeText && type === 'COMPOSE') {
if (hasComposeContent && type === 'COMPOSE') {
onOpenModal('CONFIRM', {
message: <FormattedMessage id='confirmations.delete.message' defaultMessage='Are you sure you want to delete this post?' />,
confirm: intl.formatMessage(messages.confirm),
onConfirm: () => onCancelReplyCompose(),
onCancel: () => onOpenModal('COMPOSE'),
});
} else if (composeText && type === 'CONFIRM') {
} else if (hasComposeContent && type === 'CONFIRM') {
onOpenModal('COMPOSE');
} else {
this.props.onClose();

@ -99,7 +99,7 @@ function clearAll(state) {
map.set('in_reply_to', null);
map.set('privacy', state.get('default_privacy'));
map.set('sensitive', false);
map.update('media_attachments', list => list.clear());
map.set('media_attachments', ImmutableList());
map.set('poll', null);
map.set('idempotencyKey', uuid());
});
@ -257,21 +257,12 @@ export default function compose(state = initialState, action) {
map.set('spoiler_text', '');
}
});
case COMPOSE_REPLY_CANCEL:
case COMPOSE_RESET:
return state.withMutations(map => {
map.set('in_reply_to', null);
map.set('text', '');
map.set('spoiler', false);
map.set('spoiler_text', '');
map.set('privacy', state.get('default_privacy'));
map.set('poll', null);
map.set('idempotencyKey', uuid());
});
case COMPOSE_SUBMIT_REQUEST:
return state.set('is_submitting', true);
case COMPOSE_UPLOAD_CHANGE_REQUEST:
return state.set('is_changing_upload', true);
case COMPOSE_REPLY_CANCEL:
case COMPOSE_RESET:
case COMPOSE_SUBMIT_SUCCESS:
return clearAll(state);
case COMPOSE_SUBMIT_FAIL:

Loading…
Cancel
Save