From a3ce251c2be1cb7eb5ef26c9e3d5a3693f30437d Mon Sep 17 00:00:00 2001 From: Angular2guy Date: Tue, 14 Nov 2023 20:48:18 +0100 Subject: [PATCH] fix: frontend --- .../angular/src/app/doc-search/doc-search.component.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/frontend/src/angular/src/app/doc-search/doc-search.component.ts b/frontend/src/angular/src/app/doc-search/doc-search.component.ts index c482f9b..84c9e8c 100644 --- a/frontend/src/angular/src/app/doc-search/doc-search.component.ts +++ b/frontend/src/angular/src/app/doc-search/doc-search.component.ts @@ -24,7 +24,7 @@ import { DocumentSearch } from '../model/documents'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { map, tap } from 'rxjs/operators'; import {MatProgressSpinnerModule} from '@angular/material/progress-spinner'; -import { interval } from 'rxjs'; +import { Subscription, interval } from 'rxjs'; @Component({ @@ -39,6 +39,7 @@ export class DocSearchComponent { protected searchResults: string[] = []; protected searching = false; protected msWorking = 0; + private repeatSub: Subscription | null = null; constructor(private destroyRef: DestroyRef, private router: Router, private documentService: DocumentService) { } @@ -51,13 +52,14 @@ export class DocSearchComponent { const startDate = new Date(); this.msWorking = 0; this.searching = true; - const repeatSub = interval(100).pipe(map(() => new Date())).subscribe(newDate => this.msWorking = newDate.getTime() - startDate.getTime()); + this.repeatSub?.unsubscribe(); + this.repeatSub = interval(100).pipe(map(() => new Date()), takeUntilDestroyed(this.destroyRef)).subscribe(newDate => this.msWorking = newDate.getTime() - startDate.getTime()); const documentSearch = {searchString: this.searchValueControl.value} as DocumentSearch; this.documentService.postDocumentSearch(documentSearch) - .pipe(takeUntilDestroyed(this.destroyRef), tap(() => this.searching = false), tap(() => repeatSub.unsubscribe())) + .pipe(takeUntilDestroyed(this.destroyRef), tap(() => this.searching = false), tap(() => this.repeatSub?.unsubscribe())) .subscribe(result => { this.searchResults = result.resultStrings; - //console.log(this.searchResults); + console.log(this.searchResults); }); }