Split out is_changing_upload from is_submitting

Fixes #855
This commit is contained in:
Thibaut Girka 2018-12-16 15:26:04 +01:00 committed by ThibG
parent 396c5dea87
commit 8266d224ef
2 changed files with 13 additions and 5 deletions

View file

@ -81,6 +81,7 @@ function mapStateToProps (state) {
focusDate: state.getIn(['compose', 'focusDate']),
caretPosition: state.getIn(['compose', 'caretPosition']),
isSubmitting: state.getIn(['compose', 'is_submitting']),
isChangingUpload: state.getIn(['compose', 'is_changing_upload']),
isUploading: state.getIn(['compose', 'is_uploading']),
layout: state.getIn(['local_settings', 'layout']),
media: state.getIn(['compose', 'media_attachments']),
@ -228,6 +229,7 @@ const handlers = {
onChangeText,
onSubmit,
isSubmitting,
isChangingUpload,
isUploading,
media,
anyMedia,
@ -243,7 +245,7 @@ const handlers = {
}
// Submit disabled:
if (isSubmitting || isUploading || (!text.trim().length && !anyMedia)) {
if (isSubmitting || isUploading || isChangingUpload || (!text.trim().length && !anyMedia)) {
return;
}
@ -386,6 +388,7 @@ class Composer extends React.Component {
anyMedia,
intl,
isSubmitting,
isChangingUpload,
isUploading,
layout,
media,
@ -418,7 +421,7 @@ class Composer extends React.Component {
spoilersAlwaysOn,
} = this.props;
let disabledButton = isSubmitting || isUploading || (!text.trim().length && !anyMedia);
let disabledButton = isSubmitting || isUploading || isChangingUpload || (!text.trim().length && !anyMedia);
return (
<div className='composer'>
@ -518,6 +521,7 @@ Composer.propTypes = {
focusDate: PropTypes.instanceOf(Date),
caretPosition: PropTypes.number,
isSubmitting: PropTypes.bool,
isChangingUpload: PropTypes.bool,
isUploading: PropTypes.bool,
layout: PropTypes.string,
media: ImmutablePropTypes.list,

View file

@ -67,6 +67,7 @@ const initialState = ImmutableMap({
in_reply_to: null,
is_submitting: false,
is_uploading: false,
is_changing_upload: false,
progress: 0,
media_attachments: ImmutableList(),
suggestion_token: null,
@ -130,6 +131,7 @@ function clearAll(state) {
map.set('spoiler', false);
map.set('spoiler_text', '');
map.set('is_submitting', false);
map.set('is_changing_upload', false);
map.set('in_reply_to', null);
map.update(
'advanced_options',
@ -341,13 +343,15 @@ export default function compose(state = initialState, action) {
map.set('idempotencyKey', uuid());
});
case COMPOSE_SUBMIT_REQUEST:
case COMPOSE_UPLOAD_CHANGE_REQUEST:
return state.set('is_submitting', true);
case COMPOSE_UPLOAD_CHANGE_REQUEST:
return state.set('is_changing_upload', true);
case COMPOSE_SUBMIT_SUCCESS:
return action.status && state.getIn(['advanced_options', 'threaded_mode']) ? continueThread(state, action.status) : clearAll(state);
case COMPOSE_SUBMIT_FAIL:
case COMPOSE_UPLOAD_CHANGE_FAIL:
return state.set('is_submitting', false);
case COMPOSE_UPLOAD_CHANGE_FAIL:
return state.set('is_changing_upload', false);
case COMPOSE_UPLOAD_REQUEST:
return state.set('is_uploading', true);
case COMPOSE_UPLOAD_SUCCESS:
@ -393,7 +397,7 @@ export default function compose(state = initialState, action) {
return insertEmoji(state, action.position, action.emoji);
case COMPOSE_UPLOAD_CHANGE_SUCCESS:
return state
.set('is_submitting', false)
.set('is_changing_upload', false)
.update('media_attachments', list => list.map(item => {
if (item.get('id') === action.media.id) {
return fromJS(action.media);