Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

style: update Group Avatar

canisminor1990fddff0e96226
diff --git a/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/Header/Avatar.tsx b/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/Header/Avatar.tsx
index 070c5fbce17..915377495b0 100644
--- a/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/Header/Avatar.tsx
+++ b/src/app/[variants]/(main)/group/_layout/Sidebar/GroupConfig/Header/Avatar.tsx
@@ -1,25 +1,17 @@
'use client';
-import { Block, GroupAvatar } from '@lobehub/ui';
+import { Block } from '@lobehub/ui';
import { memo } from 'react';
-import { DEFAULT_AVATAR } from '@/const/meta';
+import GroupAvatar from '@/features/GroupAvatar';
import { useOpenChatSettings } from '@/hooks/useInterceptingRoutes';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
-import { useUserStore } from '@/store/user';
-import { userProfileSelectors } from '@/store/user/selectors';
const HeaderAvatar = memo<{ size?: number }>(() => {
- const groupMeta = useAgentGroupStore(agentGroupSelectors.currentGroupMeta);
const currentGroup = useAgentGroupStore(agentGroupSelectors.currentGroup);
const agents = currentGroup?.agents || [];
- const currentUser = useUserStore((s) => ({
- avatar: userProfileSelectors.userAvatar(s),
- name: userProfileSelectors.displayUserName(s) || userProfileSelectors.nickName(s) || 'You',
- }));
-
const openChatSettings = useOpenChatSettings();
return (
@@ -39,19 +31,11 @@ const HeaderAvatar = memo<{ size?: number }>(() => {
width={32}
>
<GroupAvatar
- avatarShape={'square'}
- avatars={[
- {
- avatar: currentUser.avatar || DEFAULT_AVATAR,
- },
- ...agents.map((agent) => ({
- avatar: agent.avatar || DEFAULT_AVATAR,
- background: agent.backgroundColor || undefined,
- })),
- ]}
- cornerShape={'square'}
+ avatars={agents.map((agent) => ({
+ avatar: agent.avatar,
+ background: agent.backgroundColor || undefined,
+ }))}
size={28}
- title={groupMeta.title || undefined}
/>
</Block>
);
diff --git a/src/app/[variants]/(main)/group/_layout/Sidebar/Header/Agent/index.tsx b/src/app/[variants]/(main)/group/_layout/Sidebar/Header/Agent/index.tsx
index fab38605ff3..5188237e95c 100644
--- a/src/app/[variants]/(main)/group/_layout/Sidebar/Header/Agent/index.tsx
+++ b/src/app/[variants]/(main)/group/_layout/Sidebar/Header/Agent/index.tsx
@@ -1,11 +1,12 @@
'use client';
-import { ActionIcon, Block, GroupAvatar, Text } from '@lobehub/ui';
+import { ActionIcon, Block, Text } from '@lobehub/ui';
import { ChevronsUpDownIcon } from 'lucide-react';
import React, { type PropsWithChildren, memo } from 'react';
import { useTranslation } from 'react-i18next';
import { DEFAULT_AVATAR } from '@/const/meta';
+import GroupAvatar from '@/features/GroupAvatar';
import { SkeletonItem } from '@/features/NavPanel/components/SkeletonList';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
@@ -40,15 +41,11 @@ const Agent = memo<PropsWithChildren>(() => {
variant={'borderless'}
>
<GroupAvatar
- avatarShape={'square'}
avatars={agents.map((agent) => ({
avatar: agent.avatar || DEFAULT_AVATAR,
background: agent.backgroundColor || undefined,
- style: { borderRadius: 3 },
}))}
- cornerShape={'square'}
size={28}
- title={groupMeta?.title || undefined}
/>
<Text ellipsis weight={500}>
{displayTitle}
diff --git a/src/app/[variants]/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx b/src/app/[variants]/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
index 58a6282ee9c..1d1919e299e 100644
--- a/src/app/[variants]/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
+++ b/src/app/[variants]/(main)/group/features/Conversation/MainChatInput/GroupChat.tsx
@@ -1,13 +1,14 @@
'use client';
import { type SlashOptions } from '@lobehub/editor';
-import { Alert, Avatar, Flexbox, GroupAvatar } from '@lobehub/ui';
+import { Alert, Avatar, Flexbox } from '@lobehub/ui';
import { isEqual } from 'es-toolkit/compat';
import { Suspense, memo, useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import { DEFAULT_AVATAR } from '@/const/meta';
import { type ActionKeys, ChatInputProvider, DesktopChatInput } from '@/features/ChatInput';
+import GroupAvatar from '@/features/GroupAvatar';
import WideScreenContainer from '@/features/WideScreenContainer';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
diff --git a/src/app/[variants]/(main)/group/features/GroupAvatar.tsx b/src/app/[variants]/(main)/group/features/GroupAvatar.tsx
index fd5892b3439..2380c339230 100644
--- a/src/app/[variants]/(main)/group/features/GroupAvatar.tsx
+++ b/src/app/[variants]/(main)/group/features/GroupAvatar.tsx
@@ -1,38 +1,23 @@
'use client';
-import { Avatar, GroupAvatar, Skeleton } from '@lobehub/ui';
+import isEqual from 'fast-deep-equal';
import React, { memo } from 'react';
import { DEFAULT_AVATAR } from '@/const/meta';
-import { useAgentStore } from '@/store/agent';
-import { agentSelectors } from '@/store/agent/selectors';
+import GroupAvatar from '@/features/GroupAvatar';
import { useAgentGroupStore } from '@/store/agentGroup';
import { agentGroupSelectors } from '@/store/agentGroup/selectors';
const SupervisorAvatar = memo<{ size?: number }>(({ size = 28 }) => {
- const meta = useAgentStore(agentSelectors.currentAgentMeta);
- const [isGroupsInit, groupMeta, agents] = useAgentGroupStore((s) => [
- agentGroupSelectors.isGroupsInit(s),
- agentGroupSelectors.currentGroupMeta(s),
- agentGroupSelectors.currentGroupAgents(s),
- ]);
-
- if (isGroupsInit) return <Skeleton.Avatar shape={'square'} size={size} />;
-
- if (meta?.avatar && meta?.avatar !== DEFAULT_AVATAR)
- return <Avatar avatar={meta.avatar} background={meta?.backgroundColor} size={size} />;
+ const agents = useAgentGroupStore((s) => agentGroupSelectors.currentGroupAgents(s), isEqual);
return (
<GroupAvatar
- avatarShape={'square'}
avatars={agents.map((agent) => ({
avatar: agent.avatar || DEFAULT_AVATAR,
background: agent.backgroundColor || undefined,
- style: { borderRadius: 3 },
}))}
- cornerShape={'square'}
size={size}
- title={groupMeta?.title || undefined}
/>
);
});
diff --git a/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/Avatar.tsx b/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/Avatar.tsx
deleted file mode 100644
index 3666ac1b6c9..00000000000
--- a/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/Avatar.tsx
+++ /dev/null
@@ -1,28 +0,0 @@
-import { GroupAvatar, Icon } from '@lobehub/ui';
-import { GroupBotSquareIcon } from '@lobehub/ui/icons';
-import { memo, useMemo } from 'react';
-
-interface GroupAvatarProps {
- avatar: Array<{ avatar: string; background?: string }> | string | null;
-}
-
-const AgentGroupAvatar = memo<GroupAvatarProps>(({ avatar }) => {
- // Convert avatar to array format for GroupAvatar
- const avatars = Array.isArray(avatar) ? avatar : avatar ? [{ avatar }] : [];
-
- const displayAvatars = useMemo(
- () => avatars.map((item) => ({ ...item, style: { borderRadius: 3 } })),
- [avatars],
- );
-
- // Show default group icon if no member avatars
- if (avatars.length === 0) {
- return <Icon icon={GroupBotSquareIcon} size={28} />;
- }
-
- return (
- <GroupAvatar avatarShape={'square'} avatars={displayAvatars} cornerShape={'square'} size={22} />
- );
-});
-
-export default AgentGroupAvatar;
diff --git a/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx b/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx
index a46ed2cda18..7a12e0d4f14 100644
--- a/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx
+++ b/src/app/[variants]/(main)/home/_layout/Body/Agent/List/AgentGroupItem/index.tsx
@@ -7,13 +7,13 @@ import { type CSSProperties, type DragEvent, memo, useCallback, useMemo } from '
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
+import GroupAvatar from '@/features/GroupAvatar';
import NavItem from '@/features/NavPanel/components/NavItem';
import { useGlobalStore } from '@/store/global';
import { useHomeStore } from '@/store/home';
import Actions from '../Item/Actions';
import { useDropdownMenu } from '../Item/useDropdownMenu';
-import Avatar from './Avatar';
import Editing from './Editing';
interface GroupItemProps {
@@ -83,7 +83,7 @@ const GroupItem = memo<GroupItemProps>(({ item, style, className }) => {
if (isUpdating) {
return <Icon color={theme.colorTextDescription} icon={Loader2} size={18} spin />;
}
- return <Avatar avatar={avatar ?? null} />;
+ return <GroupAvatar avatars={(avatar as any) || []} size={22} />;
}, [isUpdating, avatar, theme.colorTextDescription]);
const dropdownMenu: MenuProps['items'] = useDropdownMenu({
diff --git a/src/app/[variants]/(main)/home/features/RecentTopic/Item.tsx b/src/app/[variants]/(main)/home/features/RecentTopic/Item.tsx
index 5b71dc46057..aaf1e3b1f3e 100644
--- a/src/app/[variants]/(main)/home/features/RecentTopic/Item.tsx
+++ b/src/app/[variants]/(main)/home/features/RecentTopic/Item.tsx
@@ -1,10 +1,11 @@
-import { Avatar, Block, Center, Flexbox, GroupAvatar, Text } from '@lobehub/ui';
+import { Avatar, Block, Center, Flexbox, Text } from '@lobehub/ui';
import { useTheme } from 'antd-style';
import { memo, useMemo } from 'react';
import Time from '@/app/[variants]/(main)/home/features/components/Time';
import { RECENT_BLOCK_SIZE } from '@/app/[variants]/(main)/home/features/const';
import { DEFAULT_AVATAR } from '@/const/meta';
+import GroupAvatar from '@/features/GroupAvatar';
import { type RecentTopic } from '@/types/topic';
const ReactTopicItem = memo<RecentTopic>(({ title, updatedAt, agent, group, type }) => {
@@ -72,9 +73,7 @@ const ReactTopicItem = memo<RecentTopic>(({ title, updatedAt, agent, group, type
>
{isGroup ? (
<GroupAvatar
- avatarShape={'square'}
avatars={groupAvatars}
- cornerShape={'square'}
size={30}
style={{
background: theme.colorBgLayout,
diff --git a/src/app/[variants]/(mobile)/(home)/features/SessionListContent/ListItem/index.tsx b/src/app/[variants]/(mobile)/(home)/features/SessionListContent/ListItem/index.tsx
index cc9d6549ca7..91761a52d98 100644
--- a/src/app/[variants]/(mobile)/(home)/features/SessionListContent/ListItem/index.tsx
+++ b/src/app/[variants]/(mobile)/(home)/features/SessionListContent/ListItem/index.tsx
@@ -1,8 +1,9 @@
-import { Avatar, GroupAvatar, List, type ListItemProps } from '@lobehub/ui';
+import { Avatar, List, type ListItemProps } from '@lobehub/ui';
import { useHover } from 'ahooks';
import { createStyles } from 'antd-style';
import { memo, useMemo, useRef } from 'react';
+import GroupAvatar from '@/features/GroupAvatar';
import { useServerConfigStore } from '@/store/serverConfig';
const { Item } = List;
diff --git a/src/components/ChatGroupWizard/ChatGroupWizard.tsx b/src/components/ChatGroupWizard/ChatGroupWizard.tsx
index b70ef7624fe..0f2e1b3f3b3 100644
--- a/src/components/ChatGroupWizard/ChatGroupWizard.tsx
+++ b/src/components/ChatGroupWizard/ChatGroupWizard.tsx
@@ -2,16 +2,16 @@
import {
Avatar,
+ Button,
Collapse,
Empty,
Flexbox,
- GroupAvatar,
List,
Modal,
SearchBar,
Text,
Tooltip,
- Button } from '@lobehub/ui';
+} from '@lobehub/ui';
import { Checkbox, Switch } from 'antd';
import { createStyles, useTheme } from 'antd-style';
import { omit } from 'es-toolkit/compat';
@@ -20,6 +20,7 @@ import { type ChangeEvent, memo, useCallback, useEffect, useMemo, useRef, useSta
import { useTranslation } from 'react-i18next';
import { DEFAULT_AVATAR } from '@/const/meta';
+import GroupAvatar from '@/features/GroupAvatar';
import ModelSelect from '@/features/ModelSelect';
import { useEnabledChatModels } from '@/hooks/useEnabledChatModels';
import { useSessionStore } from '@/store/session';
diff --git a/src/features/GroupAvatar/index.tsx b/src/features/GroupAvatar/index.tsx
new file mode 100644
index 00000000000..05d3de8fde7
--- /dev/null
+++ b/src/features/GroupAvatar/index.tsx
@@ -0,0 +1,60 @@
+'use client';
+
+import { GroupAvatar, GroupAvatarProps, Skeleton } from '@lobehub/ui';
+import { useTheme } from 'antd-style';
+import { memo, useMemo } from 'react';
+
+import { DEFAULT_AVATAR } from '@/const/meta';
+import { useUserStore } from '@/store/user';
+import { userProfileSelectors } from '@/store/user/slices/auth/selectors';
+
+interface GroupAvatarComponentProps extends GroupAvatarProps {
+ loading?: boolean;
+}
+
+const GroupAvatarComponent = memo<GroupAvatarComponentProps>(
+ ({ size = 28, avatars = [], loading, ...rest }) => {
+ const theme = useTheme();
+ const [userAvatar, nickName, username] = useUserStore((s) => [
+ userProfileSelectors.userAvatar(s),
+ userProfileSelectors.nickName(s),
+ userProfileSelectors.username(s),
+ ]);
+
+ const groupAvatars = useMemo(() => {
+ let displayAvatars = avatars;
+ if (displayAvatars.length === 0) {
+ displayAvatars = [
+ {
+ avatar: DEFAULT_AVATAR,
+ },
+ ];
+ }
+ return [
+ {
+ avatar: userAvatar || nickName || username,
+ style: { color: theme.colorText },
+ },
+ ...displayAvatars,
+ ];
+ }, [avatars, userAvatar, nickName, username, theme.colorText]);
+
+ if (loading) return <Skeleton.Avatar active shape={'square'} size={size} />;
+
+ return (
+ <GroupAvatar
+ avatarShape={'square'}
+ avatars={groupAvatars.map((agent: any) => ({
+ avatar: agent.avatar || DEFAULT_AVATAR,
+ background: agent?.backgroundColor || undefined,
+ ...agent,
+ }))}
+ cornerShape={'square'}
+ size={size}
+ {...rest}
+ />
+ );
+ },
+);
+
+export default GroupAvatarComponent;