import React, { useCallback } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { removeFromListEditor, addToListEditor } from 'soapbox/actions/lists'; import DisplayName from 'soapbox/components/display-name'; import IconButton from 'soapbox/components/icon-button'; import { Avatar } from 'soapbox/components/ui'; import { useAppSelector, useAppDispatch } from 'soapbox/hooks'; import { makeGetAccount } from 'soapbox/selectors'; const messages = defineMessages({ remove: { id: 'lists.account.remove', defaultMessage: 'Remove from list' }, add: { id: 'lists.account.add', defaultMessage: 'Add to list' }, }); interface IAccount { accountId: string, } const Account: React.FC = ({ accountId }) => { const intl = useIntl(); const dispatch = useAppDispatch(); const getAccount = useCallback(makeGetAccount(), []); const account = useAppSelector((state) => getAccount(state, accountId)); const isAdded = useAppSelector((state) => state.listEditor.accounts.items.includes(accountId)); const onRemove = () => dispatch(removeFromListEditor(accountId)); const onAdd = () => dispatch(addToListEditor(accountId)); if (!account) return null; let button; if (isAdded) { button = ; } else { button = ; } return (
{button}
); }; export default Account;