Debut parametres profil
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import {Component, inject, signal} from '@angular/core';
|
||||
import {Component, inject, OnInit, signal} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormsModule } from '@angular/forms';
|
||||
import {firstValueFrom} from "rxjs";
|
||||
@@ -12,7 +12,7 @@ import {AuthService} from "../../../core/auth/auth.service";
|
||||
templateUrl: './parameters-profile.component.html',
|
||||
styleUrl: './parameters-profile.component.css'
|
||||
})
|
||||
export class ParametersProfileComponent {
|
||||
export class ParametersProfileComponent implements OnInit {
|
||||
private usersService = inject(UsersService);
|
||||
private authService = inject(AuthService);
|
||||
|
||||
@@ -33,6 +33,7 @@ export class ParametersProfileComponent {
|
||||
this.bio.set(user?.description ?? null);
|
||||
}
|
||||
|
||||
// --- Username ---
|
||||
|
||||
toggleEditUsername() {
|
||||
if (this.editingUsername()) {
|
||||
@@ -57,9 +58,13 @@ export class ParametersProfileComponent {
|
||||
|
||||
this.loading.set(true);
|
||||
const user = this.authService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.usersService.patchUsernameEndpoint(user.id, { username: value }));
|
||||
await firstValueFrom(this.usersService.patchUsernameEndpoint(
|
||||
String(user.id), { username: value }
|
||||
));
|
||||
this.authService.updateCurrentUser({ username: value }); // 👈 maj locale
|
||||
this.usernameError.set(null);
|
||||
this.editingUsername.set(false);
|
||||
} catch (e: any) {
|
||||
@@ -73,7 +78,7 @@ export class ParametersProfileComponent {
|
||||
this.loading.set(false);
|
||||
}
|
||||
|
||||
|
||||
// --- Bio ---
|
||||
|
||||
toggleEditBio() {
|
||||
if (this.editingBio()) {
|
||||
@@ -86,9 +91,13 @@ export class ParametersProfileComponent {
|
||||
async submitBio() {
|
||||
this.loading.set(true);
|
||||
const user = this.authService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.usersService.patchUserDescriptionEndpoint(user.id, { description: this.bio() }));
|
||||
await firstValueFrom(this.usersService.patchUserDescriptionEndpoint(
|
||||
String(user.id), { description: this.bio() }
|
||||
));
|
||||
this.authService.updateCurrentUser({ description: this.bio() }); // 👈 maj locale
|
||||
this.editingBio.set(false);
|
||||
} catch (e) {
|
||||
console.error('Erreur lors de la mise à jour de la bio', e);
|
||||
@@ -97,6 +106,7 @@ export class ParametersProfileComponent {
|
||||
this.loading.set(false);
|
||||
}
|
||||
|
||||
// --- Photo ---
|
||||
|
||||
triggerFileInput() {
|
||||
document.getElementById('photoInput')?.click();
|
||||
@@ -113,9 +123,13 @@ export class ParametersProfileComponent {
|
||||
|
||||
this.loading.set(true);
|
||||
const user = this.authService.currentUser();
|
||||
if (!user) return;
|
||||
|
||||
try {
|
||||
await firstValueFrom(this.usersService.patchUserProfilePictureEndpoint(user.id, { profilePicture: base64 }));
|
||||
await firstValueFrom(this.usersService.patchUserProfilePictureEndpoint(
|
||||
String(user.id), { profilePicture: base64 }
|
||||
));
|
||||
this.authService.updateCurrentUser({ profilePicture: base64 }); // 👈 maj locale
|
||||
} catch (e) {
|
||||
console.error('Erreur lors de la mise à jour de la photo', e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user