import React, { useEffect } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { fetchAccount } from 'soapbox/actions/accounts'; import { addToMentions, removeFromMentions } from 'soapbox/actions/compose'; import Avatar from 'soapbox/components/avatar'; import DisplayName from 'soapbox/components/display-name'; import IconButton from 'soapbox/components/icon_button'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; import { makeGetAccount } from 'soapbox/selectors'; const messages = defineMessages({ remove: { id: 'reply_mentions.account.remove', defaultMessage: 'Remove from mentions' }, add: { id: 'reply_mentions.account.add', defaultMessage: 'Add to mentions' }, }); const getAccount = makeGetAccount(); interface IAccount { accountId: string, author: boolean, } const Account: React.FC = ({ accountId, author }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const account = useAppSelector((state) => getAccount(state, accountId)); const added = useAppSelector((state) => !!account && state.compose.to?.includes(account.acct)); const onRemove = () => dispatch(removeFromMentions(accountId)); const onAdd = () => dispatch(addToMentions(accountId)); useEffect(() => { if (accountId && !account) { dispatch(fetchAccount(accountId)); } }, []); if (!account) return null; let button; if (added) { button = ; } else { button = ; } return (
{!author && button}
); }; export default Account;