diff --git a/src/client/components/ProfileSection.tsx b/src/client/components/ProfileSection.tsx index 98e4191..37b50d8 100644 --- a/src/client/components/ProfileSection.tsx +++ b/src/client/components/ProfileSection.tsx @@ -11,7 +11,8 @@ export function ProfileSection() { const [displayName, setDisplayName] = useState(""); const [bio, setBio] = useState(""); - const [avatarUrl, setAvatarUrl] = useState(null); + const [avatarFilename, setAvatarFilename] = useState(null); + const [avatarDisplayUrl, setAvatarDisplayUrl] = useState(null); const [dirty, setDirty] = useState(false); const [message, setMessage] = useState<{ type: "success" | "error"; @@ -24,7 +25,8 @@ export function ProfileSection() { if (profile && !dirty) { setDisplayName(profile.displayName ?? ""); setBio(profile.bio ?? ""); - setAvatarUrl(profile.avatarUrl ?? null); + setAvatarFilename(profile.avatarUrl ?? null); + setAvatarDisplayUrl(profile.avatarImageUrl ?? null); } }, [profile, dirty]); @@ -34,7 +36,7 @@ export function ProfileSection() { try { await updateProfile.mutateAsync({ displayName: displayName.trim() || undefined, - avatarUrl, + avatarUrl: avatarFilename, bio: bio.trim() || undefined, }); setDirty(false); @@ -63,13 +65,16 @@ export function ProfileSection() { return; } + const localPreview = URL.createObjectURL(file); + setAvatarDisplayUrl(localPreview); setUploading(true); setMessage(null); try { const result = await apiUpload<{ filename: string }>("/api/images", file); - setAvatarUrl(result.filename); + setAvatarFilename(result.filename); setDirty(true); } catch { + setAvatarDisplayUrl(null); setMessage({ type: "error", text: "Avatar upload failed." }); } finally { setUploading(false); @@ -92,9 +97,9 @@ export function ProfileSection() { onClick={() => fileInputRef.current?.click()} className="relative w-16 h-16 rounded-full overflow-hidden cursor-pointer group shrink-0" > - {avatarUrl ? ( + {avatarDisplayUrl ? ( Avatar @@ -145,11 +150,12 @@ export function ProfileSection() { > {uploading ? "Uploading..." : "Change avatar"} - {avatarUrl && ( + {avatarFilename && (