Merge pull request #6100 from tsiegleauq/pending-chat

Add pending state for chat message
This commit is contained in:
Emanuel Schütze 2021-06-03 20:53:49 +02:00 committed by GitHub
commit 7a076b1d2d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -34,13 +34,15 @@
</span> </span>
</mat-hint> </mat-hint>
<mat-label>{{ 'Message' | translate }}</mat-label> <mat-label>{{ 'Message' | translate }}</mat-label>
<mat-spinner *ngIf="messagePending" matSuffix diameter="30"></mat-spinner>
<button <button
mat-icon-button mat-icon-button
matSuffix matSuffix
type="submit" type="submit"
color="accent" color="accent"
matTooltip=" {{ 'Send' | translate }}" matTooltip=" {{ 'Send' | translate }}"
[disabled]="!chatinput.value?.trim()?.length || newMessageForm.invalid" *ngIf="!messagePending"
[disabled]="!chatinput.value?.trim()?.length || newMessageForm.invalid || messagePending"
> >
<mat-icon>send</mat-icon> <mat-icon>send</mat-icon>
</button> </button>

View File

@ -26,6 +26,7 @@ import { ViewChatGroup } from '../../models/view-chat-group';
export class ChatTabsComponent extends BaseViewComponentDirective implements OnInit { export class ChatTabsComponent extends BaseViewComponentDirective implements OnInit {
public chatGroupSubject: BehaviorSubject<ViewChatGroup[]>; public chatGroupSubject: BehaviorSubject<ViewChatGroup[]>;
public newMessageForm: FormGroup; public newMessageForm: FormGroup;
public messagePending = false;
private messageControl: AbstractControl; private messageControl: AbstractControl;
public chatMessageMaxLength = 512; public chatMessageMaxLength = 512;
private selectedTabIndex = 0; private selectedTabIndex = 0;
@ -91,8 +92,12 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI
} }
public send(): void { public send(): void {
if (this.messagePending) {
return;
}
const message = this.messageControl.value?.trim(); const message = this.messageControl.value?.trim();
if (message) { if (message) {
this.messagePending = true;
const payload = { const payload = {
text: message, text: message,
chatgroup_id: this.chatGroupFromIndex.id chatgroup_id: this.chatGroupFromIndex.id
@ -102,6 +107,9 @@ export class ChatTabsComponent extends BaseViewComponentDirective implements OnI
.then(() => { .then(() => {
this.clearTextInput(); this.clearTextInput();
}) })
.finally(() => {
this.messagePending = false;
})
.catch(this.raiseError); .catch(this.raiseError);
} }
} }