mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-21 07:40:11 +08:00
refactor: improve UserSelector with tag
This commit is contained in:
parent
3fd53572dd
commit
630c8e4d38
@ -1,4 +1,5 @@
|
|||||||
import { HStack, VStack } from '@renderer/components/Layout'
|
import CustomTag from '@renderer/components/CustomTag'
|
||||||
|
import { HStack } from '@renderer/components/Layout'
|
||||||
import { useAssistants } from '@renderer/hooks/useAssistant'
|
import { useAssistants } from '@renderer/hooks/useAssistant'
|
||||||
import { Avatar, Button, Select, Space, Tooltip } from 'antd'
|
import { Avatar, Button, Select, Space, Tooltip } from 'antd'
|
||||||
import { UserRoundPlus } from 'lucide-react'
|
import { UserRoundPlus } from 'lucide-react'
|
||||||
@ -25,12 +26,13 @@ const UserSelector: React.FC<UserSelectorProps> = ({ currentUser, uniqueUsers, o
|
|||||||
// Get assistants linked to a specific memory user
|
// Get assistants linked to a specific memory user
|
||||||
const getAssistantsForUser = useCallback(
|
const getAssistantsForUser = useCallback(
|
||||||
(userId: string) => {
|
(userId: string) => {
|
||||||
return assistants.filter((assistant) => {
|
return assistants.filter(
|
||||||
|
(assistant) =>
|
||||||
// Assistant uses this user if either:
|
// Assistant uses this user if either:
|
||||||
// 1. memoryUserId explicitly matches
|
// 1. memoryUserId explicitly matches
|
||||||
// 2. memoryUserId is undefined and this is the current global user
|
// 2. memoryUserId is undefined and this is the current global user
|
||||||
return assistant.memoryUserId === userId || (!assistant.memoryUserId && userId === currentUser)
|
assistant.memoryUserId === userId || (!assistant.memoryUserId && userId === currentUser)
|
||||||
})
|
)
|
||||||
},
|
},
|
||||||
[assistants, currentUser]
|
[assistants, currentUser]
|
||||||
)
|
)
|
||||||
@ -40,26 +42,22 @@ const UserSelector: React.FC<UserSelectorProps> = ({ currentUser, uniqueUsers, o
|
|||||||
const linkedAssistants = getAssistantsForUser(userId)
|
const linkedAssistants = getAssistantsForUser(userId)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<VStack alignItems="flex-start" gap={2}>
|
<HStack alignItems="center" justifyContent="space-between" style={{ width: '100%' }}>
|
||||||
<HStack alignItems="center" gap={10}>
|
<HStack alignItems="center" gap={8} style={{ minWidth: 0 }}>
|
||||||
<Avatar size={20} style={{ background: 'var(--color-primary)' }}>
|
<Avatar size={20} style={{ background: 'var(--color-primary)' }}>
|
||||||
{getUserAvatar(userId)}
|
{getUserAvatar(userId)}
|
||||||
</Avatar>
|
</Avatar>
|
||||||
<span>{userName}</span>
|
<span style={{ whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' }}>{userName}</span>
|
||||||
</HStack>
|
</HStack>
|
||||||
{linkedAssistants.length > 0 && (
|
{linkedAssistants.length > 0 && (
|
||||||
<div
|
<CustomTag
|
||||||
style={{
|
color="#8c8c8c"
|
||||||
fontSize: '11px',
|
size={10}
|
||||||
color: 'var(--color-text-tertiary)',
|
tooltip={`Linked Assistants: ${linkedAssistants.map((a) => a.name).join(', ')}`}>
|
||||||
marginLeft: '30px',
|
{linkedAssistants.length}
|
||||||
lineHeight: '14px'
|
</CustomTag>
|
||||||
}}>
|
|
||||||
{linkedAssistants.length} {linkedAssistants.length === 1 ? 'assistant' : 'assistants'}:{' '}
|
|
||||||
{linkedAssistants.map((a) => a.name).join(', ')}
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</VStack>
|
</HStack>
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
[getUserAvatar, getAssistantsForUser]
|
[getUserAvatar, getAssistantsForUser]
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user