import classNames from 'clsx'; import React, { useEffect, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { useSettings, useSoapboxConfig } from 'soapbox/hooks'; import { Button, HStack, Text } from '../ui'; import type { Status as StatusEntity } from 'soapbox/types/entities'; const messages = defineMessages({ 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 = (props: ISensitiveContentOverlay) => { const { onToggleVisibility, status } = props; const isUnderReview = status.visibility === 'self'; const isSensitive = status.sensitive; const settings = useSettings(); const displayMedia = settings.get('displayMedia') as string | undefined; const intl = useIntl(); const { links } = useSoapboxConfig(); const [visible, setVisible] = useState( isUnderReview === true ? false : null || ( props.visible !== undefined ? props.visible : (displayMedia !== 'hide_all' && !isSensitive || displayMedia === 'show_all') ), ); const toggleVisibility = (event: React.MouseEvent) => { event.stopPropagation(); if (onToggleVisibility) { onToggleVisibility(); } else { setVisible((prevValue) => !prevValue); } }; useEffect(() => { if (typeof props.visible !== 'undefined') { setVisible(!!props.visible); } }, [props.visible]); return (
{visible ? ( )} ) : null}
)} ); }; export default SensitiveContentOverlay;