2022-05-30 09:18:31 -07:00
|
|
|
import React, { useEffect } from 'react';
|
2022-05-28 12:53:22 -07:00
|
|
|
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';
|
2022-09-14 11:01:00 -07:00
|
|
|
import { useAppDispatch, useAppSelector, useCompose } from 'soapbox/hooks';
|
2022-05-28 12:53:22 -07:00
|
|
|
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 {
|
2022-09-10 14:52:06 -07:00
|
|
|
composeId: string,
|
2022-05-28 12:53:22 -07:00
|
|
|
accountId: string,
|
|
|
|
author: boolean,
|
|
|
|
}
|
|
|
|
|
2022-09-10 14:52:06 -07:00
|
|
|
const Account: React.FC<IAccount> = ({ composeId, accountId, author }) => {
|
2022-05-28 12:53:22 -07:00
|
|
|
const intl = useIntl();
|
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
const account = useAppSelector((state) => getAccount(state, accountId));
|
2022-09-14 11:01:00 -07:00
|
|
|
const added = !!account && useCompose(composeId).to?.includes(account.acct);
|
2022-05-28 12:53:22 -07:00
|
|
|
|
|
|
|
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) {
|
2022-07-09 09:20:02 -07:00
|
|
|
button = <IconButton src={require('@tabler/icons/x.svg')} title={intl.formatMessage(messages.remove)} onClick={onRemove} />;
|
2022-05-28 12:53:22 -07:00
|
|
|
} else {
|
2022-07-09 09:20:02 -07:00
|
|
|
button = <IconButton src={require('@tabler/icons/plus.svg')} title={intl.formatMessage(messages.add)} onClick={onAdd} />;
|
2022-05-28 12:53:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className='account'>
|
|
|
|
<div className='account__wrapper'>
|
|
|
|
<div className='account__display-name'>
|
|
|
|
<div className='account__avatar-wrapper'><Avatar account={account} size={36} /></div>
|
|
|
|
<DisplayName account={account} />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div className='account__relationship'>
|
|
|
|
{!author && button}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Account;
|