diff --git a/framework/core/js/src/forum/components/EditPostComposer.js b/framework/core/js/src/forum/components/EditPostComposer.js index ba6c71107..86b9703e5 100644 --- a/framework/core/js/src/forum/components/EditPostComposer.js +++ b/framework/core/js/src/forum/components/EditPostComposer.js @@ -1,4 +1,6 @@ import ComposerBody from './ComposerBody'; +import Alert from '../../common/components/Alert'; +import Button from '../../common/components/Button'; import icon from '../../common/helpers/icon'; function minimizeComposerIfFullScreen(e) { @@ -75,10 +77,40 @@ export default class EditPostComposer extends ComposerBody { } onsubmit() { + const discussion = this.props.post.discussion(); + this.loading = true; const data = this.data(); - this.props.post.save(data).then(() => app.composer.hide(), this.loaded.bind(this)); + this.props.post.save(data).then((post) => { + // If we're currently viewing the discussion which this edit was made + // in, then we can scroll to the post. + if (app.viewingDiscussion(discussion)) { + app.current.stream.goToNumber(post.number()); + } else { + // Otherwise, we'll create an alert message to inform the user that + // their edit has been made, containing a button which will + // transition to their edited post when clicked. + let alert; + const viewButton = Button.component({ + className: 'Button Button--link', + children: app.translator.trans('core.forum.composer_edit.view_button'), + onclick: () => { + m.route(app.route.post(post)); + app.alerts.dismiss(alert); + }, + }); + app.alerts.show( + (alert = new Alert({ + type: 'success', + children: app.translator.trans('core.forum.composer_edit.edited_message'), + controls: [viewButton], + })) + ); + } + + app.composer.hide(); + }, this.loaded.bind(this)); } }