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
|
- [ ] 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
|
- [ ] Ne pas avoir à confirmer son mot de passe lors de la connexion
|
||||||
- [ ] Pouvoir modifier son commentaire
|
- [ ] 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
|
- [ ] Faire des meilleurs modal
|
||||||
- [ ] Terminer l'interface admin
|
- [ ] 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 :
|
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 {FormControl, FormGroup, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||||
import {Button} from 'primeng/button';
|
import {Button} from 'primeng/button';
|
||||||
import {CommentService} from '../../services/comment.service';
|
import {CommentService} from '../../services/comment.service';
|
||||||
import {Subscription} from 'rxjs';
|
import {Subscription, switchMap} from 'rxjs';
|
||||||
import {Comment} from '../../models/comment';
|
import {Comment} from '../../models/comment';
|
||||||
import {MessageService} from 'primeng/api';
|
import {MessageService} from 'primeng/api';
|
||||||
import {NgStyle} from '@angular/common';
|
import {NgStyle} from '@angular/common';
|
||||||
import {AuthService} from '../../auth.service';
|
import {AuthService} from '../../auth.service';
|
||||||
|
import {AuthorService} from '../../services/author.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-comment-form',
|
selector: 'app-comment-form',
|
||||||
@ -26,10 +27,12 @@ export class CommentFormComponent {
|
|||||||
@Input({required: true}) postId: bigint = BigInt(1);
|
@Input({required: true}) postId: bigint = BigInt(1);
|
||||||
@Output() commentToEmit = new EventEmitter<Comment>();
|
@Output() commentToEmit = new EventEmitter<Comment>();
|
||||||
subs: Subscription[] = [];
|
subs: Subscription[] = [];
|
||||||
|
createdComment: Comment = {} as Comment;
|
||||||
|
|
||||||
constructor(private commentService: CommentService,
|
constructor(private commentService: CommentService,
|
||||||
private messageService: MessageService,
|
private messageService: MessageService,
|
||||||
private authService: AuthService,) {
|
private authService: AuthService,
|
||||||
|
private authorService: AuthorService) {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
@ -37,14 +40,23 @@ export class CommentFormComponent {
|
|||||||
let author = this.authService.getAuthenticatedAuthor();
|
let author = this.authService.getAuthenticatedAuthor();
|
||||||
if (this.commentForm.valid && author && token && this.commentForm.value.content) {
|
if (this.commentForm.valid && author && token && this.commentForm.value.content) {
|
||||||
// get l'image de profile après avoir créé le commentaire
|
// 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({
|
this.subs.push(this.commentService.create(this.commentForm.value.content, this.postId, author.id, token).pipe(
|
||||||
next: (comment: Comment) => {
|
switchMap((comment: Comment) => {
|
||||||
comment.authorId = author.id;
|
this.createdComment.authorId = author.id;
|
||||||
comment.authorName = author.name;
|
this.createdComment.content = comment.content;
|
||||||
comment.profilePicture = author.profilePicture;
|
this.createdComment.id = comment.id;
|
||||||
comment.authorRole = author.role;
|
this.createdComment.commentDate = comment.commentDate;
|
||||||
|
this.createdComment.authorName = author.name;
|
||||||
|
this.createdComment.authorRole = author.role;
|
||||||
this.commentForm.value.content = "";
|
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");
|
this.successMessage("Succès", "Commentaire créé avec succès");
|
||||||
},
|
},
|
||||||
error: (error) => {
|
error: (error) => {
|
||||||
|
@ -28,7 +28,6 @@ import {AuthService} from '../../auth.service';
|
|||||||
styleUrl: './new-post.component.css'
|
styleUrl: './new-post.component.css'
|
||||||
})
|
})
|
||||||
export class NewPostComponent implements OnDestroy {
|
export class NewPostComponent implements OnDestroy {
|
||||||
isSessionExpired: EventEmitter<boolean> = new EventEmitter<boolean>();
|
|
||||||
subs: Subscription[] = []
|
subs: Subscription[] = []
|
||||||
actualAuthor: Author | undefined;
|
actualAuthor: Author | undefined;
|
||||||
uploadedFile: File | 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> {
|
getAuthor(id: string | null): Observable<Author> {
|
||||||
if (id) {
|
if (id) {
|
||||||
return this.httpClient.get<Author>(`${this.apiUrl}/${id}`);
|
return this.httpClient.get<Author>(`${this.apiUrl}/${id}`);
|
||||||
@ -89,7 +94,11 @@ export class AuthorService {
|
|||||||
'Authorization': `Bearer ${token}`
|
'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) {
|
getAuthorAvatar(id: string) {
|
||||||
|
Loading…
Reference in New Issue
Block a user