2022-03-21 11:09:01 -07:00
|
|
|
import * as React from 'react';
|
2022-06-05 07:17:26 -07:00
|
|
|
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
2022-03-21 11:09:01 -07:00
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
2022-05-30 11:23:55 -07:00
|
|
|
import { fetchSuggestions, dismissSuggestion } from 'soapbox/actions/suggestions';
|
2022-03-25 12:08:12 -07:00
|
|
|
import { Widget } from 'soapbox/components/ui';
|
2022-05-30 11:23:55 -07:00
|
|
|
import AccountContainer from 'soapbox/containers/account_container';
|
2022-03-21 11:09:01 -07:00
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
|
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 dispatch = useDispatch();
|
|
|
|
const intl = useIntl();
|
|
|
|
|
2022-06-05 07:17:26 -07:00
|
|
|
const suggestions = useAppSelector((state) => state.suggestions.items);
|
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) => {
|
|
|
|
dispatch(dismissSuggestion(account.id));
|
2022-03-21 11:09:01 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
dispatch(fetchSuggestions());
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
if (suggestionsToRender.isEmpty()) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-04-18 20:49:17 -07:00
|
|
|
// FIXME: This page actually doesn't look good right now
|
|
|
|
// const handleAction = () => {
|
|
|
|
// history.push('/suggestions');
|
|
|
|
// };
|
|
|
|
|
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' />}
|
|
|
|
// onAction={handleAction}
|
|
|
|
>
|
2022-06-05 07:17:26 -07:00
|
|
|
{suggestionsToRender.map((suggestion) => (
|
2022-03-25 12:08:12 -07:00
|
|
|
<AccountContainer
|
2022-06-05 07:17:26 -07:00
|
|
|
key={suggestion.account}
|
2022-03-25 12:08:12 -07:00
|
|
|
// @ts-ignore: TS thinks `id` is passed to <Account>, but it isn't
|
2022-06-05 07:17:26 -07:00
|
|
|
id={suggestion.account}
|
2022-07-09 09:20:02 -07:00
|
|
|
actionIcon={require('@tabler/icons/x.svg')}
|
2022-03-25 12:08:12 -07:00
|
|
|
actionTitle={intl.formatMessage(messages.dismissSuggestion)}
|
|
|
|
onActionClick={handleDismiss}
|
|
|
|
/>
|
|
|
|
))}
|
|
|
|
</Widget>
|
2022-03-21 11:09:01 -07:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default WhoToFollowPanel;
|