From e18eced2408f672efb06ac2885fe052846ff15ec Mon Sep 17 00:00:00 2001 From: FazCodeFR <30906528+FazCodeFR@users.noreply.github.com> Date: Tue, 16 Jul 2024 21:00:46 +0200 Subject: [PATCH] update message --- src/app/app-routing.module.ts | 5 +++ .../associations-details.component.html | 5 ++- .../tchat-message.component.html | 43 +++++++++++-------- .../tchat-message/tchat-message.component.ts | 24 ++++++++--- src/app/interfaces/interfaces.ts | 1 + src/app/services/user.service.ts | 7 ++- 6 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/app/app-routing.module.ts b/src/app/app-routing.module.ts index c599cc9..b01099d 100644 --- a/src/app/app-routing.module.ts +++ b/src/app/app-routing.module.ts @@ -72,6 +72,11 @@ const routes: Routes = [ path: 'mentions-legales', component: CguComponent, }, + { + path: 'tchat/:id', + component: TchatComponent, + canActivate: [AuthGuard], + }, { path: 'tchat', component: TchatComponent, diff --git a/src/app/components/associations/associations-details/associations-details.component.html b/src/app/components/associations/associations-details/associations-details.component.html index 7b7d386..e954df7 100644 --- a/src/app/components/associations/associations-details/associations-details.component.html +++ b/src/app/components/associations/associations-details/associations-details.component.html @@ -141,8 +141,9 @@

- Contacter {{asso.nom }} + class="flex mx-auto mt-16 text-white bg-indigo-500 border-0 py-2 px-8 focus:outline-none hover:bg-indigo-600 rounded text-lg" + [routerLink]="['/tchat', asso.id]"> + Contacter {{asso.nom }} \ No newline at end of file diff --git a/src/app/components/tchat/tchat-message/tchat-message.component.html b/src/app/components/tchat/tchat-message/tchat-message.component.html index 5fb5d3d..fee0f26 100644 --- a/src/app/components/tchat/tchat-message/tchat-message.component.html +++ b/src/app/components/tchat/tchat-message/tchat-message.component.html @@ -1,33 +1,40 @@ -
+
- +

{{selectedConversation!.nom}}

+

{{selectedConversation!.nom}}

-
- -
-
- ... +
+
+ +
+
+ ... +
+
+

{{ msg.contenu + ' (receveur)' }}

+
-
-

{{ msg.contenu + ' (receveur)' }}

-
-
- -
-
-

{{ msg.contenu + ' (envoyeur)' }}

-
-
- ... + +
+
+

{{ msg.contenu + ' (envoyeur)' }}

+
+
+ ... + ... +
+ +

Merci d'écrire votre message

+
diff --git a/src/app/components/tchat/tchat-message/tchat-message.component.ts b/src/app/components/tchat/tchat-message/tchat-message.component.ts index 284ceae..56c6f5e 100644 --- a/src/app/components/tchat/tchat-message/tchat-message.component.ts +++ b/src/app/components/tchat/tchat-message/tchat-message.component.ts @@ -5,6 +5,7 @@ import { WebSocketService } from '../../../services/web-socket.service'; import { Message } from '../../../interfaces/interfaces'; import { Conversation } from '../../../interfaces/interfaces'; import { UserService } from '../../../services/user.service'; +import { ActivatedRoute } from '@angular/router'; @Component({ selector: 'app-tchat-message', @@ -15,6 +16,7 @@ export class TchatMessageComponent implements OnInit, OnChanges { @Input() selectedConversation: Conversation | null = null; associationId: number = 1; // Remplacez par l'ID de l'association appropriée + idFromUrl: number | null = null; isAssociation = false; utilisateurId: number = 1; // Remplacez par l'ID de l'utilisateur approprié message = ''; @@ -23,23 +25,35 @@ export class TchatMessageComponent implements OnInit, OnChanges { constructor( public auth: AuthService, private appService: AppService, - private webSocketService: WebSocketService + private webSocketService: WebSocketService, + private route: ActivatedRoute ) {} ngOnInit(): void { - this.loadMessages(); + this.route.params.subscribe(params => { + const idFromUrl = params['id']; + if (idFromUrl) { + this.idFromUrl = +idFromUrl; + this.associationId = this.idFromUrl; + this.loadMessages(); + this.appService.getByIdAsso(this.idFromUrl).subscribe((association) => { + this.selectedConversation = association as unknown as Conversation; + }); + } + }); } ngOnChanges(changes: SimpleChanges): void { if (changes['selectedConversation'] && this.selectedConversation) { - console.log('🚀 ~ TchatMessageComponent ~ ngOnChanges ~ this.selectedConversation:', this.selectedConversation); + this.isAssociation = !!this.selectedConversation.img ? true : false; + console.log('🚀 ~ TchatMessageComponent ~ ngOnChanges ~ this.isAssociation:', this.isAssociation); + this.associationId = this.selectedConversation.id; this.loadMessages(); } } loadMessages(): void { - if (this.selectedConversation) { - this.associationId = this.selectedConversation.id; + if (this.selectedConversation || this.idFromUrl) { this.appService.getMessages(this.utilisateurId, this.associationId).subscribe((messages: Message[]) => { this.messages = messages; console.log('🚀 ~ TchatMessageComponent ~ this.appService.getMessages ~ this.messages:', this.messages); diff --git a/src/app/interfaces/interfaces.ts b/src/app/interfaces/interfaces.ts index d038ceb..7142711 100644 --- a/src/app/interfaces/interfaces.ts +++ b/src/app/interfaces/interfaces.ts @@ -142,4 +142,5 @@ export interface Conversation { img?: string; messages: Message[]; photos?: Photo[]; + associationId?: number; } \ No newline at end of file diff --git a/src/app/services/user.service.ts b/src/app/services/user.service.ts index 7dee400..ef3cfa9 100644 --- a/src/app/services/user.service.ts +++ b/src/app/services/user.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable, map, share, take } from 'rxjs'; import { AuthService } from '@auth0/auth0-angular'; -import { Conversation, UserRole } from '../interfaces/interfaces'; +import { Conversation, UserRole, Utilisateur } from '../interfaces/interfaces'; import { environment } from 'src/environments/environment'; @Injectable({ @@ -13,6 +13,7 @@ export class UserService { public isAsso = false; public isUser = false; api = environment.urlAPI; + public user: Utilisateur | null = null; constructor( private http: HttpClient, @@ -30,6 +31,10 @@ export class UserService { } this.isAsso = this.isRole(roles, UserRole.Asso); this.isUser = true; + + this.getMeInfo().subscribe((res) => { + this.user = res; + }); } }); }