From 02d92d3b68601e34e540156e71f55d39b79bd459 Mon Sep 17 00:00:00 2001 From: Echo Date: Wed, 13 Aug 2025 15:52:29 +0200 Subject: [PATCH] [Glitch] Redirect on success for standalone compose Port 1675eab56145152dfbc7858efb36f3c30d89dcf4 to glitch-soc Signed-off-by: Claire --- app/javascript/flavours/glitch/actions/compose.js | 6 +++++- .../glitch/features/compose/components/compose_form.jsx | 3 ++- .../features/compose/containers/compose_form_container.js | 8 ++++++-- .../flavours/glitch/features/standalone/compose/index.jsx | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/compose.js b/app/javascript/flavours/glitch/actions/compose.js index 3b4b704626..ad436e9d79 100644 --- a/app/javascript/flavours/glitch/actions/compose.js +++ b/app/javascript/flavours/glitch/actions/compose.js @@ -193,8 +193,9 @@ export function directCompose(account) { /** * @param {null | string} overridePrivacy + * @param {undefined | Function} successCallback */ -export function submitCompose(overridePrivacy = null) { +export function submitCompose(overridePrivacy = null, successCallback = undefined) { return function (dispatch, getState) { let status = getState().getIn(['compose', 'text'], ''); const media = getState().getIn(['compose', 'media_attachments']); @@ -259,6 +260,9 @@ export function submitCompose(overridePrivacy = null) { dispatch(insertIntoTagHistory(response.data.tags, status)); dispatch(submitComposeSuccess({ ...response.data })); + if (typeof successCallback === 'function') { + successCallback(response.data); + } // To make the app more responsive, immediately push the status // into the columns diff --git a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx index 96e252ad2f..631181658a 100644 --- a/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx +++ b/app/javascript/flavours/glitch/features/compose/components/compose_form.jsx @@ -81,6 +81,7 @@ class ComposeForm extends ImmutablePureComponent { singleColumn: PropTypes.bool, lang: PropTypes.string, maxChars: PropTypes.number, + redirectOnSuccess: PropTypes.bool, }; static defaultProps = { @@ -336,7 +337,7 @@ class ComposeForm extends ImmutablePureComponent { > {intl.formatMessage( this.props.isEditing ? - messages.saveChanges : + messages.saveChanges : (this.props.isInReply ? messages.reply : messages.publish) )} diff --git a/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js b/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js index fab954b9b1..239f2f8a3d 100644 --- a/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js +++ b/app/javascript/flavours/glitch/features/compose/containers/compose_form_container.js @@ -56,7 +56,7 @@ const mapStateToProps = state => ({ maxChars: state.getIn(['server', 'server', 'configuration', 'statuses', 'max_characters'], 500), }); -const mapDispatchToProps = (dispatch) => ({ +const mapDispatchToProps = (dispatch, props) => ({ onChange (text) { dispatch(changeCompose(text)); @@ -69,7 +69,11 @@ const mapDispatchToProps = (dispatch) => ({ modalProps: { overridePrivacy }, })); } else { - dispatch(submitCompose(overridePrivacy)); + dispatch(submitCompose(overridePrivacy, (status) => { + if (props.redirectOnSuccess) { + window.location.assign(status.url); + } + })); } }, diff --git a/app/javascript/flavours/glitch/features/standalone/compose/index.jsx b/app/javascript/flavours/glitch/features/standalone/compose/index.jsx index ce4fdf434f..b5cec1ee4b 100644 --- a/app/javascript/flavours/glitch/features/standalone/compose/index.jsx +++ b/app/javascript/flavours/glitch/features/standalone/compose/index.jsx @@ -5,7 +5,7 @@ import ModalContainer from 'flavours/glitch/features/ui/containers/modal_contain const Compose = () => ( <> - +