🐛 fix: slove commnuity user avatarUrl is wrong, should update others in profile (#11634)

* fix: slove when avatarUrl is wrong, should update others

* feat: add the avatar url inital by /webapi/avater
This commit is contained in:
Shinji-Li
2026-01-20 14:45:49 +08:00
committed by GitHub
parent ff63a44f07
commit 04465c8105
2 changed files with 26 additions and 4 deletions

View File

@@ -4,7 +4,7 @@ import { SiGithub, SiX } from '@icons-pack/react-simple-icons';
import { ActionIcon, Avatar, Button, Flexbox, Text, Tooltip, TooltipGroup } from '@lobehub/ui';
import { cssVar } from 'antd-style';
import { Globe } from 'lucide-react';
import { memo } from 'react';
import { memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { useUserDetailContext } from '../DetailProvider';
@@ -19,12 +19,31 @@ const UserHeader = memo(() => {
const displayName = user.displayName || user.userName || user.namespace;
const username = user.userName || user.namespace;
// Normalize avatar URL - convert relative paths to absolute URLs
const avatarUrl = useMemo(() => {
if (!user.avatarUrl) return undefined;
// If it's a relative path (starts with /), prepend the origin
if (user.avatarUrl.startsWith('/')) {
return `${window.location.origin}${user.avatarUrl}`;
}
return user.avatarUrl;
}, [user.avatarUrl]);
const bannerUrl = useMemo(() => {
if (!user.bannerUrl) return null;
// If it's a relative path (starts with /), prepend the origin
if (user.bannerUrl.startsWith('/')) {
return `${window.location.origin}${user.bannerUrl}`;
}
return user.bannerUrl;
}, [user.bannerUrl]);
return (
<>
<Banner avatar={user?.avatarUrl} bannerUrl={user?.bannerUrl} />
<Banner avatar={avatarUrl} bannerUrl={bannerUrl} />
<Flexbox gap={16}>
<Avatar
avatar={user.avatarUrl || undefined}
avatar={avatarUrl}
shape={'square'}
size={64}
style={{ boxShadow: `0 0 0 4px ${cssVar.colorBgContainer}`, flexShrink: 0 }}

View File

@@ -46,6 +46,9 @@ const UserDetailPage = memo<UserDetailPageProps>(({ mobile }) => {
// Call the original onSuccess callback if provided
onSuccess?.(profile);
// Refresh page data to show updated profile
mutate();
// Navigate to new URL if userName changed
const newUserName = profile.userName || profile.namespace;
if (newUserName && newUserName !== currentUserName) {
@@ -53,7 +56,7 @@ const UserDetailPage = memo<UserDetailPageProps>(({ mobile }) => {
}
});
},
[data?.user?.userName, data?.user?.namespace, openProfileSetup, navigate],
[data?.user?.userName, data?.user?.namespace, openProfileSetup, navigate, mutate],
);
const contextConfig = useMemo(() => {