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-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
|
|
|
|
return (
|
|
|
|
<SiteLink
|
|
|
|
href={`/${username}`}
|
2022-09-15 15:51:52 +00:00
|
|
|
className={clsx(
|
|
|
|
'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
|
|
|
|
|
|
|
const BOT_USERNAMES = ['v']
|
|
|
|
|
|
|
|
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>
|
|
|
|
)
|
|
|
|
}
|