Skip to content

Commit

Permalink
Closes Taskana#2563 - work in progress: debounceTime of type-ahead-co…
Browse files Browse the repository at this point in the history
…mponent
  • Loading branch information
MM1277 committed May 28, 2024
1 parent 6fd112f commit 329ffbc
Showing 1 changed file with 11 additions and 23 deletions.
34 changes: 11 additions & 23 deletions web/src/app/shared/components/type-ahead/type-ahead.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,7 @@ export class TypeAheadComponent implements OnInit, OnDestroy {
});
emptyAccessId: AccessId = { accessId: '', name: '' };

constructor(private accessIdService: AccessIdsService, private httpClient: HttpClient) {
this.httpClient
.get<Customisation>(customisationUrl)
.pipe(take(1))
.subscribe((customisation) => {
Object.keys(customisation).forEach((lang) => {
this.time = customisation[lang].workbaskets.time.debounceTime;
});
});
}
constructor(private accessIdService: AccessIdsService, private httpClient: HttpClient) {}

ngOnChanges(changes: SimpleChanges) {
// currently needed because when saving, workbasket-details components sends old workbasket which reverts changes in this component
Expand All @@ -59,6 +50,16 @@ export class TypeAheadComponent implements OnInit, OnDestroy {
}

ngOnInit() {
this.httpClient
.get<Customisation>(customisationUrl)
.pipe(take(1))
.subscribe((customisation) => {
Object.keys(customisation).forEach((lang) => {
this.time = customisation[lang].workbaskets.time.debounceTime;
this.accessIdValueChanges();
});
});

if (this.isDisabled) {
this.accessIdForm.controls['accessId'].disable();
}
Expand All @@ -69,19 +70,6 @@ export class TypeAheadComponent implements OnInit, OnDestroy {
this.accessIdForm.controls['accessId'].setValue(this.lastSavedAccessId);
}
});

this.accessIdForm.controls['accessId'].valueChanges
.pipe(debounceTime(this.time), distinctUntilChanged(), takeUntil(this.destroy$))
.subscribe(() => {
const value = this.accessIdForm.controls['accessId'].value;
if (value === '') {
this.handleEmptyAccessId();
return;
}
this.searchForAccessId(value);
});

this.setAccessIdFromInput();
}

accessIdValueChanges() {
Expand Down

0 comments on commit 329ffbc

Please sign in to comment.