Skip to content
Snippets Groups Projects
Commit 3b5dd56d authored by OZGCloud's avatar OZGCloud
Browse files

OZG-6169 CR Anmerkung

parent 5952786c
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ import { Injectable, OnDestroy } from '@angular/core';
import { FormGroup, UntypedFormBuilder, UntypedFormControl } from '@angular/forms';
import { Params } from '@angular/router';
import { isEmpty } from 'lodash-es';
import { BehaviorSubject, combineLatest, Observable, Subscription } from 'rxjs';
import { filter, Observable, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, first, tap } from 'rxjs/operators';
@Injectable()
......@@ -44,7 +44,7 @@ export class VorgangSearchFormService implements OnDestroy {
public lastSearchString: string;
public hasSearchString: boolean = false;
private lastKeyPressed: BehaviorSubject<string> = new BehaviorSubject<string>(EMPTY_STRING);
private lastKeyPressed: string;
constructor(
private formBuilder: UntypedFormBuilder,
......@@ -68,15 +68,15 @@ export class VorgangSearchFormService implements OnDestroy {
}
subscribeToValueChanges(): void {
this.fromControlSubscription = combineLatest(
this.lastKeyPressed.asObservable(),
this.getSearchFormControl().valueChanges.pipe(
this.fromControlSubscription = this.getSearchFormControl()
.valueChanges.pipe(
distinctUntilChanged(),
debounceTime(300),
tap((value) => this.setHasSearchString(value)),
),
).subscribe(([lastKeyPressed, value]) => {
if (lastKeyPressed !== 'Enter') this.handleValueChanges(value);
filter(() => this.lastKeyPressedIsNotEnter()),
)
.subscribe((value) => {
this.handleValueChanges(value);
});
}
......@@ -84,6 +84,10 @@ export class VorgangSearchFormService implements OnDestroy {
this.hasSearchString = isNotEmpty(value);
}
private lastKeyPressedIsNotEnter(): boolean {
return this.lastKeyPressed !== 'Enter';
}
handleValueChanges(value: string): void {
if (this.shouldSearchForPreview(value)) {
this.vorgangListService.setSearchString(value);
......@@ -171,6 +175,6 @@ export class VorgangSearchFormService implements OnDestroy {
}
public setLastKeyPressed(key: string): void {
this.lastKeyPressed.next(key);
this.lastKeyPressed = key;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment