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