profile-image

This commit is contained in:
Alessio
2026-06-02 12:27:03 +02:00
parent ef3b944718
commit 93be8add4e
3 changed files with 14 additions and 6 deletions

View File

@@ -26,7 +26,7 @@ export function AccountCard({
}: { }: {
onDeleteAvatar: () => Promise<void>; onDeleteAvatar: () => Promise<void>;
onEditAccount: () => void; onEditAccount: () => void;
onEditAvatar: () => void; onEditAvatar: () => Promise<boolean>;
onEditPassword: () => void; onEditPassword: () => void;
onSelectAvatar: (file: File) => void; onSelectAvatar: (file: File) => void;
savingAvatar: boolean; savingAvatar: boolean;
@@ -76,9 +76,11 @@ export function AccountCard({
disabled={savingAvatar} disabled={savingAvatar}
icon={user.avatarUrl ? LuPencil : LuImagePlus} icon={user.avatarUrl ? LuPencil : LuImagePlus}
label={user.avatarUrl ? "Modifica avatar" : "Carica avatar"} label={user.avatarUrl ? "Modifica avatar" : "Carica avatar"}
onClick={() => onClick={async () => {
user.avatarUrl ? onEditAvatar() : inputRef.current?.click() if (!user.avatarUrl || !(await onEditAvatar())) {
} inputRef.current?.click();
}
}}
/> />
{user.avatarUrl ? ( {user.avatarUrl ? (
<ListCardAction <ListCardAction

View File

@@ -88,7 +88,7 @@ export function ProfilePageClient({ user }: { user: UserSession }) {
} }
async function editAvatar() { async function editAvatar() {
if (!account.avatarUrl) return; if (!account.avatarUrl) return false;
setSavingAvatar(true); setSavingAvatar(true);
try { try {
const response = await fetch(account.avatarUrl, { cache: "no-store" }); const response = await fetch(account.avatarUrl, { cache: "no-store" });
@@ -97,8 +97,10 @@ export function ProfilePageClient({ user }: { user: UserSession }) {
setSelectedAvatar( setSelectedAvatar(
new File([blob], avatarFilename(blob.type), { type: blob.type }), new File([blob], avatarFilename(blob.type), { type: blob.type }),
); );
return true;
} catch (error) { } catch (error) {
notify(errorMessage(error), "error"); notify(errorMessage(error), "error");
return false;
} finally { } finally {
setSavingAvatar(false); setSavingAvatar(false);
} }

View File

@@ -83,7 +83,11 @@ export function MobileSidebar({
ref={panelRef} ref={panelRef}
> >
<SidebarBrand /> <SidebarBrand />
<SidebarLinks className="mt-8" pathname={pathname} onNavigate={onClose} /> <SidebarLinks
className="mt-8"
pathname={pathname}
onNavigate={onClose}
/>
<SidebarAccount onLogout={onLogout} user={user} /> <SidebarAccount onLogout={onLogout} user={user} />
</aside> </aside>
</> </>