From d1f21c78f15fe056c2ab2262ac4c665b542130a8 Mon Sep 17 00:00:00 2001 From: Keegan George Date: Fri, 17 Nov 2023 09:25:41 -0800 Subject: [PATCH] UX: Add copy button to generated suggestion (#296) --- .../ai-helper-options-menu.gjs | 34 +++++++++++++++++-- .../modules/ai-helper/common/ai-helper.scss | 16 ++++++++- config/locales/client.en.yml | 2 ++ 3 files changed, 49 insertions(+), 3 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 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)}} -
{{this.suggestion}}
+
+
+ {{this.suggestion}} +
+ +
{{/if}} -} +} \ No newline at end of file diff --git a/assets/stylesheets/modules/ai-helper/common/ai-helper.scss b/assets/stylesheets/modules/ai-helper/common/ai-helper.scss index 77de358c..3d954be0 100644 --- a/assets/stylesheets/modules/ai-helper/common/ai-helper.scss +++ b/assets/stylesheets/modules/ai-helper/common/ai-helper.scss @@ -326,6 +326,20 @@ } &__suggestion { - padding: 1rem; + padding: 0.5rem; + display: flex; + flex-direction: column; + + &__copy { + margin-top: 0.5rem; + + .d-icon-check { + color: var(--success); + } + } + + &__text { + padding: 0.5rem; + } } } diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index 14af7117..33f40e99 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -70,6 +70,8 @@ en: trigger: "Ask AI" loading: "AI is generating" close: "Close" + copy: "Copy" + copied: "Copied!" reviewables: model_used: "Model used:" accuracy: "Accuracy:"