UX: Add copy button to generated suggestion (#296)
This commit is contained in:
parent
e1a7d07a91
commit
d1f21c78f1
|
@ -7,6 +7,8 @@ import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
import eq from "truth-helpers/helpers/eq";
|
import eq from "truth-helpers/helpers/eq";
|
||||||
import { showPostAIHelper } from "../../lib/show-ai-helper";
|
import { showPostAIHelper } from "../../lib/show-ai-helper";
|
||||||
|
import not from "truth-helpers/helpers/not";
|
||||||
|
|
||||||
|
|
||||||
const i18n = I18n.t.bind(I18n);
|
const i18n = I18n.t.bind(I18n);
|
||||||
|
|
||||||
|
@ -20,6 +22,9 @@ export default class AIHelperOptionsMenu extends Component {
|
||||||
@tracked suggestion = "";
|
@tracked suggestion = "";
|
||||||
@tracked showMainButtons = true;
|
@tracked showMainButtons = true;
|
||||||
|
|
||||||
|
@tracked copyButtonIcon = "copy";
|
||||||
|
@tracked copyButtonLabel = "discourse_ai.ai_helper.post_options_menu.copy";
|
||||||
|
|
||||||
MENU_STATES = {
|
MENU_STATES = {
|
||||||
triggers: "TRIGGERS",
|
triggers: "TRIGGERS",
|
||||||
options: "OPTIONS",
|
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() {
|
async loadPrompts() {
|
||||||
let prompts = await ajax("/discourse-ai/ai-helper/prompts");
|
let prompts = await ajax("/discourse-ai/ai-helper/prompts");
|
||||||
|
|
||||||
|
@ -146,7 +165,18 @@ export default class AIHelperOptionsMenu extends Component {
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{{else if (eq this.menuState this.MENU_STATES.result)}}
|
{{else if (eq this.menuState this.MENU_STATES.result)}}
|
||||||
<div class="ai-post-helper__suggestion">{{this.suggestion}}</div>
|
<div class="ai-post-helper__suggestion">
|
||||||
|
<div class="ai-post-helper__suggestion__text">
|
||||||
|
{{this.suggestion}}
|
||||||
|
</div>
|
||||||
|
<DButton
|
||||||
|
@class="btn-flat ai-post-helper__suggestion__copy"
|
||||||
|
@icon={{this.copyButtonIcon}}
|
||||||
|
@label={{this.copyButtonLabel}}
|
||||||
|
@action={{this.copySuggestion}}
|
||||||
|
@disabled={{not this.suggestion}}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
|
@ -326,6 +326,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
&__suggestion {
|
&__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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,8 @@ en:
|
||||||
trigger: "Ask AI"
|
trigger: "Ask AI"
|
||||||
loading: "AI is generating"
|
loading: "AI is generating"
|
||||||
close: "Close"
|
close: "Close"
|
||||||
|
copy: "Copy"
|
||||||
|
copied: "Copied!"
|
||||||
reviewables:
|
reviewables:
|
||||||
model_used: "Model used:"
|
model_used: "Model used:"
|
||||||
accuracy: "Accuracy:"
|
accuracy: "Accuracy:"
|
||||||
|
|
Loading…
Reference in New Issue