feat(header): afficher la photo de profil a la place des initiales (#6)
CD — Déploiement / deploy (push) Successful in 20s

/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.

---------

Co-authored-by: xEsiah <[email protected]>
Reviewed-on: #6
Reviewed-by: Esiah <[email protected]>
Co-authored-by: Gitea Actions <-[email protected]>
This commit was merged in pull request #6.
This commit is contained in:
Gitea Actions
2026-10-16 11:44:34 +00:00
committed by Esiah
co-authored by Esiah
parent 284646562b
commit c5df5c05f1
4 changed files with 24 additions and 4 deletions
+8 -3
View File
@@ -46,6 +46,7 @@ interface UserRow {
max_file_bytes: number; max_file_bytes: number;
must_change_password: number; must_change_password: number;
is_active: number; is_active: number;
avatar_updated_at: Date | null;
} }
const publicUser = (row: UserRow) => ({ const publicUser = (row: UserRow) => ({
@@ -58,15 +59,19 @@ const publicUser = (row: UserRow) => ({
quota_bytes: row.quota_bytes, quota_bytes: row.quota_bytes,
used_bytes: row.used_bytes, used_bytes: row.used_bytes,
max_file_bytes: row.max_file_bytes, max_file_bytes: row.max_file_bytes,
must_change_password: row.must_change_password === 1, must_change_password: row.must_change_password,
has_avatar: row.avatar_updated_at !== null,
avatar_updated_at: row.avatar_updated_at,
}); });
const SELECT_USER = ` const SELECT_USER = `
SELECT u.id, u.email, u.first_name, u.last_name, u.password_hash, SELECT u.id, u.email, u.first_name, u.last_name, u.password_hash,
r.slug AS role_slug, r.name AS role_name, r.slug AS role_slug, r.name AS role_name,
u.quota_bytes, u.used_bytes, u.max_file_bytes, u.must_change_password, u.is_active u.quota_bytes, u.used_bytes, u.max_file_bytes, u.must_change_password, u.is_active,
ua.updated_at AS avatar_updated_at
FROM users u FROM users u
JOIN roles r ON r.id = u.role_id`; JOIN roles r ON r.id = u.role_id
LEFT JOIN user_avatars ua ON ua.user_id = u.id`;
export const registerAuthRoutes = (app: App, db: Db, config: Config): void => { export const registerAuthRoutes = (app: App, db: Db, config: Config): void => {
app.use("/api/cloud/*", attachUser(db)); app.use("/api/cloud/*", attachUser(db));
+12 -1
View File
@@ -1,6 +1,7 @@
import { useState } from "react"; import { useState } from "react";
import { NavLink, Outlet } from "react-router-dom"; import { NavLink, Outlet } from "react-router-dom";
import { Button, cn } from "../ui/index.js"; import { Button, cn } from "../ui/index.js";
import { api } from "../lib/api.js";
import { useSession } from "../lib/session.js"; import { useSession } from "../lib/session.js";
import { import {
ActivityIcon, ActivityIcon,
@@ -127,10 +128,20 @@ export const AppShell = () => {
</p> </p>
</div> </div>
<span <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" aria-hidden="true"
> >
{initials(user.first_name, user.last_name)} {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> </span>
<Button <Button
variant="secondary" variant="secondary"
+2
View File
@@ -9,6 +9,8 @@ export interface User {
used_bytes: number; used_bytes: number;
max_file_bytes: number; max_file_bytes: number;
must_change_password: boolean; must_change_password: boolean;
has_avatar: boolean;
avatar_updated_at: string | null;
} }
export interface Folder { export interface Folder {
+2
View File
@@ -91,6 +91,7 @@ export const Profile = () => {
try { try {
await api.uploadAvatar(file); await api.uploadAvatar(file);
setAvatarNonce((value) => value + 1); setAvatarNonce((value) => value + 1);
await refresh();
} catch (caught) { } catch (caught) {
setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible."); setAvatarError(caught instanceof ApiError ? caught.message : "Envoi impossible.");
} finally { } finally {
@@ -103,6 +104,7 @@ export const Profile = () => {
try { try {
await api.deleteAvatar(); await api.deleteAvatar();
setAvatarNonce((value) => value + 1); setAvatarNonce((value) => value + 1);
await refresh();
} catch (caught) { } catch (caught) {
setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible."); setAvatarError(caught instanceof ApiError ? caught.message : "Suppression impossible.");
} }