| 1 | import type { SocialAccount } from '@/api/accounts/account.types' |
| 2 | import { memo } from 'react' |
| 3 | import { useTransClient } from '@/app/i18n/client' |
| 4 | import { OssImage } from '@/components/common/OssImage' |
| 5 | |
| 6 | import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar' |
| 7 | import { getPlatformInfoSync } from '@/store/platformMetadata' |
| 8 | import { cn } from '@/utils/className' |
| 9 | import { getOssUrl } from '@/utils/oss' |
| 10 | import AccountStatusView from './AccountStatusView' |
| 11 | |
| 12 | interface AccountItemProps { |
| 13 | account: SocialAccount |
| 14 | isActive: boolean |
| 15 | onSelect: (account: SocialAccount) => void |
| 16 | indent?: boolean |
| 17 | } |
| 18 | |
| 19 | const AccountItem = memo(({ account, isActive, onSelect, indent = false }: AccountItemProps) => { |
| 20 | const { t } = useTransClient('account') |
| 21 | const platInfo = getPlatformInfoSync(account.type) |
| 22 | |
| 23 | return ( |
| 24 | <div |
| 25 | data-testid="accounts-selector-account-item" |
| 26 | onClick={() => onSelect(account)} |
| 27 | className={cn( |
| 28 | 'flex items-center gap-3 px-3 py-2 mx-2 rounded-sm transition-colors group relative', |
| 29 | indent && 'ml-8', |
| 30 | isActive && 'bg-accent text-accent-foreground', |
| 31 | 'cursor-pointer hover:bg-muted/50', |
| 32 | )} |
| 33 | > |
| 34 | <Avatar className="h-8 w-8 shrink-0"> |
| 35 | <AvatarImage src={getOssUrl(account.avatar)} alt={account.nickname} /> |
| 36 | <AvatarFallback>{account.nickname?.[0]}</AvatarFallback> |
| 37 | </Avatar> |
| 38 | |
| 39 | <div className="flex-1 min-w-0"> |
| 40 | <div className="text-sm font-medium truncate">{account.nickname}</div> |
| 41 | <div className="flex items-center gap-2 mt-1 flex-wrap"> |
| 42 | {platInfo?.icon && ( |
| 43 | <OssImage |
| 44 | src={platInfo.icon} |
| 45 | alt={platInfo.name} |
| 46 | width={16} |
| 47 | height={16} |
| 48 | className="rounded-sm shrink-0" |
| 49 | /> |
| 50 | )} |
| 51 | <span className="text-xs text-muted-foreground shrink-0">{platInfo?.name}</span> |
| 52 | <AccountStatusView account={account} /> |
| 53 | {account.fansCount !== undefined && account.fansCount !== null && ( |
| 54 | <span className="text-xs text-muted-foreground shrink-0"> |
| 55 | {t('fansCount')} |
| 56 | : |
| 57 | {account.fansCount ?? 0} |
| 58 | </span> |
| 59 | )} |
| 60 | </div> |
| 61 | </div> |
| 62 | </div> |
| 63 | ) |
| 64 | }) |
| 65 | |
| 66 | AccountItem.displayName = 'AccountItem' |
| 67 | |
| 68 | export default AccountItem |
| 69 |