2022-04-10 01:48:56 -07:00
|
|
|
import React from 'react';
|
2022-05-16 11:30:42 -07:00
|
|
|
import { FormattedList, FormattedMessage } from 'react-intl';
|
2022-04-10 01:48:56 -07:00
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
|
|
|
import { openModal } from 'soapbox/actions/modals';
|
|
|
|
import { useAppSelector } from 'soapbox/hooks';
|
|
|
|
import { statusToMentionsAccountIdsArray } from 'soapbox/reducers/compose';
|
|
|
|
import { makeGetStatus } from 'soapbox/selectors';
|
|
|
|
import { getFeatures } from 'soapbox/utils/features';
|
|
|
|
|
|
|
|
import type { Status as StatusEntity } from 'soapbox/types/entities';
|
|
|
|
|
|
|
|
const ReplyMentions: React.FC = () => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const instance = useAppSelector((state) => state.instance);
|
2022-06-20 10:59:51 -07:00
|
|
|
const status = useAppSelector<StatusEntity | null>(state => makeGetStatus()(state, { id: state.compose.in_reply_to! }));
|
2022-04-10 01:48:56 -07:00
|
|
|
|
2022-06-20 10:59:51 -07:00
|
|
|
const to = useAppSelector((state) => state.compose.to);
|
2022-04-10 01:48:56 -07:00
|
|
|
const account = useAppSelector((state) => state.accounts.get(state.me));
|
|
|
|
|
|
|
|
const { explicitAddressing } = getFeatures(instance);
|
|
|
|
|
|
|
|
if (!explicitAddressing || !status || !to) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-06-20 10:59:51 -07:00
|
|
|
const parentTo = status && statusToMentionsAccountIdsArray(status, account!);
|
2022-04-10 01:48:56 -07:00
|
|
|
|
|
|
|
const handleClick = (e: React.MouseEvent<HTMLAnchorElement>) => {
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
dispatch(openModal('REPLY_MENTIONS'));
|
|
|
|
};
|
|
|
|
|
|
|
|
if (!parentTo || (parentTo.size === 0)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (to.size === 0) {
|
|
|
|
return (
|
|
|
|
<a href='#' className='reply-mentions' onClick={handleClick}>
|
|
|
|
<FormattedMessage
|
|
|
|
id='reply_mentions.reply_empty'
|
|
|
|
defaultMessage='Replying to post'
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-05-16 11:30:42 -07:00
|
|
|
const accounts = to.slice(0, 2).map((acct: string) => (
|
|
|
|
<span className='reply-mentions__account'>@{acct.split('@')[0]}</span>
|
|
|
|
)).toArray();
|
|
|
|
|
|
|
|
if (to.size > 2) {
|
|
|
|
accounts.push(
|
|
|
|
<FormattedMessage id='reply_mentions.more' defaultMessage='{count} more' values={{ count: to.size - 2 }} />,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-04-10 01:48:56 -07:00
|
|
|
return (
|
|
|
|
<a href='#' className='reply-mentions' onClick={handleClick}>
|
|
|
|
<FormattedMessage
|
|
|
|
id='reply_mentions.reply'
|
2022-05-16 11:30:42 -07:00
|
|
|
defaultMessage='Replying to {accounts}'
|
2022-04-10 01:48:56 -07:00
|
|
|
values={{
|
2022-05-16 11:30:42 -07:00
|
|
|
accounts: <FormattedList type='conjunction' value={accounts} />,
|
2022-04-10 01:48:56 -07:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default ReplyMentions;
|