profile-image
This commit is contained in:
@@ -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
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
</>
|
</>
|
||||||
|
|||||||
Reference in New Issue
Block a user