Composer: refactor submitCompose code

datepicker-css
Alex Gleason 3 years ago
parent 1f5580ce66
commit 600146f2be
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7

@ -161,26 +161,49 @@ export function handleComposeSubmit(dispatch, getState, data, status) {
} }
} }
export function submitCompose(routerHistory, group) { const needsDescriptions = state => {
const media = state.getIn(['compose', 'media_attachments']);
const missingDescriptionModal = getSettings(state).get('missingDescriptionModal');
const hasMissing = media.filter(item => !item.get('description')).size > 0;
return missingDescriptionModal && hasMissing;
};
export function submitCompose(routerHistory, force = false) {
return function(dispatch, getState) { return function(dispatch, getState) {
if (!isLoggedIn(getState)) return; if (!isLoggedIn(getState)) return;
const state = getState();
const status = state.getIn(['compose', 'text'], '');
const media = state.getIn(['compose', 'media_attachments']);
if ((!status || !status.length) && media.size === 0) {
return;
}
if (!force && needsDescriptions(state)) {
dispatch(openModal('MISSING_DESCRIPTION', {
onContinue: () => dispatch(submitCompose(routerHistory, true)),
}));
return;
}
function onModalSubmitCompose() {
dispatch(submitComposeRequest()); dispatch(submitComposeRequest());
dispatch(closeModal()); dispatch(closeModal());
const idempotencyKey = getState().getIn(['compose', 'idempotencyKey']); const idempotencyKey = state.getIn(['compose', 'idempotencyKey']);
const params = { const params = {
status, status,
in_reply_to_id: getState().getIn(['compose', 'in_reply_to'], null), in_reply_to_id: state.getIn(['compose', 'in_reply_to'], null),
media_ids: media.map(item => item.get('id')), media_ids: media.map(item => item.get('id')),
sensitive: getState().getIn(['compose', 'sensitive']), sensitive: state.getIn(['compose', 'sensitive']),
spoiler_text: getState().getIn(['compose', 'spoiler_text'], ''), spoiler_text: state.getIn(['compose', 'spoiler_text'], ''),
visibility: getState().getIn(['compose', 'privacy']), visibility: state.getIn(['compose', 'privacy']),
content_type: getState().getIn(['compose', 'content_type']), content_type: state.getIn(['compose', 'content_type']),
poll: getState().getIn(['compose', 'poll'], null), poll: state.getIn(['compose', 'poll'], null),
scheduled_at: getState().getIn(['compose', 'schedule'], null), scheduled_at: state.getIn(['compose', 'schedule'], null),
}; };
dispatch(createStatus(params, idempotencyKey)).then(function(data) { dispatch(createStatus(params, idempotencyKey)).then(function(data) {
@ -191,22 +214,6 @@ export function submitCompose(routerHistory, group) {
}).catch(function(error) { }).catch(function(error) {
dispatch(submitComposeFail(error)); dispatch(submitComposeFail(error));
}); });
}
const status = getState().getIn(['compose', 'text'], '');
const media = getState().getIn(['compose', 'media_attachments']);
if ((!status || !status.length) && media.size === 0) {
return;
}
const missingDescriptionModal = getSettings(getState()).get('missingDescriptionModal');
if (missingDescriptionModal && media.filter(item => !item.get('description')).size) {
dispatch(openModal('MISSING_DESCRIPTION', {
onContinue: () => onModalSubmitCompose(),
}));
} else onModalSubmitCompose();
}; };
}; };

Loading…
Cancel
Save