A platform for community discussion. Free, open, simple.
FEATURE: revert/re-add import quote toolbar button (#31449)
Renato Atilio4f0ab65b5ba7
diff --git a/app/assets/javascripts/discourse/app/components/composer-editor.js b/app/assets/javascripts/discourse/app/components/composer-editor.jsindex 6817ed6353e..5bb3c40179f 100644--- a/app/assets/javascripts/discourse/app/components/composer-editor.js+++ b/app/assets/javascripts/discourse/app/components/composer-editor.js@@ -875,6 +875,15 @@ export default class ComposerEditor extends Component {@actionextraButtons(toolbar) {+ toolbar.addButton({+ id: "quote",+ group: "fontStyles",+ icon: "far-comment",+ sendAction: this.composer.importQuote,+ title: "composer.quote_post_title",+ unshift: true,+ });+if (this.composer.allowUpload &&this.composer.uploadIcon &&diff --git a/app/assets/javascripts/discourse/app/services/composer.js b/app/assets/javascripts/discourse/app/services/composer.jsindex d29e7eb9af9..d1263c8cae0 100644--- a/app/assets/javascripts/discourse/app/services/composer.js+++ b/app/assets/javascripts/discourse/app/services/composer.js@@ -28,6 +28,7 @@ import { getOwnerWithFallback } from "discourse/lib/get-owner";import getURL from "discourse/lib/get-url";import { disableImplicitInjections } from "discourse/lib/implicit-injections";import { wantsNewWindow } from "discourse/lib/intercept-click";+import { buildQuote } from "discourse/lib/quote";import { emojiUnescape } from "discourse/lib/text";import { applyValueTransformer } from "discourse/lib/transformer";import {@@ -844,6 +845,45 @@ export default class ComposerService extends Service {return false;}+ // Import a quote from the post+ @action+ async importQuote(toolbarEvent) {+ const postStream = this.get("topic.postStream");+ let postId = this.get("model.post.id");++ // If there is no current post, use the first post id from the stream+ if (!postId && postStream) {+ postId = postStream.get("stream.firstObject");+ }++ // If we're editing a post, fetch the reply when importing a quote+ if (this.get("model.editingPost")) {+ const replyToPostNumber = this.get("model.post.reply_to_post_number");+ if (replyToPostNumber) {+ const replyPost = postStream.posts.findBy(+ "post_number",+ replyToPostNumber+ );++ if (replyPost) {+ postId = replyPost.id;+ }+ }+ }++ if (!postId) {+ return;+ }++ this.set("model.loading", true);++ const post = await this.store.find("post", postId);+ const quote = buildQuote(post, post.raw, { full: true });++ toolbarEvent.addText(quote);+ this.set("model.loading", false);+ }+@actionsaveAction(ignore, event) {this.save(false, {diff --git a/app/assets/javascripts/discourse/tests/integration/components/composer-editor-test.gjs b/app/assets/javascripts/discourse/tests/integration/components/composer-editor-test.gjsindex ecbbc001a67..c2beb339da2 100644--- a/app/assets/javascripts/discourse/tests/integration/components/composer-editor-test.gjs+++ b/app/assets/javascripts/discourse/tests/integration/components/composer-editor-test.gjs@@ -51,4 +51,10 @@ module("Integration | Component | ComposerEditor", function (hooks) {await fillIn(".d-editor-input", `"><svg onload="prompt(/xss/)"></svg>`);assert.dom(".d-editor-preview").hasHtml('<p>"><svg></svg></p>');});++ test("has a toolbar button to quote a post", async function (assert) {+ await render(<template><ComposerEditor /></template>);++ assert.dom(".d-editor-button-bar .btn.quote").exists();+ });});