added functions and web-socket to chat in group
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {IonicModule} from "@ionic/angular";
|
||||
import {Component, inject, input} from '@angular/core';
|
||||
import {IonicModule, LoadingController, ToastController} from "@ionic/angular";
|
||||
import {FormControl, FormGroup, ReactiveFormsModule, Validators} from "@angular/forms";
|
||||
import {addIcons} from "ionicons";
|
||||
import {sendOutline} from 'ionicons/icons';
|
||||
import {GetGroupDetailsDto, MessagesService} from "../../services/api";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
addIcons({
|
||||
"send-outline" : sendOutline
|
||||
})
|
||||
@@ -17,7 +19,48 @@ addIcons({
|
||||
]
|
||||
})
|
||||
export class MessageFormComponent {
|
||||
private messagesService = inject(MessagesService);
|
||||
private loadCtrl = inject(LoadingController);
|
||||
private toastCtrl = inject(ToastController);
|
||||
|
||||
groupId = input.required<GetGroupDetailsDto["id"]>();
|
||||
|
||||
messageForm: FormGroup = new FormGroup({
|
||||
libelle: new FormControl<string>(null, [Validators.required]),
|
||||
})
|
||||
|
||||
async sendMessageOnGroup(){
|
||||
const loading = await this.loadCtrl.create({
|
||||
message: 'Envoi...',
|
||||
spinner: 'lines-sharp-small'
|
||||
});
|
||||
await loading.present();
|
||||
|
||||
if (this.messageForm.invalid) {
|
||||
this.messageForm.reset();
|
||||
const toast = await this.toastCtrl.create({
|
||||
message: 'Message incorrect',
|
||||
duration: 2000,
|
||||
color: 'danger'
|
||||
});
|
||||
await toast.present();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.messagesService.sendMessageEndpoint(this.groupId(), this.messageForm.getRawValue()));
|
||||
this.messageForm.reset();
|
||||
}
|
||||
catch {
|
||||
const toast = await this.toastCtrl.create({
|
||||
message: 'Impossible d\'envoyer le messages.',
|
||||
duration: 2000,
|
||||
color: 'danger'
|
||||
});
|
||||
await toast.present();
|
||||
this.messageForm.reset();
|
||||
}
|
||||
await loading.dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user