[angular-18 | DONE | FIXED]: natural-language-search.component.ts: Commented subscriptions and added nlSearchSubscription, to unsubscribe on every new request (if a new question responds before the previous question, then we would get not matching question-response or both (error case) at the same time).
This commit is contained in:
parent
fe792691a5
commit
ec2a7fbda1
|
@ -11,7 +11,8 @@ import {properties} from "../../environments/environment";
|
|||
})
|
||||
|
||||
export class NaturalLanguageSearchComponent {
|
||||
private subscriptions = [];
|
||||
// private subscriptions = [];
|
||||
private nlSearchSubscription = null;
|
||||
properties: EnvProperties = properties;
|
||||
showLoading: boolean = false;
|
||||
errorMessage: string;
|
||||
|
@ -25,18 +26,24 @@ export class NaturalLanguageSearchComponent {
|
|||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscriptions.forEach(subscription => {
|
||||
if (subscription instanceof Subscriber) {
|
||||
subscription.unsubscribe();
|
||||
}
|
||||
});
|
||||
// this.subscriptions.forEach(subscription => {
|
||||
// if (subscription instanceof Subscriber) {
|
||||
// subscription.unsubscribe();
|
||||
// }
|
||||
// });
|
||||
if (this.nlSearchSubscription instanceof Subscriber) {
|
||||
this.nlSearchSubscription.unsubscribe();
|
||||
}
|
||||
}
|
||||
|
||||
search() {
|
||||
this.queryPhrase = this.phrase;
|
||||
this.errorMessage = null;
|
||||
this.showLoading = true;
|
||||
this.subscriptions.push(this.naturalLanguageSearchService.getResults(this.properties.naturalLanguageSearchAPI, this.queryPhrase).subscribe(data => {
|
||||
if(this.nlSearchSubscription) {
|
||||
this.nlSearchSubscription.unsubscribe();
|
||||
}
|
||||
this.nlSearchSubscription = this.naturalLanguageSearchService.getResults(this.properties.naturalLanguageSearchAPI, this.queryPhrase).subscribe(data => {
|
||||
if(data && data['columns']) {
|
||||
for(let i = 0; i < data['columns'].length - 1; i++) {
|
||||
if(data['columns'][i] == 'id') {
|
||||
|
@ -54,6 +61,6 @@ export class NaturalLanguageSearchComponent {
|
|||
this.errorMessage = 'Sorry, something went wrong. Please try again later.';
|
||||
}
|
||||
this.showLoading = false;
|
||||
}));
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue