bigbuffet-rw/app/soapbox/features/groups/components/discover/group-list-item.tsx

82 lines
2.6 KiB
TypeScript
Raw Normal View History

2023-03-08 10:22:10 -08:00
import React from 'react';
import { FormattedMessage } from 'react-intl';
import { Link } from 'react-router-dom';
2023-03-08 10:22:10 -08:00
2023-03-14 11:44:48 -07:00
import GroupAvatar from 'soapbox/components/groups/group-avatar';
2023-03-28 08:52:25 -07:00
import { HStack, Icon, Stack, Text } from 'soapbox/components/ui';
import GroupActionButton from 'soapbox/features/group/components/group-action-button';
2023-03-08 10:22:10 -08:00
import { Group as GroupEntity } from 'soapbox/types/entities';
import { shortNumberFormat } from 'soapbox/utils/numbers';
2023-06-08 06:00:49 -07:00
interface IGroupListItem {
2023-03-08 10:22:10 -08:00
group: GroupEntity
withJoinAction?: boolean
}
2023-06-08 06:00:49 -07:00
const GroupListItem = (props: IGroupListItem) => {
2023-03-08 10:22:10 -08:00
const { group, withJoinAction = true } = props;
return (
<HStack
alignItems='center'
justifyContent='between'
data-testid='group-list-item'
2023-03-08 10:22:10 -08:00
>
2023-05-23 09:32:55 -07:00
<Link key={group.id} to={`/group/${group.slug}`} className='overflow-hidden'>
<HStack alignItems='center' space={2}>
2023-03-14 11:44:48 -07:00
<GroupAvatar
group={group}
size={44}
2023-03-08 10:22:10 -08:00
/>
2023-05-23 09:32:55 -07:00
<Stack className='overflow-hidden'>
<Text
weight='bold'
dangerouslySetInnerHTML={{ __html: group.display_name_html }}
2023-05-23 09:32:55 -07:00
truncate
2023-03-08 10:22:10 -08:00
/>
<HStack className='text-gray-700 dark:text-gray-600' space={1} alignItems='center'>
<Icon
className='h-4.5 w-4.5'
src={group.locked ? require('@tabler/icons/lock.svg') : require('@tabler/icons/world.svg')}
/>
<Text theme='inherit' tag='span' size='sm' weight='medium'>
{group.locked ? (
<FormattedMessage id='group.privacy.locked' defaultMessage='Private' />
) : (
<FormattedMessage id='group.privacy.public' defaultMessage='Public' />
)}
</Text>
2023-03-08 10:22:10 -08:00
{typeof group.members_count !== 'undefined' && (
<>
<span>&bull;</span>
<Text theme='inherit' tag='span' size='sm' weight='medium'>
{shortNumberFormat(group.members_count)}
{' '}
<FormattedMessage
id='groups.discover.search.results.member_count'
defaultMessage='{members, plural, one {member} other {members}}'
values={{
members: group.members_count,
}}
/>
</Text>
</>
)}
</HStack>
</Stack>
</HStack>
</Link>
2023-03-08 10:22:10 -08:00
{withJoinAction && (
2023-03-28 08:52:25 -07:00
<GroupActionButton group={group} />
2023-03-08 10:22:10 -08:00
)}
</HStack>
);
};
export default GroupListItem;