mirror of
https://github.com/flarum/framework.git
synced 2025-02-11 06:59:46 +08:00
Scroll to edited post or inform the user (#2108)
* scroll to edit or inform the user
This commit is contained in:
parent
af22f5f89a
commit
909e741c62
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user