import React from 'react'; import { FormattedList, FormattedMessage } from 'react-intl'; import { Link } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; import HoverRefWrapper from 'soapbox/components/hover-ref-wrapper'; import HoverStatusWrapper from 'soapbox/components/hover-status-wrapper'; import { useAppDispatch } from 'soapbox/hooks'; import type { Account, Status } from 'soapbox/types/entities'; interface IStatusReplyMentions { status: Status, hoverable?: boolean, } const StatusReplyMentions: React.FC = ({ status, hoverable = true }) => { const dispatch = useAppDispatch(); const handleOpenMentionsModal: React.MouseEventHandler = (e) => { e.stopPropagation(); const account = status.account as Account; dispatch(openModal('MENTIONS', { username: account.acct, statusId: status.id, })); }; if (!status.in_reply_to_id) { return null; } const to = status.mentions; // The post is a reply, but it has no mentions. // Rare, but it can happen. if (to.size === 0) { return (
); } // The typical case with a reply-to and a list of mentions. const accounts = to.slice(0, 2).map(account => { const link = ( e.stopPropagation()}>@{account.username} ); if (hoverable) { return ( {link} ); } else { return link; } }).toArray(); if (to.size > 2) { accounts.push( , ); } return (
, // @ts-ignore wtf? hover: (children: React.ReactNode) => { if (hoverable) { return ( {children} ); } else { return children; } }, }} />
); }; export default StatusReplyMentions;