bigbuffet-rw/app/soapbox/features/feed-suggestions/feed-suggestions.tsx

96 lines
2.8 KiB
TypeScript
Raw Normal View History

2022-07-01 13:09:07 -07:00
import React from 'react';
2022-07-06 06:04:26 -07:00
import { defineMessages, useIntl } from 'react-intl';
2022-07-01 13:09:07 -07:00
import { Link } from 'react-router-dom';
import VerificationBadge from 'soapbox/components/verification_badge';
import { useAccount, useAppSelector } from 'soapbox/hooks';
import { Card, CardBody, CardTitle, HStack, Stack, Text } from '../../components/ui';
import ActionButton from '../ui/components/action-button';
import type { Account } from 'soapbox/types/entities';
2022-07-06 06:04:26 -07:00
const messages = defineMessages({
heading: { id: 'feed_suggestions.heading', defaultMessage: 'Suggested profiles' },
viewAll: { id: 'feed_suggestions.view_all', defaultMessage: 'View all' },
2022-07-06 06:04:26 -07:00
});
2022-07-01 13:09:07 -07:00
const SuggestionItem = ({ accountId }: { accountId: string }) => {
const account = useAccount(accountId) as Account;
return (
<Stack className='w-24 h-auto' space={3}>
<Link
to={`/@${account.acct}`}
title={account.acct}
>
<Stack space={3}>
<img
src={account.avatar}
className='mx-auto block w-16 h-16 min-w-[56px] rounded-full object-cover'
2022-07-01 13:09:07 -07:00
alt={account.acct}
/>
<Stack>
<HStack alignItems='center' justifyContent='center' space={1}>
<Text
weight='semibold'
dangerouslySetInnerHTML={{ __html: account.display_name }}
truncate
align='center'
size='sm'
className='max-w-[95%]'
/>
{account.verified && <VerificationBadge />}
</HStack>
<Text theme='muted' align='center' size='sm' truncate>@{account.acct}</Text>
</Stack>
</Stack>
</Link>
<div className='text-center'>
<ActionButton account={account} />
</div>
</Stack>
);
};
const FeedSuggestions = () => {
2022-07-06 06:04:26 -07:00
const intl = useIntl();
2022-07-01 13:09:07 -07:00
const suggestedProfiles = useAppSelector((state) => state.suggestions.items);
const isLoading = useAppSelector((state) => state.suggestions.isLoading);
if (!isLoading && suggestedProfiles.size === 0) return null;
2022-07-01 13:09:07 -07:00
return (
<Card size='lg' variant='rounded'>
<HStack justifyContent='between' alignItems='center'>
2022-07-06 06:04:26 -07:00
<CardTitle title={intl.formatMessage(messages.heading)} />
2022-07-01 13:09:07 -07:00
<Link
to='/suggestions'
className='text-primary-600 dark:text-primary-400 hover:underline'
>
2022-07-06 06:04:26 -07:00
{intl.formatMessage(messages.viewAll)}
2022-07-01 13:09:07 -07:00
</Link>
</HStack>
<CardBody>
<HStack
alignItems='center'
justifyContent='around'
space={8}
>
{suggestedProfiles.slice(0, 4).map((suggestedProfile) => (
<SuggestionItem key={suggestedProfile.account} accountId={suggestedProfile.account} />
))}
</HStack>
</CardBody>
</Card>
);
};
export default FeedSuggestions;