bigbuffet-rw/app/soapbox/features/ui/components/who-to-follow-panel.tsx

64 lines
1.9 KiB
TypeScript
Raw Normal View History

2022-03-21 11:09:01 -07:00
import * as React from 'react';
import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
2022-03-21 11:09:01 -07:00
import { useDispatch } from 'react-redux';
import { fetchSuggestions, dismissSuggestion } from 'soapbox/actions/suggestions';
import { Widget } from 'soapbox/components/ui';
import AccountContainer from 'soapbox/containers/account_container';
2022-03-21 11:09:01 -07:00
import { useAppSelector } from 'soapbox/hooks';
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();
const suggestions = useAppSelector((state) => state.suggestions.items);
2022-03-21 11:09:01 -07:00
const suggestionsToRender = suggestions.slice(0, limit);
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}
>
{suggestionsToRender.map((suggestion) => (
<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}
/>
))}
</Widget>
2022-03-21 11:09:01 -07:00
);
};
export default WhoToFollowPanel;