FIX: Show warning when trying to generate suggestions without content (#175)

This commit is contained in:
Keegan George 2023-08-29 11:58:45 -07:00 committed by GitHub
parent 494964c51d
commit 4da4b5609f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View File

@ -6,6 +6,9 @@ import { ajax } from "discourse/lib/ajax";
import { popupAjaxError } from "discourse/lib/ajax-error";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import { bind } from "discourse-common/utils/decorators";
import { inject as service } from "@ember/service";
import I18n from "I18n";
export default class AITitleSuggester extends Component {
<template>
@ -33,6 +36,7 @@ export default class AITitleSuggester extends Component {
{{/if}}
</template>
@service dialog;
@tracked loading = false;
@tracked showMenu = false;
@tracked generatedTitleSuggestions = [];
@ -50,7 +54,7 @@ export default class AITitleSuggester extends Component {
}
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() {
@ -90,6 +94,10 @@ export default class AITitleSuggester extends Component {
@action
async suggestTitles() {
if (this.composerInput?.length === 0) {
return this.dialog.alert(I18n.t("discourse_ai.ai_helper.missing_content"));
}
this.loading = true;
this.suggestTitleIcon = "spinner";

View File

@ -17,6 +17,7 @@ en:
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."
suggest_titles: "Suggest titles with AI"
missing_content: "Please enter some content to generate suggestions."
context_menu:
trigger: "AI"
undo: "Undo"