FIX: Subsequent results in full page search should re-trigger discovery (#1156)

This update fixes an issue where subsequent results in full page search were not trigger Discobot discoveries to search for the new result.
This commit is contained in:
Keegan George 2025-02-27 10:18:42 -08:00 committed by GitHub
parent e15952031d
commit a3fb5cdc21
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -21,6 +21,7 @@ export default class AiSearchDiscoveries extends Component {
@service search; @service search;
@service messageBus; @service messageBus;
@service discobotDiscoveries; @service discobotDiscoveries;
@service appEvents;
@tracked loadingDiscoveries = false; @tracked loadingDiscoveries = false;
@tracked hideDiscoveries = false; @tracked hideDiscoveries = false;
@ -34,6 +35,24 @@ export default class AiSearchDiscoveries extends Component {
typingTimer = null; typingTimer = null;
streamedTextLength = 0; streamedTextLength = 0;
constructor() {
super(...arguments);
this.appEvents.on(
"full-page-search:trigger-search",
this,
this.triggerDiscovery
);
}
willDestroy() {
super.willDestroy(...arguments);
this.appEvents.off(
"full-page-search:trigger-search",
this,
this.triggerDiscovery
);
}
typeCharacter() { typeCharacter() {
if (this.streamedTextLength < this.discobotDiscoveries.discovery.length) { if (this.streamedTextLength < this.discobotDiscoveries.discovery.length) {
this.streamedText += this.discobotDiscoveries.discovery.charAt( this.streamedText += this.discobotDiscoveries.discovery.charAt(
@ -48,11 +67,20 @@ export default class AiSearchDiscoveries extends Component {
} }
onTextUpdate() { onTextUpdate() {
this.cancelTypingTimer();
this.typeCharacter();
}
cancelTypingTimer() {
if (this.typingTimer) { if (this.typingTimer) {
cancel(this.typingTimer); cancel(this.typingTimer);
} }
}
this.typeCharacter(); resetStreaming() {
this.cancelTypingTimer();
this.streamedText = "";
this.streamedTextLength = 0;
} }
@bind @bind
@ -77,10 +105,7 @@ export default class AiSearchDiscoveries extends Component {
this.isStreaming = false; this.isStreaming = false;
// Clear pending animations // Clear pending animations
if (this.typingTimer) { this.cancelTypingTimer();
cancel(this.typingTimer);
this.typingTimer = null;
}
} else if (newText.length > this.discobotDiscoveries.discovery.length) { } else if (newText.length > this.discobotDiscoveries.discovery.length) {
this.discobotDiscoveries.discovery = newText; this.discobotDiscoveries.discovery = newText;
this.isStreaming = true; this.isStreaming = true;
@ -148,6 +173,7 @@ export default class AiSearchDiscoveries extends Component {
this.hideDiscoveries = false; this.hideDiscoveries = false;
return; return;
} else { } else {
this.resetStreaming();
this.discobotDiscoveries.resetDiscovery(); this.discobotDiscoveries.resetDiscovery();
} }