From 9d8bbe32a986e88bcf50a47ac319c7a6573eadd2 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Wed, 10 Jan 2024 10:41:48 -0800 Subject: [PATCH] FIX: AI Explain copy button not working (#415) --- .../ai-helper-options-menu.gjs | 30 +++++++------------ 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/assets/javascripts/discourse/connectors/post-text-buttons/ai-helper-options-menu.gjs b/assets/javascripts/discourse/connectors/post-text-buttons/ai-helper-options-menu.gjs index 372745f1..5e49d83b 100644 --- a/assets/javascripts/discourse/connectors/post-text-buttons/ai-helper-options-menu.gjs +++ b/assets/javascripts/discourse/connectors/post-text-buttons/ai-helper-options-menu.gjs @@ -4,12 +4,13 @@ import { action } from "@ember/object"; import didInsert from "@ember/render-modifiers/modifiers/did-insert"; import willDestroy from "@ember/render-modifiers/modifiers/will-destroy"; import { inject as service } from "@ember/service"; +import CookText from "discourse/components/cook-text"; import DButton from "discourse/components/d-button"; import FastEdit from "discourse/components/fast-edit"; import FastEditModal from "discourse/components/modal/fast-edit"; import { ajax } from "discourse/lib/ajax"; import { popupAjaxError } from "discourse/lib/ajax-error"; -import { cook } from "discourse/lib/text"; +import { clipboardCopy } from "discourse/lib/utilities"; import { bind } from "discourse-common/utils/decorators"; import eq from "truth-helpers/helpers/eq"; import not from "truth-helpers/helpers/not"; @@ -78,13 +79,7 @@ export default class AIHelperOptionsMenu extends Component { @bind _updateResult(result) { - const suggestion = result.result; - - if (suggestion.length > 0) { - cook(suggestion).then((cooked) => { - this.suggestion = cooked; - }); - } + this.suggestion = result.result; } @action @@ -160,16 +155,13 @@ export default class AIHelperOptionsMenu extends Component { @action copySuggestion() { if (this.suggestion?.length > 0) { - navigator.clipboard.writeText(this.suggestion).then(() => { - this.copyButtonIcon = "check"; - this.copyButtonLabel = - "discourse_ai.ai_helper.post_options_menu.copied"; - setTimeout(() => { - this.copyButtonIcon = "copy"; - this.copyButtonLabel = - "discourse_ai.ai_helper.post_options_menu.copy"; - }, 3500); - }); + clipboardCopy(this.suggestion); + this.copyButtonIcon = "check"; + this.copyButtonLabel = "discourse_ai.ai_helper.post_options_menu.copied"; + setTimeout(() => { + this.copyButtonIcon = "copy"; + this.copyButtonLabel = "discourse_ai.ai_helper.post_options_menu.copy"; + }, 3500); } } @@ -263,7 +255,7 @@ export default class AIHelperOptionsMenu extends Component { > {{#if this.suggestion}}
- {{this.suggestion}} +