import PropTypes from 'prop-types'; import { useCallback } from 'react'; import { FormattedMessage, useIntl, defineMessages } from 'react-intl'; import { Link } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import CloseIcon from '@/material-icons/400-24px/close.svg?react'; import { followAccount, unfollowAccount } from 'mastodon/actions/accounts'; import { dismissSuggestion } from 'mastodon/actions/suggestions'; import { Avatar } from 'mastodon/components/avatar'; import { Button } from 'mastodon/components/button'; import { DisplayName } from 'mastodon/components/display_name'; import { IconButton } from 'mastodon/components/icon_button'; import { domain } from 'mastodon/initial_state'; const messages = defineMessages({ follow: { id: 'account.follow', defaultMessage: 'Follow' }, unfollow: { id: 'account.unfollow', defaultMessage: 'Unfollow' }, dismiss: { id: 'follow_suggestions.dismiss', defaultMessage: "Don't show again" }, }); export const Card = ({ id, source }) => { const intl = useIntl(); const account = useSelector(state => state.getIn(['accounts', id])); const relationship = useSelector(state => state.getIn(['relationships', id])); const dispatch = useDispatch(); const following = relationship?.get('following') ?? relationship?.get('requested'); const handleFollow = useCallback(() => { if (following) { dispatch(unfollowAccount(id)); } else { dispatch(followAccount(id)); } }, [id, following, dispatch]); const handleDismiss = useCallback(() => { dispatch(dismissSuggestion(id)); }, [id, dispatch]); let label; switch (source) { case 'friends_of_friends': label = ; break; case 'similar_to_recently_followed': label = ; break; case 'featured': label = ; break; case 'most_followed': label = ; break; case 'most_interactions': label = ; break; } return (
{label}
); }; Card.propTypes = { id: PropTypes.string.isRequired, source: PropTypes.oneOf(['friends_of_friends', 'similar_to_recently_followed', 'featured', 'most_followed', 'most_interactions']), };