feat(header): afficher la photo de profil a la place des initiales
PR — Ouverture automatique / create-pr (push) Successful in 2s
PR — Ouverture automatique / create-pr (push) Successful in 2s
/auth/me renvoie desormais has_avatar et avatar_updated_at (LEFT JOIN user_avatars). Le header affiche l'avatar avec un cache-buster sur updated_at, et retombe sur les initiales en cas d'absence ou d'echec. Le profil rafraichit la session apres ajout/retrait de l'avatar pour que le header se mette a jour immediatement.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { useState } from "react";
|
||||
import { NavLink, Outlet } from "react-router-dom";
|
||||
import { Button, cn } from "../ui/index.js";
|
||||
import { api } from "../lib/api.js";
|
||||
import { useSession } from "../lib/session.js";
|
||||
import {
|
||||
ActivityIcon,
|
||||
@@ -127,10 +128,20 @@ export const AppShell = () => {
|
||||
</p>
|
||||
</div>
|
||||
<span
|
||||
className="flex h-9 w-9 shrink-0 items-center justify-center rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
className="relative flex h-9 w-9 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-surface text-xs font-semibold text-foreground"
|
||||
aria-hidden="true"
|
||||
>
|
||||
{initials(user.first_name, user.last_name)}
|
||||
{user.has_avatar ? (
|
||||
<img
|
||||
src={`${api.avatarUrl(user.id)}?v=${encodeURIComponent(user.avatar_updated_at ?? "")}`}
|
||||
alt=""
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
onError={(event) => {
|
||||
event.currentTarget.style.display = "none";
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
</span>
|
||||
<Button
|
||||
variant="secondary"
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface User {
|
||||
used_bytes: number;
|
||||
max_file_bytes: number;
|
||||
must_change_password: boolean;
|
||||
has_avatar: boolean;
|
||||
avatar_updated_at: string | null;
|
||||
}
|
||||
|
||||
export interface Folder {
|
||||
|
||||
@@ -91,6 +91,7 @@ export const Profile = () => {
|
||||
try {
|
||||
await api.uploadAvatar(file);
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
|
||||
} finally {
|
||||
@@ -103,6 +104,7 @@ export const Profile = () => {
|
||||
try {
|
||||
await api.deleteAvatar();
|
||||
setAvatarNonce((value) => value + 1);
|
||||
await refresh();
|
||||
} catch (caught) {
|
||||
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user