FIX: Un-clickable AI Results (#298)

This commit is contained in:
Keegan George 2023-11-20 11:37:00 -08:00 committed by GitHub
parent f7277d244e
commit 491111e5c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 6 deletions

View File

@ -29,7 +29,7 @@ export default class SemanticSearch extends Component {
{{if this.searching 'in-progress'}}"
>
<DToggleSwitch
disabled={{this.searching}}
disabled={{this.disableToggleSwitch}}
@state={{this.showingAIResults}}
title="AI search results hidden"
class="semantic-search__results-toggle"
@ -65,6 +65,12 @@ export default class SemanticSearch extends Component {
@tracked AIResults = [];
@tracked showingAIResults = false;
get disableToggleSwitch() {
if (this.searching || this.AIResults.length === 0) {
return true;
}
}
get searchStateText() {
if (this.searching) {
return I18n.t("discourse_ai.embeddings.semantic_search_loading");
@ -133,12 +139,18 @@ export default class SemanticSearch extends Component {
})
.then(async (results) => {
const model = (await translateResults(results)) || {};
const AIResults = model.posts.map(function (post) {
return Object.assign({}, post, { generatedByAI: true });
if (model.posts?.length === 0) {
this.searching = false;
return;
}
model.posts.forEach((post) => {
post.generatedByAI = true;
});
this.args.outletArgs.addSearchResults(AIResults, "topic_id");
this.AIResults = AIResults;
this.args.outletArgs.addSearchResults(model.posts, "topic_id");
this.AIResults = model.posts;
})
.catch(popupAjaxError)
.finally(() => (this.searching = false));

View File

@ -62,7 +62,6 @@
.ai-result {
display: none;
background: var(--tertiary-very-low);
border-radius: var(--d-border-radius);
.ai-result__icon {