2022-11-25 09:04:11 -08:00
|
|
|
import React from 'react';
|
2022-05-13 09:12:19 -07:00
|
|
|
|
2022-11-15 12:46:23 -08:00
|
|
|
import HoverRefWrapper from 'soapbox/components/hover-ref-wrapper';
|
2022-05-13 09:12:19 -07:00
|
|
|
import { useSoapboxConfig } from 'soapbox/hooks';
|
|
|
|
|
|
|
|
import { getAcct } from '../utils/accounts';
|
|
|
|
|
|
|
|
import Icon from './icon';
|
2022-08-31 15:01:58 -07:00
|
|
|
import RelativeTimestamp from './relative-timestamp';
|
2022-11-25 09:04:11 -08:00
|
|
|
import { HStack, Text } from './ui';
|
2022-11-15 08:00:49 -08:00
|
|
|
import VerificationBadge from './verification-badge';
|
2022-05-13 09:12:19 -07:00
|
|
|
|
|
|
|
import type { Account } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
interface IDisplayName {
|
|
|
|
account: Account
|
2022-11-25 09:04:11 -08:00
|
|
|
withSuffix?: boolean
|
2022-05-13 09:12:19 -07:00
|
|
|
withDate?: boolean
|
2023-01-10 15:03:15 -08:00
|
|
|
children?: React.ReactNode
|
2022-05-13 09:12:19 -07:00
|
|
|
}
|
|
|
|
|
2022-11-25 09:04:11 -08:00
|
|
|
const DisplayName: React.FC<IDisplayName> = ({ account, children, withSuffix = true, withDate = false }) => {
|
2022-05-13 09:12:19 -07:00
|
|
|
const { displayFqn = false } = useSoapboxConfig();
|
|
|
|
const { created_at: createdAt, verified } = account;
|
|
|
|
|
|
|
|
const joinedAt = createdAt ? (
|
|
|
|
<div className='account__joined-at'>
|
2022-07-09 09:20:02 -07:00
|
|
|
<Icon src={require('@tabler/icons/clock.svg')} />
|
2022-05-13 09:12:19 -07:00
|
|
|
<RelativeTimestamp timestamp={createdAt} />
|
|
|
|
</div>
|
|
|
|
) : null;
|
|
|
|
|
|
|
|
const displayName = (
|
2022-11-25 09:04:11 -08:00
|
|
|
<HStack space={1} alignItems='center' grow>
|
|
|
|
<Text
|
|
|
|
size='sm'
|
|
|
|
weight='semibold'
|
|
|
|
truncate
|
|
|
|
dangerouslySetInnerHTML={{ __html: account.display_name_html }}
|
|
|
|
/>
|
|
|
|
|
2022-05-13 09:12:19 -07:00
|
|
|
{verified && <VerificationBadge />}
|
|
|
|
{withDate && joinedAt}
|
2022-11-25 09:04:11 -08:00
|
|
|
</HStack>
|
2022-05-13 09:12:19 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
const suffix = (<span className='display-name__account'>@{getAcct(account, displayFqn)}</span>);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span className='display-name' data-testid='display-name'>
|
|
|
|
<HoverRefWrapper accountId={account.get('id')} inline>
|
|
|
|
{displayName}
|
|
|
|
</HoverRefWrapper>
|
2022-11-25 09:04:11 -08:00
|
|
|
{withSuffix && suffix}
|
2022-05-13 09:12:19 -07:00
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default DisplayName;
|