mirror of
https://github.com/flarum/framework.git
synced 2025-05-31 12:35:48 +08:00
Massive JavaScript cleanup
- Use JSX for templates - Docblock/comment everything - Mostly passes ESLint (still some work to do) - Lots of renaming, refactoring, etc. CSS hasn't been updated yet.
This commit is contained in:
93
js/forum/src/components/ReplyComposer.js
Normal file
93
js/forum/src/components/ReplyComposer.js
Normal file
@ -0,0 +1,93 @@
|
||||
import ComposerBody from 'flarum/components/ComposerBody';
|
||||
import Alert from 'flarum/components/Alert';
|
||||
import Button from 'flarum/components/Button';
|
||||
import icon from 'flarum/helpers/icon';
|
||||
|
||||
/**
|
||||
* The `ReplyComposer` component displays the composer content for replying to a
|
||||
* discussion.
|
||||
*
|
||||
* ### Props
|
||||
*
|
||||
* - All of the props of ComposerBody
|
||||
* - `discussion`
|
||||
*/
|
||||
export default class ReplyComposer extends ComposerBody {
|
||||
static initProps(props) {
|
||||
super.initProps(props);
|
||||
|
||||
props.placeholder = props.placeholder || 'Write a Reply...';
|
||||
props.submitLabel = props.submitLabel || 'Post Reply';
|
||||
props.confirmExit = props.confirmExit || 'You have not posted your reply. Do you wish to discard it?';
|
||||
}
|
||||
|
||||
headerItems() {
|
||||
const items = super.headerItems();
|
||||
const discussion = this.props.discussion;
|
||||
|
||||
items.add('title', (
|
||||
<h3>
|
||||
{icon('reply')} <a href={app.route.discussion(discussion)} config={m.route}>{discussion.title()}</a>
|
||||
</h3>
|
||||
));
|
||||
|
||||
return items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data to submit to the server when the reply is saved.
|
||||
*
|
||||
* @return {Object}
|
||||
*/
|
||||
data() {
|
||||
return {
|
||||
content: this.content(),
|
||||
relationships: {discussion: this.props.discussion}
|
||||
};
|
||||
}
|
||||
|
||||
onsubmit() {
|
||||
const discussion = this.props.discussion;
|
||||
|
||||
this.loading = true;
|
||||
m.redraw();
|
||||
|
||||
const data = this.data();
|
||||
|
||||
app.store.createRecord('posts').save(data).then(
|
||||
post => {
|
||||
// If we're currently viewing the discussion which this reply was made
|
||||
// in, then we can update the post stream.
|
||||
if (app.viewingDiscussion(discussion)) {
|
||||
app.current.stream.update();
|
||||
} else {
|
||||
// Otherwise, we'll create an alert message to inform the user that
|
||||
// their reply has been posted, containing a button which will
|
||||
// transition to their new post when clicked.
|
||||
let alert;
|
||||
const viewButton = Button.component({
|
||||
children: 'View',
|
||||
onclick: () => {
|
||||
m.route(app.route.post(post));
|
||||
app.alerts.dismiss(alert);
|
||||
}
|
||||
});
|
||||
app.alerts.show(
|
||||
alert = new Alert({
|
||||
type: 'success',
|
||||
message: 'Your reply was posted.',
|
||||
controls: [viewButton]
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
app.composer.hide();
|
||||
},
|
||||
errors => {
|
||||
this.loading = false;
|
||||
m.redraw();
|
||||
app.alertErrors(errors);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user