Fix: update de la photo de profil quand un commentaire est publié
This commit is contained in:
parent
2e357e1b59
commit
caaca29da9
@ -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 :
|
||||
```
|
||||
|
@ -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<Comment>();
|
||||
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) => {
|
||||
|
@ -28,7 +28,6 @@ import {AuthService} from '../../auth.service';
|
||||
styleUrl: './new-post.component.css'
|
||||
})
|
||||
export class NewPostComponent implements OnDestroy {
|
||||
isSessionExpired: EventEmitter<boolean> = new EventEmitter<boolean>();
|
||||
subs: Subscription[] = []
|
||||
actualAuthor: Author | undefined;
|
||||
uploadedFile: File | undefined;
|
||||
|
@ -62,6 +62,11 @@ export class AuthorService {
|
||||
}
|
||||
}
|
||||
|
||||
getAvatar(id: string): Observable<string> {
|
||||
return this.httpClient.get(`${this.apiUrl}/${id}/avatar`, { responseType: 'text' });
|
||||
}
|
||||
|
||||
|
||||
getAuthor(id: string | null): Observable<Author> {
|
||||
if (id) {
|
||||
return this.httpClient.get<Author>(`${this.apiUrl}/${id}`);
|
||||
@ -89,7 +94,11 @@ export class AuthorService {
|
||||
'Authorization': `Bearer ${token}`
|
||||
})
|
||||
}
|
||||
return this.httpClient.post<Author>(`${this.apiUrl}/register/admin`, {name: username, password: password, role: role}, httpOptions);
|
||||
return this.httpClient.post<Author>(`${this.apiUrl}/register/admin`, {
|
||||
name: username,
|
||||
password: password,
|
||||
role: role
|
||||
}, httpOptions);
|
||||
}
|
||||
|
||||
getAuthorAvatar(id: string) {
|
||||
|
Loading…
Reference in New Issue
Block a user