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>
</mat-hint>
<mat-label>{{ 'Message' | translate }}</mat-label>
<mat-spinner *ngIf="messagePending" matSuffix diameter="30"></mat-spinner>
<button
mat-icon-button
matSuffix
type="submit"
color="accent"
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>
</button>

View File

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