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 a959a2a7..80a297c2 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 @@ -7,6 +7,8 @@ import { popupAjaxError } from "discourse/lib/ajax-error"; import I18n from "I18n"; import eq from "truth-helpers/helpers/eq"; import { showPostAIHelper } from "../../lib/show-ai-helper"; +import not from "truth-helpers/helpers/not"; + const i18n = I18n.t.bind(I18n); @@ -20,6 +22,9 @@ export default class AIHelperOptionsMenu extends Component { @tracked suggestion = ""; @tracked showMainButtons = true; + @tracked copyButtonIcon = "copy"; + @tracked copyButtonLabel = "discourse_ai.ai_helper.post_options_menu.copy"; + MENU_STATES = { triggers: "TRIGGERS", options: "OPTIONS", @@ -90,6 +95,20 @@ 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); + }); + } + } + async loadPrompts() { let prompts = await ajax("/discourse-ai/ai-helper/prompts"); @@ -146,8 +165,19 @@ export default class AIHelperOptionsMenu extends Component { /> {{else if (eq this.menuState this.MENU_STATES.result)}} -