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

View File

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

View File

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