From caaca29da9b5a1328fbf62f1fc0b1571902d1e1b Mon Sep 17 00:00:00 2001 From: guams Date: Wed, 7 May 2025 19:54:29 +0200 Subject: [PATCH] =?UTF-8?q?Fix:=20update=20de=20la=20photo=20de=20profil?= =?UTF-8?q?=20quand=20un=20commentaire=20est=20publi=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +-- .../comment-form/comment-form.component.ts | 30 +++++++++++++------ src/app/pages/new-post/new-post.component.ts | 1 - src/app/services/author.service.ts | 11 ++++++- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 68f1ce0..f7152d4 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ - [ ] Garder l'avatar de l'utilisateur quand il met à jour uniquement son pseudo - [ ] Ne pas avoir à confirmer son mot de passe lors de la connexion - [ ] Pouvoir modifier son commentaire -- [ ] L'avatar s'affiche pas quand on upload un commentaire (il faut recharger la page) +- [x] L'avatar s'affiche pas quand on upload un commentaire (il faut recharger la page) - [ ] Faire des meilleurs modal - [ ] Terminer l'interface admin -- [x] Bug (de temps en temps) pour stocker les cookies utilisateur +- [x] Bug (de temps en temps) pour stocker les données utilisateur pour run le docker : ``` diff --git a/src/app/components/comment-form/comment-form.component.ts b/src/app/components/comment-form/comment-form.component.ts index 50e783a..4fdd2a9 100644 --- a/src/app/components/comment-form/comment-form.component.ts +++ b/src/app/components/comment-form/comment-form.component.ts @@ -2,11 +2,12 @@ import {Component, EventEmitter, Input, Output} from '@angular/core'; import {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms'; import {Button} from 'primeng/button'; import {CommentService} from '../../services/comment.service'; -import {Subscription} from 'rxjs'; +import {Subscription, switchMap} from 'rxjs'; import {Comment} from '../../models/comment'; import {MessageService} from 'primeng/api'; import {NgStyle} from '@angular/common'; import {AuthService} from '../../auth.service'; +import {AuthorService} from '../../services/author.service'; @Component({ selector: 'app-comment-form', @@ -26,10 +27,12 @@ export class CommentFormComponent { @Input({required: true}) postId: bigint = BigInt(1); @Output() commentToEmit = new EventEmitter(); subs: Subscription[] = []; + createdComment: Comment = {} as Comment; constructor(private commentService: CommentService, private messageService: MessageService, - private authService: AuthService,) { + private authService: AuthService, + private authorService: AuthorService) { } onSubmit() { @@ -37,14 +40,23 @@ export class CommentFormComponent { let author = this.authService.getAuthenticatedAuthor(); if (this.commentForm.valid && author && token && this.commentForm.value.content) { // get l'image de profile après avoir créé le commentaire - this.subs.push(this.commentService.create(this.commentForm.value.content, this.postId, author.id, token).subscribe({ - next: (comment: Comment) => { - comment.authorId = author.id; - comment.authorName = author.name; - comment.profilePicture = author.profilePicture; - comment.authorRole = author.role; + this.subs.push(this.commentService.create(this.commentForm.value.content, this.postId, author.id, token).pipe( + switchMap((comment: Comment) => { + this.createdComment.authorId = author.id; + this.createdComment.content = comment.content; + this.createdComment.id = comment.id; + this.createdComment.commentDate = comment.commentDate; + this.createdComment.authorName = author.name; + this.createdComment.authorRole = author.role; this.commentForm.value.content = ""; - this.commentToEmit.emit(comment); + return this.authorService.getAvatar(author?.id) + }) + ).subscribe({ + next: (profilePicture: string) => { + this.createdComment.profilePicture = profilePicture; // c'est de la merde + this.commentForm.value.content = ""; + this.commentToEmit.emit(this.createdComment); + console.log(this.createdComment) this.successMessage("Succès", "Commentaire créé avec succès"); }, error: (error) => { diff --git a/src/app/pages/new-post/new-post.component.ts b/src/app/pages/new-post/new-post.component.ts index b235bc7..00c7bde 100644 --- a/src/app/pages/new-post/new-post.component.ts +++ b/src/app/pages/new-post/new-post.component.ts @@ -28,7 +28,6 @@ import {AuthService} from '../../auth.service'; styleUrl: './new-post.component.css' }) export class NewPostComponent implements OnDestroy { - isSessionExpired: EventEmitter = new EventEmitter(); subs: Subscription[] = [] actualAuthor: Author | undefined; uploadedFile: File | undefined; diff --git a/src/app/services/author.service.ts b/src/app/services/author.service.ts index f25fae1..910b955 100644 --- a/src/app/services/author.service.ts +++ b/src/app/services/author.service.ts @@ -62,6 +62,11 @@ export class AuthorService { } } + getAvatar(id: string): Observable { + return this.httpClient.get(`${this.apiUrl}/${id}/avatar`, { responseType: 'text' }); + } + + getAuthor(id: string | null): Observable { if (id) { return this.httpClient.get(`${this.apiUrl}/${id}`); @@ -89,7 +94,11 @@ export class AuthorService { 'Authorization': `Bearer ${token}` }) } - return this.httpClient.post(`${this.apiUrl}/register/admin`, {name: username, password: password, role: role}, httpOptions); + return this.httpClient.post(`${this.apiUrl}/register/admin`, { + name: username, + password: password, + role: role + }, httpOptions); } getAuthorAvatar(id: string) {