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

96 lines
3.1 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';
2023-06-21 14:28:51 -07:00
import { useAccount } from 'soapbox/api/hooks';
2022-11-15 08:00:49 -08:00
import VerificationBadge from 'soapbox/components/verification-badge';
2023-06-21 14:28:51 -07:00
import { useAppSelector } from 'soapbox/hooks';
2022-07-01 13:09:07 -07:00
import { Card, CardBody, CardTitle, HStack, Stack, Text } from '../../components/ui';
import ActionButton from '../ui/components/action-button';
2022-07-06 06:04:26 -07:00
const messages = defineMessages({
2022-09-26 12:23:51 -07:00
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
});
2023-06-21 14:28:51 -07:00
interface ISuggestionItem {
accountId: string
}
const SuggestionItem: React.FC<ISuggestionItem> = ({ accountId }) => {
const { account } = useAccount(accountId);
if (!account) return null;
2022-07-01 13:09:07 -07:00
return (
2023-02-01 14:13:42 -08:00
<Stack space={3} className='w-52 shrink-0 rounded-md border border-solid border-gray-300 p-4 dark:border-gray-800 md:w-full md:shrink md:border-transparent md:p-0 dark:md:border-transparent'>
2022-07-01 13:09:07 -07:00
<Link
to={`/@${account.acct}`}
title={account.acct}
>
2023-02-01 14:13:42 -08:00
<Stack space={3} className='mx-auto w-40 md:w-24'>
2022-07-01 13:09:07 -07:00
<img
src={account.avatar}
2023-02-01 14:13:42 -08:00
className='mx-auto block h-16 w-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'
2022-11-21 08:56:38 -08:00
dangerouslySetInnerHTML={{ __html: account.display_name_html }}
2022-07-01 13:09:07 -07:00
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 (
2022-09-26 12:23:51 -07:00
<Card size='lg' variant='rounded' className='space-y-6'>
2022-07-01 13:09:07 -07:00
<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'
2023-02-01 14:13:42 -08:00
className='text-primary-600 hover:underline dark:text-accent-blue'
2022-07-01 13:09:07 -07:00
>
2022-07-06 06:04:26 -07:00
{intl.formatMessage(messages.viewAll)}
2022-07-01 13:09:07 -07:00
</Link>
</HStack>
<CardBody>
2023-02-01 14:13:42 -08:00
<HStack space={4} alignItems='center' className='overflow-x-auto md:space-x-0 lg:overflow-x-hidden'>
2022-07-01 13:09:07 -07:00
{suggestedProfiles.slice(0, 4).map((suggestedProfile) => (
<SuggestionItem key={suggestedProfile.account} accountId={suggestedProfile.account} />
))}
</HStack>
</CardBody>
</Card>
);
};
export default FeedSuggestions;