2022-11-25 09:04:11 -08:00
|
|
|
import React from 'react';
|
2022-06-05 07:17:26 -07:00
|
|
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
2022-09-26 12:22:00 -07:00
|
|
|
import { Link } from 'react-router-dom';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-09-26 12:22:00 -07:00
|
|
|
import { Text, Widget } from 'soapbox/components/ui';
|
2022-11-15 08:13:54 -08:00
|
|
|
import AccountContainer from 'soapbox/containers/account-container';
|
2022-09-26 12:22:00 -07:00
|
|
|
import PlaceholderSidebarSuggestions from 'soapbox/features/placeholder/components/placeholder-sidebar-suggestions';
|
|
|
|
import { useDismissSuggestion, useSuggestions } from 'soapbox/queries/suggestions';
|
2022-03-21 11:09:01 -07:00
|
|
|
|
2022-06-05 07:17:26 -07:00
|
|
|
import type { Account as AccountEntity } from 'soapbox/types/entities';
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
const messages = defineMessages({
|
|
|
|
dismissSuggestion: { id: 'suggestions.dismiss', defaultMessage: 'Dismiss suggestion' },
|
|
|
|
});
|
|
|
|
|
|
|
|
interface IWhoToFollowPanel {
|
|
|
|
limit: number
|
|
|
|
}
|
|
|
|
|
|
|
|
const WhoToFollowPanel = ({ limit }: IWhoToFollowPanel) => {
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-09-26 12:22:00 -07:00
|
|
|
const { data: suggestions, isFetching } = useSuggestions();
|
|
|
|
const dismissSuggestion = useDismissSuggestion();
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
const suggestionsToRender = suggestions.slice(0, limit);
|
|
|
|
|
2022-06-05 07:17:26 -07:00
|
|
|
const handleDismiss = (account: AccountEntity) => {
|
2022-09-26 12:22:00 -07:00
|
|
|
dismissSuggestion.mutate(account.id);
|
2022-03-21 11:09:01 -07:00
|
|
|
};
|
|
|
|
|
2022-09-28 15:06:37 -07:00
|
|
|
if (!isFetching && !suggestions.length) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-03-21 11:09:01 -07:00
|
|
|
return (
|
2022-04-18 20:49:17 -07:00
|
|
|
<Widget
|
|
|
|
title={<FormattedMessage id='who_to_follow.title' defaultMessage='People To Follow' />}
|
2022-09-26 12:22:00 -07:00
|
|
|
action={
|
2023-01-23 14:59:30 -08:00
|
|
|
<Link className='text-right' to='/suggestions'>
|
2022-12-18 09:43:40 -08:00
|
|
|
<Text tag='span' theme='primary' size='sm' className='hover:underline'>
|
|
|
|
<FormattedMessage id='feed_suggestions.view_all' defaultMessage='View all' />
|
|
|
|
</Text>
|
2022-09-26 12:22:00 -07:00
|
|
|
</Link>
|
|
|
|
}
|
2022-04-18 20:49:17 -07:00
|
|
|
>
|
2022-09-26 12:22:00 -07:00
|
|
|
{isFetching ? (
|
|
|
|
<PlaceholderSidebarSuggestions limit={limit} />
|
|
|
|
) : (
|
|
|
|
suggestionsToRender.map((suggestion: any) => (
|
|
|
|
<AccountContainer
|
|
|
|
key={suggestion.account}
|
|
|
|
// @ts-ignore: TS thinks `id` is passed to <Account>, but it isn't
|
|
|
|
id={suggestion.account}
|
|
|
|
actionIcon={require('@tabler/icons/x.svg')}
|
|
|
|
actionTitle={intl.formatMessage(messages.dismissSuggestion)}
|
|
|
|
onActionClick={handleDismiss}
|
|
|
|
/>
|
|
|
|
))
|
|
|
|
)}
|
2022-03-25 12:08:12 -07:00
|
|
|
</Widget>
|
2022-03-21 11:09:01 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WhoToFollowPanel;
|