Skip to content

Commit

Permalink
Don't spam the request
Browse files Browse the repository at this point in the history
  • Loading branch information
Zemke committed Nov 10, 2023
1 parent e55e54d commit 49ea1a9
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions cwt-angular/src/main/webapp/app/message/chat-input.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export class ChatInputComponent {
@ViewChild('tagbox') tagbox: ElementRef<ZemkeTagboxElement>;
@ViewChild('valueEl') valueEl: ElementRef<HTMLInputElement>;

private users: UserMinimalDto[];

value = '';
recipients: number[] = [];
_disabled = false;
Expand Down Expand Up @@ -71,12 +73,16 @@ export class ChatInputComponent {
});
}

lazyLoad(e: KeyboardEvent) {
async lazyLoad(e: KeyboardEvent) {
if (!(e.target as HTMLInputElement).value.includes('@')) return;
this.requestService.get<UserMinimalDto[]>("user", {minimal: "true"}).toPromise()
.then(users => this.suggestions.push(
...users.filter(user =>
!this.suggestions.map(u => u.id).includes(user.id) && user.id !== this.authUser.id)));
if (!this.users) {
this.users = await this.requestService.get<UserMinimalDto[]>("user", {minimal: "true"})
.toPromise();
console.log('req users', this.users);
}
this.suggestions.push(
...this.users.filter(user =>
!this.suggestions.map(u => u.id).includes(user.id) && user.id !== this.authUser.id));
}

submit(valid: boolean) {
Expand Down

0 comments on commit 49ea1a9

Please sign in to comment.