2023-02-06 10:01:03 -08:00
|
|
|
import clsx from 'clsx';
|
2024-04-21 10:07:14 -07:00
|
|
|
import React from 'react';
|
2022-09-29 07:44:06 -07:00
|
|
|
import { defineMessages, useIntl } from 'react-intl';
|
|
|
|
|
2024-08-23 15:27:40 -07:00
|
|
|
import { toggleStatusMediaHidden } from 'soapbox/actions/statuses';
|
2024-04-21 10:07:14 -07:00
|
|
|
import { useAppDispatch, useSettings } from 'soapbox/hooks';
|
2022-09-29 07:44:06 -07:00
|
|
|
|
|
|
|
import { Button, HStack, Text } from '../ui';
|
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
import type { Status } from 'soapbox/normalizers';
|
2022-10-20 07:48:41 -07:00
|
|
|
|
2022-09-29 07:44:06 -07:00
|
|
|
const messages = defineMessages({
|
2022-11-28 06:05:13 -08:00
|
|
|
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?' },
|
2022-10-20 07:48:41 -07:00
|
|
|
hide: { id: 'moderation_overlay.hide', defaultMessage: 'Hide content' },
|
|
|
|
sensitiveTitle: { id: 'status.sensitive_warning', defaultMessage: 'Sensitive content' },
|
|
|
|
sensitiveSubtitle: { id: 'status.sensitive_warning.subtitle', defaultMessage: 'This content may not be suitable for all audiences.' },
|
2022-09-29 07:44:06 -07:00
|
|
|
show: { id: 'moderation_overlay.show', defaultMessage: 'Show Content' },
|
|
|
|
});
|
|
|
|
|
2022-10-20 09:15:37 -07:00
|
|
|
interface ISensitiveContentOverlay {
|
2024-08-23 14:50:00 -07:00
|
|
|
status: Pick<Status, 'id' | 'sensitive' | 'hidden' | 'media_attachments' | 'currentLanguage'>;
|
2022-10-20 07:48:41 -07:00
|
|
|
}
|
|
|
|
|
2022-11-17 05:03:15 -08:00
|
|
|
const SensitiveContentOverlay = React.forwardRef<HTMLDivElement, ISensitiveContentOverlay>((props, ref) => {
|
2024-04-21 10:07:14 -07:00
|
|
|
const { status } = props;
|
2022-10-20 07:48:41 -07:00
|
|
|
|
2022-11-28 06:05:13 -08:00
|
|
|
const dispatch = useAppDispatch();
|
2022-09-29 07:44:06 -07:00
|
|
|
const intl = useIntl();
|
2024-04-21 13:06:53 -07:00
|
|
|
const { displayMedia } = useSettings();
|
2022-09-29 07:44:06 -07:00
|
|
|
|
2024-04-21 13:06:53 -07:00
|
|
|
let visible = !status.sensitive;
|
2022-11-28 06:05:13 -08:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
if (status.hidden !== null) visible = !status.hidden;
|
2024-04-21 13:06:53 -07:00
|
|
|
else if (displayMedia === 'show_all') visible = true;
|
2024-08-11 01:48:58 -07:00
|
|
|
else if (displayMedia === 'hide_all' && status.media_attachments.length) visible = false;
|
2024-04-21 13:06:53 -07:00
|
|
|
|
2024-08-11 01:48:58 -07:00
|
|
|
const showHideButton = status.sensitive || (status.media_attachments.length && displayMedia === 'hide_all');
|
2022-09-29 07:44:06 -07:00
|
|
|
|
2022-11-19 14:08:58 -08:00
|
|
|
const toggleVisibility = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
|
|
event.stopPropagation();
|
|
|
|
|
2024-08-23 15:27:40 -07:00
|
|
|
dispatch(toggleStatusMediaHidden(status));
|
2022-09-29 07:44:06 -07:00
|
|
|
};
|
|
|
|
|
2024-04-21 13:06:53 -07:00
|
|
|
if (visible && !showHideButton) return null;
|
|
|
|
|
2022-09-29 07:44:06 -07:00
|
|
|
return (
|
|
|
|
<div
|
2023-02-06 10:01:03 -08:00
|
|
|
className={clsx('absolute z-40', {
|
2023-01-15 14:05:04 -08:00
|
|
|
'cursor-default backdrop-blur-lg rounded-lg w-full h-full border-0 flex justify-center': !visible,
|
2022-09-29 07:44:06 -07:00
|
|
|
'bg-gray-800/75 inset-0': !visible,
|
2022-10-20 07:48:41 -07:00
|
|
|
'bottom-1 right-1': visible,
|
2022-09-29 07:44:06 -07:00
|
|
|
})}
|
2022-10-20 07:48:41 -07:00
|
|
|
data-testid='sensitive-overlay'
|
2022-09-29 07:44:06 -07:00
|
|
|
>
|
|
|
|
{visible ? (
|
2022-11-19 14:08:58 -08:00
|
|
|
<Button
|
|
|
|
text={intl.formatMessage(messages.hide)}
|
2024-04-03 04:28:30 -07:00
|
|
|
icon={require('@tabler/icons/outline/eye-off.svg')}
|
2022-11-19 14:08:58 -08:00
|
|
|
onClick={toggleVisibility}
|
|
|
|
theme='primary'
|
|
|
|
size='sm'
|
|
|
|
/>
|
2022-09-29 07:44:06 -07:00
|
|
|
) : (
|
2023-02-01 14:13:42 -08:00
|
|
|
<div className='flex max-h-screen items-center justify-center'>
|
2024-05-27 15:11:28 -07:00
|
|
|
<div className='mx-auto space-y-4 text-center' ref={ref}>
|
2023-01-15 14:05:04 -08:00
|
|
|
<div className='space-y-1'>
|
|
|
|
<Text theme='white' weight='semibold'>
|
2024-04-21 10:07:14 -07:00
|
|
|
{intl.formatMessage(messages.sensitiveTitle)}
|
2023-01-15 14:05:04 -08:00
|
|
|
</Text>
|
|
|
|
|
|
|
|
<Text theme='white' size='sm' weight='medium'>
|
2024-04-21 10:07:14 -07:00
|
|
|
{intl.formatMessage(messages.sensitiveSubtitle)}
|
2023-01-15 14:05:04 -08:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<HStack alignItems='center' justifyContent='center' space={2}>
|
|
|
|
<Button
|
|
|
|
type='button'
|
|
|
|
theme='outline'
|
|
|
|
size='sm'
|
2024-04-03 04:28:30 -07:00
|
|
|
icon={require('@tabler/icons/outline/eye.svg')}
|
2023-01-15 14:05:04 -08:00
|
|
|
onClick={toggleVisibility}
|
|
|
|
>
|
|
|
|
{intl.formatMessage(messages.show)}
|
|
|
|
</Button>
|
|
|
|
</HStack>
|
|
|
|
</div>
|
2022-09-29 07:44:06 -07:00
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
);
|
2022-11-17 05:03:15 -08:00
|
|
|
});
|
2022-09-29 07:44:06 -07:00
|
|
|
|
2024-05-13 10:00:42 -07:00
|
|
|
export { SensitiveContentOverlay as default };
|