From 49ea1a990627fd98263f7706790801a0c071894d Mon Sep 17 00:00:00 2001 From: Zemke Date: Fri, 10 Nov 2023 13:00:30 +0100 Subject: [PATCH] Don't spam the request --- .../webapp/app/message/chat-input.component.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/cwt-angular/src/main/webapp/app/message/chat-input.component.ts b/cwt-angular/src/main/webapp/app/message/chat-input.component.ts index 113a4bc4..9dde1ffc 100644 --- a/cwt-angular/src/main/webapp/app/message/chat-input.component.ts +++ b/cwt-angular/src/main/webapp/app/message/chat-input.component.ts @@ -25,6 +25,8 @@ export class ChatInputComponent { @ViewChild('tagbox') tagbox: ElementRef; @ViewChild('valueEl') valueEl: ElementRef; + private users: UserMinimalDto[]; + value = ''; recipients: number[] = []; _disabled = false; @@ -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("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("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) {