From d1a1277f889eca49e44d1eb7ee1ee01c96729846 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Sun, 9 Aug 2020 23:53:24 -0400 Subject: [PATCH] update: forum/components/EditPostComponent --- js/src/forum/components/EditPostComposer.js | 53 ++++++++++----------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/js/src/forum/components/EditPostComposer.js b/js/src/forum/components/EditPostComposer.js index a49d133f0..76ec04f48 100644 --- a/js/src/forum/components/EditPostComposer.js +++ b/js/src/forum/components/EditPostComposer.js @@ -14,38 +14,32 @@ function minimizeComposerIfFullScreen(e) { * post. It sets the initial content to the content of the post that is being * edited, and adds a header control to indicate which post is being edited. * - * ### Props + * ### Attrs * - * - All of the props for ComposerBody + * - All of the attrs for ComposerBody * - `post` */ export default class EditPostComposer extends ComposerBody { - static initProps(props) { - super.initProps(props); + initAttrs(attrs) { + super.initAttrs(attrs); - props.submitLabel = props.submitLabel || app.translator.trans('core.forum.composer_edit.submit_button'); - props.confirmExit = props.confirmExit || app.translator.trans('core.forum.composer_edit.discard_confirmation'); - props.originalContent = props.originalContent || props.post.content(); - props.user = props.user || props.post.user(); + attrs.submitLabel = attrs.submitLabel || app.translator.trans('core.forum.composer_edit.submit_button'); + attrs.confirmExit = attrs.confirmExit || app.translator.trans('core.forum.composer_edit.discard_confirmation'); + attrs.originalContent = attrs.originalContent || attrs.post.content(); + attrs.user = attrs.user || attrs.post.user(); - props.post.editedContent = props.originalContent; + attrs.post.editedContent = attrs.originalContent; } headerItems() { const items = super.headerItems(); - const post = this.props.post; - - const routeAndMinimize = function (element, isInitialized) { - if (isInitialized) return; - $(element).on('click', minimizeComposerIfFullScreen); - m.route.apply(this, arguments); - }; + const post = this.attrs.post; items.add( 'title',

{icon('fas fa-pencil-alt')}{' '} - + {app.translator.trans('core.forum.composer_edit.post_link', { number: post.number(), discussion: post.discussion().title() })}

@@ -60,7 +54,7 @@ export default class EditPostComposer extends ComposerBody { jumpToPreview(e) { minimizeComposerIfFullScreen(e); - m.route(app.route.post(this.props.post)); + m.route.set(app.route.post(this.attrs.post)); } /** @@ -75,13 +69,13 @@ export default class EditPostComposer extends ComposerBody { } onsubmit() { - const discussion = this.props.post.discussion(); + const discussion = this.attrs.post.discussion(); this.loading = true; const data = this.data(); - this.props.post.save(data).then((post) => { + this.attrs.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)) { @@ -91,17 +85,18 @@ export default class EditPostComposer extends ComposerBody { // 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); + const viewButton = Button.component( + { + className: 'Button Button--link', + onclick: () => { + m.route(app.route.post(post)); + app.alerts.dismiss(alert); + }, }, - }); - alert = app.alerts.show({ + app.translator.trans('core.forum.composer_edit.view_button') + ); + alert = app.alerts.show(app.translator.trans('core.forum.composer_edit.edited_message'), { type: 'success', - children: app.translator.trans('core.forum.composer_edit.edited_message'), controls: [viewButton], }); }