Skip to content

Commit 2af814c

Browse files
committed
fix: improve avatar handling in UserMenu and AccountAvatar components by refining fallback logic and increasing max upload size to 2MB
1 parent 8d0e7c2 commit 2af814c

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

apps/web/src/components/UserMenu.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,17 @@ export function UserMenu() {
8181
aria-label="User menu"
8282
>
8383
<Avatar className="h-8 w-8">
84-
{userProfile?.avatar_url ? (
85-
<AvatarImage
86-
src={userProfile.avatar_url}
87-
alt={userProfile.full_name ?? ""}
88-
/>
89-
) : (
90-
<AvatarFallback className="bg-muted text-muted-foreground font-medium text-xs">
91-
{userProfile?.full_name?.charAt(0)?.toUpperCase()}
92-
</AvatarFallback>
93-
)}
84+
<AvatarImage
85+
src={userProfile?.avatar_url ?? undefined}
86+
alt={
87+
userProfile?.full_name
88+
? `${userProfile.full_name}'s avatar`
89+
: "Avatar"
90+
}
91+
/>
92+
<AvatarFallback className="bg-muted text-muted-foreground font-medium">
93+
{userProfile?.full_name?.charAt(0)?.toUpperCase()}
94+
</AvatarFallback>
9495
</Avatar>
9596
</Button>
9697
</DropdownMenuTrigger>

apps/web/src/components/settings/account/AccountAvatar.tsx

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { CameraIcon, Loader2 } from "lucide-react";
1313
import { useEffect, useState } from "react";
1414
import { toast } from "sonner";
1515

16-
const MAX_AVATAR_SIZE = 1024 * 1024 * 1; // 1MB
16+
const MAX_AVATAR_SIZE = 1024 * 1024 * 2; // 2MB
1717
const ALLOWED_TYPES = new Set(["image/png", "image/jpeg", "image/webp"]);
1818

1919
export const AccountAvatar = () => {
@@ -23,19 +23,21 @@ export const AccountAvatar = () => {
2323

2424
const { mutate: mutateUserProfile, isPending: isMutatingUserProfile } =
2525
useUploadUserAvatar({
26-
onSuccess: async () => {
27-
await queryClient.invalidateQueries({
26+
onSuccess: () => {
27+
return queryClient.invalidateQueries({
2828
queryKey: [UsersServerKeys.GET_USER_PROFILE],
2929
});
30-
setPreviewUrl(null);
3130
},
3231
});
3332

33+
// biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
3434
useEffect(() => {
3535
return () => {
36-
revokeBlobUrl(previewUrl);
36+
if (previewUrl) {
37+
revokeBlobUrl(previewUrl);
38+
}
3739
};
38-
}, [previewUrl]);
40+
}, []);
3941

4042
const handleUploadAvatar = (e: React.ChangeEvent<HTMLInputElement>) => {
4143
const file = e.target.files?.[0];
@@ -57,6 +59,7 @@ export const AccountAvatar = () => {
5759
return;
5860
}
5961

62+
revokeBlobUrl(previewUrl);
6063
const newPreviewUrl = URL.createObjectURL(file);
6164
setPreviewUrl(newPreviewUrl);
6265

@@ -65,7 +68,6 @@ export const AccountAvatar = () => {
6568
{
6669
onError: () => {
6770
toast.error("Failed to upload avatar. Please try again.");
68-
setPreviewUrl(null);
6971
},
7072
},
7173
);
@@ -102,7 +104,7 @@ export const AccountAvatar = () => {
102104
}
103105
}}
104106
/>
105-
<AvatarFallback aria-label="Avatar fallback">
107+
<AvatarFallback className="bg-muted text-muted-foreground font-medium">
106108
{userProfile?.full_name?.charAt(0)?.toUpperCase()}
107109
</AvatarFallback>
108110
</Avatar>

0 commit comments

Comments
 (0)