Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.

Commit 1cbace4

Browse files
committed
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.
1 parent 5264641 commit 1cbace4

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

assets/javascripts/discourse/components/ai-search-discoveries.gjs

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default class AiSearchDiscoveries extends Component {
2121
@service search;
2222
@service messageBus;
2323
@service discobotDiscoveries;
24+
@service appEvents;
2425

2526
@tracked loadingDiscoveries = false;
2627
@tracked hideDiscoveries = false;
@@ -34,6 +35,24 @@ export default class AiSearchDiscoveries extends Component {
3435
typingTimer = null;
3536
streamedTextLength = 0;
3637

38+
constructor() {
39+
super(...arguments);
40+
this.appEvents.on(
41+
"full-page-search:trigger-search",
42+
this,
43+
this.triggerDiscovery
44+
);
45+
}
46+
47+
willDestroy() {
48+
super.willDestroy(...arguments);
49+
this.appEvents.off(
50+
"full-page-search:trigger-search",
51+
this,
52+
this.triggerDiscovery
53+
);
54+
}
55+
3756
typeCharacter() {
3857
if (this.streamedTextLength < this.discobotDiscoveries.discovery.length) {
3958
this.streamedText += this.discobotDiscoveries.discovery.charAt(
@@ -48,11 +67,20 @@ export default class AiSearchDiscoveries extends Component {
4867
}
4968

5069
onTextUpdate() {
70+
this.cancelTypingTimer();
71+
this.typeCharacter();
72+
}
73+
74+
cancelTypingTimer() {
5175
if (this.typingTimer) {
5276
cancel(this.typingTimer);
5377
}
78+
}
5479

55-
this.typeCharacter();
80+
resetStreaming() {
81+
this.cancelTypingTimer();
82+
this.streamedText = "";
83+
this.streamedTextLength = 0;
5684
}
5785

5886
@bind
@@ -77,10 +105,7 @@ export default class AiSearchDiscoveries extends Component {
77105
this.isStreaming = false;
78106

79107
// Clear pending animations
80-
if (this.typingTimer) {
81-
cancel(this.typingTimer);
82-
this.typingTimer = null;
83-
}
108+
this.cancelTypingTimer();
84109
} else if (newText.length > this.discobotDiscoveries.discovery.length) {
85110
this.discobotDiscoveries.discovery = newText;
86111
this.isStreaming = true;
@@ -148,6 +173,7 @@ export default class AiSearchDiscoveries extends Component {
148173
this.hideDiscoveries = false;
149174
return;
150175
} else {
176+
this.resetStreaming();
151177
this.discobotDiscoveries.resetDiscovery();
152178
}
153179

0 commit comments

Comments
 (0)