2022-05-28 09:02:04 -07:00
|
|
|
import React from 'react';
|
|
|
|
import { FormattedList, FormattedMessage } from 'react-intl';
|
|
|
|
import { Link } from 'react-router-dom';
|
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import { openModal } from 'pl-fe/actions/modals';
|
|
|
|
import HoverRefWrapper from 'pl-fe/components/hover-ref-wrapper';
|
|
|
|
import HoverStatusWrapper from 'pl-fe/components/hover-status-wrapper';
|
|
|
|
import { useAppDispatch } from 'pl-fe/hooks';
|
2022-05-28 09:02:04 -07:00
|
|
|
|
2024-08-28 04:41:08 -07:00
|
|
|
import type { Status } from 'pl-fe/normalizers';
|
2022-05-28 09:02:04 -07:00
|
|
|
|
|
|
|
interface IStatusReplyMentions {
|
2024-08-22 07:46:46 -07:00
|
|
|
status: Pick<Status, 'in_reply_to_id' | 'id' | 'mentions'>;
|
2023-10-02 11:54:02 -07:00
|
|
|
hoverable?: boolean;
|
2022-05-28 09:02:04 -07:00
|
|
|
}
|
|
|
|
|
2022-06-20 15:37:20 -07:00
|
|
|
const StatusReplyMentions: React.FC<IStatusReplyMentions> = ({ status, hoverable = true }) => {
|
2022-05-28 09:02:04 -07:00
|
|
|
const dispatch = useAppDispatch();
|
|
|
|
|
|
|
|
const handleOpenMentionsModal: React.MouseEventHandler<HTMLSpanElement> = (e) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
|
2024-08-22 07:46:46 -07:00
|
|
|
dispatch(openModal('MENTIONS', { statusId: status.id }));
|
2022-05-28 09:02:04 -07:00
|
|
|
};
|
|
|
|
|
2022-06-04 06:20:19 -07:00
|
|
|
if (!status.in_reply_to_id) {
|
2022-05-28 09:02:04 -07:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-06-04 06:20:19 -07:00
|
|
|
const to = status.mentions;
|
2022-05-28 09:02:04 -07:00
|
|
|
|
|
|
|
// The post is a reply, but it has no mentions.
|
|
|
|
// Rare, but it can happen.
|
2024-08-11 01:48:58 -07:00
|
|
|
if (to.length === 0) {
|
2022-05-28 09:02:04 -07:00
|
|
|
return (
|
2024-04-29 06:49:09 -07:00
|
|
|
<div className='mb-1 block text-sm text-gray-700 dark:text-gray-600'>
|
2022-05-28 09:02:04 -07:00
|
|
|
<FormattedMessage
|
|
|
|
id='reply_mentions.reply_empty'
|
|
|
|
defaultMessage='Replying to post'
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The typical case with a reply-to and a list of mentions.
|
2022-06-20 15:37:20 -07:00
|
|
|
const accounts = to.slice(0, 2).map(account => {
|
|
|
|
const link = (
|
2023-01-25 07:06:03 -08:00
|
|
|
<Link
|
|
|
|
key={account.id}
|
|
|
|
to={`/@${account.acct}`}
|
2024-04-29 06:49:09 -07:00
|
|
|
className='inline-block max-w-[200px] truncate align-bottom text-primary-600 no-underline [direction:ltr] hover:text-primary-700 hover:underline dark:text-accent-blue dark:hover:text-accent-blue'
|
2023-01-25 07:06:03 -08:00
|
|
|
onClick={(e) => e.stopPropagation()}
|
|
|
|
>
|
2024-04-29 09:43:33 -07:00
|
|
|
@{account.username}
|
2023-01-25 07:06:03 -08:00
|
|
|
</Link>
|
2022-06-20 15:37:20 -07:00
|
|
|
);
|
|
|
|
|
|
|
|
if (hoverable) {
|
|
|
|
return (
|
|
|
|
<HoverRefWrapper key={account.id} accountId={account.id} inline>
|
|
|
|
{link}
|
|
|
|
</HoverRefWrapper>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return link;
|
|
|
|
}
|
2024-08-11 01:48:58 -07:00
|
|
|
});
|
2022-05-28 09:02:04 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
if (to.length > 2) {
|
2022-05-28 09:02:04 -07:00
|
|
|
accounts.push(
|
2023-02-01 14:13:42 -08:00
|
|
|
<span key='more' className='cursor-pointer hover:underline' role='button' onClick={handleOpenMentionsModal} tabIndex={0}>
|
2024-08-11 01:48:58 -07:00
|
|
|
<FormattedMessage id='reply_mentions.more' defaultMessage='{count} more' values={{ count: to.length - 2 }} />
|
2022-05-28 09:02:04 -07:00
|
|
|
</span>,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2024-04-29 06:49:09 -07:00
|
|
|
<div className='mb-1 block text-sm text-gray-700 dark:text-gray-600'>
|
2022-05-28 09:02:04 -07:00
|
|
|
<FormattedMessage
|
2022-11-16 14:52:12 -08:00
|
|
|
id='reply_mentions.reply.hoverable'
|
2022-06-16 21:19:53 -07:00
|
|
|
defaultMessage='<hover>Replying to</hover> {accounts}'
|
2022-05-28 09:02:04 -07:00
|
|
|
values={{
|
|
|
|
accounts: <FormattedList type='conjunction' value={accounts} />,
|
2023-01-10 15:03:15 -08:00
|
|
|
// @ts-ignore wtf?
|
2022-06-20 15:37:20 -07:00
|
|
|
hover: (children: React.ReactNode) => {
|
|
|
|
if (hoverable) {
|
|
|
|
return (
|
|
|
|
<HoverStatusWrapper statusId={status.in_reply_to_id} inline>
|
|
|
|
<span
|
|
|
|
key='hoverstatus'
|
2023-02-01 14:13:42 -08:00
|
|
|
className='cursor-pointer hover:underline'
|
2022-06-20 15:37:20 -07:00
|
|
|
role='presentation'
|
|
|
|
>
|
|
|
|
{children}
|
|
|
|
</span>
|
|
|
|
</HoverStatusWrapper>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return children;
|
|
|
|
}
|
|
|
|
},
|
2022-05-28 09:02:04 -07:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2024-05-13 10:00:42 -07:00
|
|
|
export { StatusReplyMentions as default };
|