import clsx from 'clsx'; import React, { useEffect, useMemo, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; import { deleteStatus } from 'soapbox/actions/statuses'; import { useAppDispatch, useOwnAccount, useSettings, useSoapboxConfig } from 'soapbox/hooks'; import { defaultMediaVisibility } from 'soapbox/utils/status'; import DropdownMenu from '../dropdown-menu'; import { Button, HStack, Text } from '../ui'; import type { Status as StatusEntity } from 'soapbox/types/entities'; const messages = defineMessages({ delete: { id: 'status.delete', defaultMessage: 'Delete' }, deleteConfirm: { id: 'confirmations.delete.confirm', defaultMessage: 'Delete' }, deleteHeading: { id: 'confirmations.delete.heading', defaultMessage: 'Delete post' }, deleteMessage: { id: 'confirmations.delete.message', defaultMessage: 'Are you sure you want to delete this post?' }, hide: { id: 'moderation_overlay.hide', defaultMessage: 'Hide content' }, sensitiveTitle: { id: 'status.sensitive_warning', defaultMessage: 'Sensitive content' }, underReviewTitle: { id: 'moderation_overlay.title', defaultMessage: 'Content Under Review' }, underReviewSubtitle: { id: 'moderation_overlay.subtitle', defaultMessage: 'This Post has been sent to Moderation for review and is only visible to you. If you believe this is an error please contact Support.' }, sensitiveSubtitle: { id: 'status.sensitive_warning.subtitle', defaultMessage: 'This content may not be suitable for all audiences.' }, contact: { id: 'moderation_overlay.contact', defaultMessage: 'Contact' }, show: { id: 'moderation_overlay.show', defaultMessage: 'Show Content' }, }); interface ISensitiveContentOverlay { status: StatusEntity onToggleVisibility?(): void visible?: boolean } const SensitiveContentOverlay = React.forwardRef((props, ref) => { const { onToggleVisibility, status } = props; const account = useOwnAccount(); const dispatch = useAppDispatch(); const intl = useIntl(); const settings = useSettings(); const { links } = useSoapboxConfig(); const isUnderReview = status.visibility === 'self'; const isOwnStatus = status.getIn(['account', 'id']) === account?.id; const displayMedia = settings.get('displayMedia') as string; const [visible, setVisible] = useState(defaultMediaVisibility(status, displayMedia)); const toggleVisibility = (event: React.MouseEvent) => { event.stopPropagation(); if (onToggleVisibility) { onToggleVisibility(); } else { setVisible((prevValue) => !prevValue); } }; const handleDeleteStatus = () => { const deleteModal = settings.get('deleteModal'); if (!deleteModal) { dispatch(deleteStatus(status.id, false)); } else { dispatch(openModal('CONFIRM', { icon: require('@tabler/icons/trash.svg'), heading: intl.formatMessage(messages.deleteHeading), message: intl.formatMessage(messages.deleteMessage), confirm: intl.formatMessage(messages.deleteConfirm), onConfirm: () => dispatch(deleteStatus(status.id, false)), })); } }; const menu = useMemo(() => { return [ { text: intl.formatMessage(messages.delete), action: handleDeleteStatus, icon: require('@tabler/icons/trash.svg'), destructive: true, }, ]; }, []); useEffect(() => { if (typeof props.visible !== 'undefined') { setVisible(!!props.visible); } }, [props.visible]); return (
{visible ? ( )} ) : null} {(isUnderReview && isOwnStatus) ? ( ) : null}
)} ); }); export default SensitiveContentOverlay;