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

View File

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