import classNames from 'classnames'; import React, { useState } from 'react'; import { defineMessages, useIntl, FormattedMessage, FormattedList } from 'react-intl'; import { useHistory } from 'react-router-dom'; import StatusMedia from 'soapbox/components/status-media'; import { Stack, Text } from 'soapbox/components/ui'; import AccountContainer from 'soapbox/containers/account_container'; import { useSettings } from 'soapbox/hooks'; import { defaultMediaVisibility } from 'soapbox/utils/status'; import type { Account as AccountEntity, Status as StatusEntity } from 'soapbox/types/entities'; const messages = defineMessages({ cancel: { id: 'reply_indicator.cancel', defaultMessage: 'Cancel' }, }); interface IQuotedStatus { /** The quoted status entity. */ status?: StatusEntity, /** Callback when cancelled (during compose). */ onCancel?: Function, /** Whether the status is shown in the post composer. */ compose?: boolean, } /** Status embedded in a quote post. */ const QuotedStatus: React.FC = ({ status, onCancel, compose }) => { const intl = useIntl(); const history = useHistory(); const settings = useSettings(); const displayMedia = settings.get('displayMedia'); const [showMedia, setShowMedia] = useState(defaultMediaVisibility(status, displayMedia)); const handleExpandClick = (e: React.MouseEvent) => { if (!status) return; const account = status.account as AccountEntity; if (!compose && e.button === 0) { history.push(`/@${account.acct}/posts/${status.id}`); e.stopPropagation(); e.preventDefault(); } }; const handleClose = () => { if (onCancel) { onCancel(); } }; const handleToggleMediaVisibility = () => { setShowMedia(!showMedia); }; const renderReplyMentions = () => { if (!status?.in_reply_to_id) { return null; } const account = status.account as AccountEntity; const to = status.mentions || []; if (to.size === 0) { if (status.in_reply_to_account_id === account.id) { return (
); } else { return (
); } } const accounts = to.slice(0, 2).map(account => <>@{account.username}).toArray(); if (to.size > 2) { accounts.push( , ); } return (
, }} />
); }; if (!status) { return null; } const account = status.account as AccountEntity; let actions = {}; if (onCancel) { actions = { onActionClick: handleClose, actionIcon: require('@tabler/icons/icons/x.svg'), actionAlignment: 'top', actionTitle: intl.formatMessage(messages.cancel), }; } return ( {renderReplyMentions()} ); }; export default QuotedStatus;