From 5ae0366739c2781cc1cd609991d1be8ee24cc6a2 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 19 Jun 2020 18:26:31 -0400 Subject: [PATCH] refactor composer load to use the composer instance internally --- js/src/forum/components/IndexPage.js | 3 +-- js/src/forum/states/ComposerState.js | 6 ++++-- js/src/forum/utils/DiscussionControls.js | 10 ++++------ js/src/forum/utils/PostControls.js | 2 +- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/js/src/forum/components/IndexPage.js b/js/src/forum/components/IndexPage.js index dff0c17d2d9..0cbb01c18ac 100644 --- a/js/src/forum/components/IndexPage.js +++ b/js/src/forum/components/IndexPage.js @@ -11,7 +11,6 @@ import Dropdown from '../../common/components/Dropdown'; import Button from '../../common/components/Button'; import LinkButton from '../../common/components/LinkButton'; import SelectDropdown from '../../common/components/SelectDropdown'; -import Composer from '../instances/Composer'; /** * The `IndexPage` component displays the index page, including the welcome @@ -274,7 +273,7 @@ export default class IndexPage extends Page { const deferred = m.deferred(); if (app.session.user) { - app.composer.load(new Composer(DiscussionComposer, { user: app.session.user })); + app.composer.load(DiscussionComposer, { user: app.session.user }); app.composer.show(); deferred.resolve(app.composer); diff --git a/js/src/forum/states/ComposerState.js b/js/src/forum/states/ComposerState.js index 4f202c4590c..981f2a8864d 100644 --- a/js/src/forum/states/ComposerState.js +++ b/js/src/forum/states/ComposerState.js @@ -89,10 +89,12 @@ class ComposerState { /** * Load a content component into the composer. * - * @param {Composer} composer + * @param {ComposerBody} bodyClass * @public */ - load(body) { + load(bodyClass, bodyAttrs) { + const body = new Composer(bodyClass, bodyAttrs); + if (this.preventExit()) return; // If we load a similar component into the composer, then Mithril will be diff --git a/js/src/forum/utils/DiscussionControls.js b/js/src/forum/utils/DiscussionControls.js index 1dd54dbe366..4721b332446 100644 --- a/js/src/forum/utils/DiscussionControls.js +++ b/js/src/forum/utils/DiscussionControls.js @@ -169,12 +169,10 @@ export default { if (app.session.user) { if (this.canReply()) { if (!app.composer.composingReplyTo(this) || forceRefresh) { - app.composer.load( - new Composer(ReplyComposer, { - user: app.session.user, - discussion: this, - }) - ); + app.composer.load(ReplyComposer, { + user: app.session.user, + discussion: this, + }); } app.composer.show(); diff --git a/js/src/forum/utils/PostControls.js b/js/src/forum/utils/PostControls.js index d154927ae58..2ed7790ed8d 100644 --- a/js/src/forum/utils/PostControls.js +++ b/js/src/forum/utils/PostControls.js @@ -131,7 +131,7 @@ export default { editAction() { const deferred = m.deferred(); - app.composer.load(new Composer(EditPostComposer, { post: this })); + app.composer.load(EditPostComposer, { post: this }); app.composer.show(); deferred.resolve(app.composer);