FIX: Show warning when trying to generate suggestions without content (#175)
This commit is contained in:
parent
494964c51d
commit
4da4b5609f
|
@ -6,6 +6,9 @@ import { ajax } from "discourse/lib/ajax";
|
||||||
import { popupAjaxError } from "discourse/lib/ajax-error";
|
import { popupAjaxError } from "discourse/lib/ajax-error";
|
||||||
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
|
||||||
import { bind } from "discourse-common/utils/decorators";
|
import { bind } from "discourse-common/utils/decorators";
|
||||||
|
import { inject as service } from "@ember/service";
|
||||||
|
import I18n from "I18n";
|
||||||
|
|
||||||
|
|
||||||
export default class AITitleSuggester extends Component {
|
export default class AITitleSuggester extends Component {
|
||||||
<template>
|
<template>
|
||||||
|
@ -33,6 +36,7 @@ export default class AITitleSuggester extends Component {
|
||||||
{{/if}}
|
{{/if}}
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@service dialog;
|
||||||
@tracked loading = false;
|
@tracked loading = false;
|
||||||
@tracked showMenu = false;
|
@tracked showMenu = false;
|
||||||
@tracked generatedTitleSuggestions = [];
|
@tracked generatedTitleSuggestions = [];
|
||||||
|
@ -50,7 +54,7 @@ export default class AITitleSuggester extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
get composerInput() {
|
get composerInput() {
|
||||||
return document.querySelector(".d-editor-input").value || this.args.outletArgs.composer.reply;
|
return document.querySelector(".d-editor-input")?.value || this.args.outletArgs.composer.reply;
|
||||||
}
|
}
|
||||||
|
|
||||||
get disableSuggestionButton() {
|
get disableSuggestionButton() {
|
||||||
|
@ -90,6 +94,10 @@ export default class AITitleSuggester extends Component {
|
||||||
|
|
||||||
@action
|
@action
|
||||||
async suggestTitles() {
|
async suggestTitles() {
|
||||||
|
if (this.composerInput?.length === 0) {
|
||||||
|
return this.dialog.alert(I18n.t("discourse_ai.ai_helper.missing_content"));
|
||||||
|
}
|
||||||
|
|
||||||
this.loading = true;
|
this.loading = true;
|
||||||
this.suggestTitleIcon = "spinner";
|
this.suggestTitleIcon = "spinner";
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,7 @@ en:
|
||||||
description: "Choose one of the options below, and the AI will suggest you a new version of the text."
|
description: "Choose one of the options below, and the AI will suggest you a new version of the text."
|
||||||
selection_hint: "Hint: You can also select a portion of the text before opening the helper to rewrite only that."
|
selection_hint: "Hint: You can also select a portion of the text before opening the helper to rewrite only that."
|
||||||
suggest_titles: "Suggest titles with AI"
|
suggest_titles: "Suggest titles with AI"
|
||||||
|
missing_content: "Please enter some content to generate suggestions."
|
||||||
context_menu:
|
context_menu:
|
||||||
trigger: "AI"
|
trigger: "AI"
|
||||||
undo: "Undo"
|
undo: "Undo"
|
||||||
|
|
Loading…
Reference in New Issue