From f0505a5b2e727da73c8aa651b804508a8187a3c4 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Thu, 13 Dec 2018 16:50:37 +0100 Subject: [PATCH] On mobile, go back in browser history upon posting, unless threaded mode is enabled --- .../flavours/glitch/actions/compose.js | 8 +++++++- .../flavours/glitch/features/composer/index.js | 16 ++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 58f2b3786f..d53d269249 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -116,7 +116,7 @@ export function directCompose(account, router) { }; }; -export function submitCompose() { +export function submitCompose(routerHistory) { return function (dispatch, getState) { let status = getState().getIn(['compose', 'text'], ''); let media = getState().getIn(['compose', 'media_attachments']); @@ -158,6 +158,12 @@ export function submitCompose() { } }; + if (routerHistory && routerHistory.location.pathname === '/statuses/new' + && window.history.state + && !getState().getIn(['compose', 'advanced_options', 'threaded_mode'])) { + routerHistory.goBack(); + } + insertIfOnline('home'); if (response.data.in_reply_to_id === null && response.data.visibility === 'public') { diff --git a/app/javascript/flavours/glitch/features/composer/index.js b/app/javascript/flavours/glitch/features/composer/index.js index 029b11a369..40eae1f539 100644 --- a/app/javascript/flavours/glitch/features/composer/index.js +++ b/app/javascript/flavours/glitch/features/composer/index.js @@ -159,15 +159,15 @@ const mapDispatchToProps = (dispatch, { intl }) => ({ onSelectSuggestion(position, token, suggestion) { dispatch(selectComposeSuggestion(position, token, suggestion)); }, - onMediaDescriptionConfirm() { + onMediaDescriptionConfirm(routerHistory) { dispatch(openModal('CONFIRM', { message: intl.formatMessage(messages.missingDescriptionMessage), confirm: intl.formatMessage(messages.missingDescriptionConfirm), - onConfirm: () => dispatch(submitCompose()), + onConfirm: () => dispatch(submitCompose(routerHistory)), })); }, - onSubmit() { - dispatch(submitCompose()); + onSubmit(routerHistory) { + dispatch(submitCompose(routerHistory)); }, onUndoUpload(id) { dispatch(undoUploadCompose(id)); @@ -256,9 +256,9 @@ const handlers = { inputs[firstWithoutDescription].focus(); } } - onMediaDescriptionConfirm(); + onMediaDescriptionConfirm(this.context.router ? this.context.router.history : null); } else if (onSubmit) { - onSubmit(); + onSubmit(this.context.router ? this.context.router.history : null); } }, @@ -563,6 +563,10 @@ Composer.propTypes = { onMediaDescriptionConfirm: PropTypes.func, }; +Composer.contextTypes = { + router: PropTypes.object, +}; + // Connecting and export. export { Composer as WrappedComponent }; export default wrap(Composer, mapStateToProps, mapDispatchToProps, true);