mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
🐛 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:
@@ -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 }}
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user