2022-09-01 22:23:12 +00:00
|
|
|
import { SiteLink } from 'web/components/site-link'
|
2022-08-30 15:38:59 +00:00
|
|
|
import clsx from 'clsx'
|
2022-10-10 21:38:27 +00:00
|
|
|
import { useWindowSize } from 'web/hooks/use-window-size'
|
2022-08-30 15:38:59 +00:00
|
|
|
|
2022-09-01 22:23:12 +00:00
|
|
|
export function shortenName(name: string) {
|
2022-08-30 15:38:59 +00:00
|
|
|
const firstName = name.split(' ')[0]
|
2022-08-31 14:29:35 +00:00
|
|
|
const maxLength = 11
|
2022-08-30 15:38:59 +00:00
|
|
|
const shortName =
|
2022-08-31 14:29:35 +00:00
|
|
|
firstName.length >= 3 && name.length > maxLength
|
2022-08-30 15:38:59 +00:00
|
|
|
? firstName.length < maxLength
|
|
|
|
? firstName
|
|
|
|
: firstName.substring(0, maxLength - 3) + '...'
|
|
|
|
: name.length > maxLength
|
2022-08-31 14:29:35 +00:00
|
|
|
? name.substring(0, maxLength - 3) + '...'
|
2022-08-30 15:38:59 +00:00
|
|
|
: name
|
|
|
|
return shortName
|
|
|
|
}
|
|
|
|
|
|
|
|
export function UserLink(props: {
|
|
|
|
name: string
|
|
|
|
username: string
|
|
|
|
className?: string
|
|
|
|
short?: boolean
|
2022-09-15 15:51:52 +00:00
|
|
|
noLink?: boolean
|
2022-08-30 15:38:59 +00:00
|
|
|
}) {
|
2022-09-15 15:51:52 +00:00
|
|
|
const { name, username, className, short, noLink } = props
|
2022-08-30 15:38:59 +00:00
|
|
|
const shortName = short ? shortenName(name) : name
|
2022-10-10 21:38:27 +00:00
|
|
|
const { width } = useWindowSize()
|
2022-08-30 15:38:59 +00:00
|
|
|
return (
|
|
|
|
<SiteLink
|
|
|
|
href={`/${username}`}
|
2022-09-15 15:51:52 +00:00
|
|
|
className={clsx(
|
2022-10-10 21:38:27 +00:00
|
|
|
(width ?? 0) < 450 ? ' max-w-[120px]' : 'max-w-[200px]',
|
2022-09-15 15:51:52 +00:00
|
|
|
'z-10 truncate',
|
|
|
|
className,
|
|
|
|
noLink ? 'pointer-events-none' : ''
|
|
|
|
)}
|
2022-08-30 15:38:59 +00:00
|
|
|
>
|
|
|
|
{shortName}
|
2022-10-06 18:20:35 +00:00
|
|
|
{BOT_USERNAMES.includes(username) && <BotBadge />}
|
2022-08-30 15:38:59 +00:00
|
|
|
</SiteLink>
|
|
|
|
)
|
|
|
|
}
|
2022-10-06 18:20:35 +00:00
|
|
|
|
2022-10-10 21:38:27 +00:00
|
|
|
const BOT_USERNAMES = [
|
|
|
|
'v',
|
|
|
|
'ArbitrageBot',
|
|
|
|
'MarketManagerBot',
|
|
|
|
'Botlab',
|
|
|
|
'JuniorBot',
|
|
|
|
]
|
2022-10-06 18:20:35 +00:00
|
|
|
|
|
|
|
function BotBadge() {
|
|
|
|
return (
|
|
|
|
<span className="ml-1.5 inline-flex items-center rounded-full bg-gray-100 px-2.5 py-0.5 text-xs font-medium text-gray-800">
|
|
|
|
Bot
|
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|