Compose: Fix content retention on close, fixes #139

stable/1.0.x
Alex Gleason 2020-06-07 16:40:56 -05:00
rodzic 346d84351c
commit e78d8d59b6
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 7211D1F99744FBB7
2 zmienionych plików z 18 dodań i 17 usunięć

Wyświetl plik

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

Wyświetl plik

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