mirror of
https://github.com/flarum/framework.git
synced 2025-06-21 01:31:21 +08:00
Use new replyAction promise implementation
This commit is contained in:
@ -7,24 +7,31 @@ export default function() {
|
|||||||
var post = this.props.post;
|
var post = this.props.post;
|
||||||
if (post.isHidden()) return;
|
if (post.isHidden()) return;
|
||||||
|
|
||||||
|
function insertMention(component, quote) {
|
||||||
|
var mention = '@'+post.user().username()+'#'+post.number()+' ';
|
||||||
|
|
||||||
|
// If the composer is empty, then assume we're starting a new reply.
|
||||||
|
// In which case we don't want the user to have to confirm if they
|
||||||
|
// close the composer straight away.
|
||||||
|
if (!component.content()) {
|
||||||
|
component.props.originalContent = mention;
|
||||||
|
}
|
||||||
|
|
||||||
|
component.editor.insertAtCursor((component.editor.getSelectionRange()[0] > 0 ? '\n\n' : '')+(quote ? '> '+mention+quote.trim().replace(/\n/g, '\n> ')+'\n\n' : mention));
|
||||||
|
}
|
||||||
|
|
||||||
items.add('reply',
|
items.add('reply',
|
||||||
ActionButton.component({
|
ActionButton.component({
|
||||||
icon: 'reply',
|
icon: 'reply',
|
||||||
label: 'Reply',
|
label: 'Reply',
|
||||||
onclick: () => {
|
onclick: () => {
|
||||||
var component = post.discussion().replyAction();
|
var quote = window.getSelection().toString();
|
||||||
if (component) {
|
|
||||||
var quote = window.getSelection().toString();
|
|
||||||
var mention = '@'+post.user().username()+'#'+post.number()+' ';
|
|
||||||
|
|
||||||
// If the composer is empty, then assume we're starting a new reply.
|
var component = app.composer.component;
|
||||||
// In which case we don't want the user to have to confirm if they
|
if (component && component.props.post && component.props.post.discussion() === post.discussion()) {
|
||||||
// close the composer straight away.
|
insertMention(component, quote);
|
||||||
if (!component.content()) {
|
} else {
|
||||||
component.props.originalContent = mention;
|
post.discussion().replyAction().then(component => insertMention(component, quote));
|
||||||
}
|
|
||||||
|
|
||||||
component.editor.insertAtCursor((component.editor.value() ? '\n\n' : '')+(quote ? '> '+mention+quote+'\n\n' : mention));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user