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 a550b32
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,5 @@ describe('TypeAheadComponent with AccessId input', () => {
tick(750);
fixture.detectChanges();
expect(emitSpy).toHaveBeenCalledWith(true);
}));
}), 5000000);
});
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 a550b32

Please sign in to comment.