Redirect on success for standalone compose (#35763)
This commit is contained in:
		@@ -183,7 +183,7 @@ export function directCompose(account) {
 | 
				
			|||||||
  };
 | 
					  };
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export function submitCompose() {
 | 
					export function submitCompose(successCallback) {
 | 
				
			||||||
  return function (dispatch, getState) {
 | 
					  return function (dispatch, getState) {
 | 
				
			||||||
    const status   = getState().getIn(['compose', 'text'], '');
 | 
					    const status   = getState().getIn(['compose', 'text'], '');
 | 
				
			||||||
    const media    = getState().getIn(['compose', 'media_attachments']);
 | 
					    const media    = getState().getIn(['compose', 'media_attachments']);
 | 
				
			||||||
@@ -239,6 +239,9 @@ export function submitCompose() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
      dispatch(insertIntoTagHistory(response.data.tags, status));
 | 
					      dispatch(insertIntoTagHistory(response.data.tags, status));
 | 
				
			||||||
      dispatch(submitComposeSuccess({ ...response.data }));
 | 
					      dispatch(submitComposeSuccess({ ...response.data }));
 | 
				
			||||||
 | 
					      if (typeof successCallback === 'function') {
 | 
				
			||||||
 | 
					        successCallback(response.data);
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      // To make the app more responsive, immediately push the status
 | 
					      // To make the app more responsive, immediately push the status
 | 
				
			||||||
      // into the columns
 | 
					      // into the columns
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -73,6 +73,7 @@ class ComposeForm extends ImmutablePureComponent {
 | 
				
			|||||||
    singleColumn: PropTypes.bool,
 | 
					    singleColumn: PropTypes.bool,
 | 
				
			||||||
    lang: PropTypes.string,
 | 
					    lang: PropTypes.string,
 | 
				
			||||||
    maxChars: PropTypes.number,
 | 
					    maxChars: PropTypes.number,
 | 
				
			||||||
 | 
					    redirectOnSuccess: PropTypes.bool,
 | 
				
			||||||
  };
 | 
					  };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static defaultProps = {
 | 
					  static defaultProps = {
 | 
				
			||||||
@@ -310,7 +311,7 @@ class ComposeForm extends ImmutablePureComponent {
 | 
				
			|||||||
                >
 | 
					                >
 | 
				
			||||||
                  {intl.formatMessage(
 | 
					                  {intl.formatMessage(
 | 
				
			||||||
                    this.props.isEditing ?
 | 
					                    this.props.isEditing ?
 | 
				
			||||||
                      messages.saveChanges : 
 | 
					                      messages.saveChanges :
 | 
				
			||||||
                      (this.props.isInReply ? messages.reply : messages.publish)
 | 
					                      (this.props.isInReply ? messages.reply : messages.publish)
 | 
				
			||||||
                  )}
 | 
					                  )}
 | 
				
			||||||
                </Button>
 | 
					                </Button>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,7 +34,7 @@ const mapStateToProps = state => ({
 | 
				
			|||||||
  maxChars: state.getIn(['server', 'server', 'configuration', 'statuses', 'max_characters'], 500),
 | 
					  maxChars: state.getIn(['server', 'server', 'configuration', 'statuses', 'max_characters'], 500),
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const mapDispatchToProps = (dispatch) => ({
 | 
					const mapDispatchToProps = (dispatch, props) => ({
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  onChange (text) {
 | 
					  onChange (text) {
 | 
				
			||||||
    dispatch(changeCompose(text));
 | 
					    dispatch(changeCompose(text));
 | 
				
			||||||
@@ -47,7 +47,11 @@ const mapDispatchToProps = (dispatch) => ({
 | 
				
			|||||||
        modalProps: {},
 | 
					        modalProps: {},
 | 
				
			||||||
      }));
 | 
					      }));
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      dispatch(submitCompose());
 | 
					      dispatch(submitCompose((status) => {
 | 
				
			||||||
 | 
					        if (props.redirectOnSuccess) {
 | 
				
			||||||
 | 
					          window.location.assign(status.url);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					      }));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ import ModalContainer from 'mastodon/features/ui/containers/modal_container';
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
const Compose = () => (
 | 
					const Compose = () => (
 | 
				
			||||||
  <>
 | 
					  <>
 | 
				
			||||||
    <ComposeFormContainer autoFocus withoutNavigation />
 | 
					    <ComposeFormContainer autoFocus withoutNavigation redirectOnSuccess />
 | 
				
			||||||
    <AlertsController />
 | 
					    <AlertsController />
 | 
				
			||||||
    <ModalContainer />
 | 
					    <ModalContainer />
 | 
				
			||||||
    <LoadingBarContainer className='loading-bar' />
 | 
					    <LoadingBarContainer className='loading-bar' />
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -23,7 +23,7 @@ RSpec.describe 'Share page', :js, :streaming do
 | 
				
			|||||||
    fill_in_form
 | 
					    fill_in_form
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    expect(page)
 | 
					    expect(page)
 | 
				
			||||||
      .to have_css('.notification-bar-message', text: frontend_translations('compose.published.body'))
 | 
					      .to have_current_path(%r{/@bob/[0-9]+})
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  def fill_in_form
 | 
					  def fill_in_form
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user