2023-02-06 10:01:03 -08:00
import clsx from 'clsx' ;
2022-11-28 06:05:13 -08:00
import React , { useEffect , useMemo , useState } from 'react' ;
2022-09-29 07:44:06 -07:00
import { defineMessages , useIntl } from 'react-intl' ;
2022-11-28 06:05:13 -08:00
import { openModal } from 'soapbox/actions/modals' ;
import { deleteStatus } from 'soapbox/actions/statuses' ;
import { useAppDispatch , useOwnAccount , useSettings , useSoapboxConfig } from 'soapbox/hooks' ;
2022-10-20 09:27:59 -07:00
import { defaultMediaVisibility } from 'soapbox/utils/status' ;
2022-09-29 07:44:06 -07:00
2023-02-09 09:42:46 -08:00
import DropdownMenu from '../dropdown-menu' ;
2022-09-29 07:44:06 -07:00
import { Button , HStack , Text } from '../ui' ;
2022-10-20 07:48:41 -07:00
import type { Status as StatusEntity } from 'soapbox/types/entities' ;
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' } ,
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.' } ,
2022-09-29 07:44:06 -07:00
contact : { id : 'moderation_overlay.contact' , defaultMessage : 'Contact' } ,
show : { id : 'moderation_overlay.show' , defaultMessage : 'Show Content' } ,
} ) ;
2022-10-20 09:15:37 -07:00
interface ISensitiveContentOverlay {
2022-10-20 07:48:41 -07:00
status : StatusEntity
onToggleVisibility ? ( ) : void
visible? : boolean
}
2022-11-17 05:03:15 -08:00
const SensitiveContentOverlay = React . forwardRef < HTMLDivElement , ISensitiveContentOverlay > ( ( props , ref ) = > {
2022-10-20 07:48:41 -07:00
const { onToggleVisibility , status } = props ;
2022-11-28 06:05:13 -08:00
const account = useOwnAccount ( ) ;
const dispatch = useAppDispatch ( ) ;
2022-09-29 07:44:06 -07:00
const intl = useIntl ( ) ;
2022-11-28 06:05:13 -08:00
const settings = useSettings ( ) ;
2022-09-29 07:44:06 -07:00
const { links } = useSoapboxConfig ( ) ;
2022-11-28 06:05:13 -08:00
const isUnderReview = status . visibility === 'self' ;
const isOwnStatus = status . getIn ( [ 'account' , 'id' ] ) === account ? . id ;
const displayMedia = settings . get ( 'displayMedia' ) as string ;
2022-10-20 09:27:59 -07:00
const [ visible , setVisible ] = useState < boolean > ( defaultMediaVisibility ( status , displayMedia ) ) ;
2022-09-29 07:44:06 -07:00
2022-11-19 14:08:58 -08:00
const toggleVisibility = ( event : React.MouseEvent < HTMLButtonElement > ) = > {
event . stopPropagation ( ) ;
2022-10-20 07:48:41 -07:00
if ( onToggleVisibility ) {
onToggleVisibility ( ) ;
} else {
setVisible ( ( prevValue ) = > ! prevValue ) ;
}
2022-09-29 07:44:06 -07:00
} ;
2022-11-28 06:05:13 -08:00
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 ,
} ,
] ;
} , [ ] ) ;
2022-10-20 07:48:41 -07:00
useEffect ( ( ) = > {
if ( typeof props . visible !== 'undefined' ) {
setVisible ( ! ! props . visible ) ;
}
} , [ props . visible ] ) ;
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 ) }
icon = { require ( '@tabler/icons/eye-off.svg' ) }
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' >
< div className = 'mx-auto w-3/4 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' >
{ intl . formatMessage ( isUnderReview ? messages.underReviewTitle : messages.sensitiveTitle ) }
< / Text >
< Text theme = 'white' size = 'sm' weight = 'medium' >
{ intl . formatMessage ( isUnderReview ? messages.underReviewSubtitle : messages.sensitiveSubtitle ) }
< / Text >
{ status . spoiler_text && (
< div className = 'py-4 italic' >
< Text className = 'line-clamp-6' theme = 'white' size = 'md' weight = 'medium' >
& ldquo ; < span dangerouslySetInnerHTML = { { __html : status.spoilerHtml } } / > & rdquo ;
< / Text >
< / div >
) }
< / div >
< HStack alignItems = 'center' justifyContent = 'center' space = { 2 } >
{ isUnderReview ? (
< >
{ links . get ( 'support' ) && (
< a
href = { links . get ( 'support' ) }
target = '_blank'
onClick = { ( event ) = > event . stopPropagation ( ) }
2022-11-19 14:08:58 -08:00
>
2023-01-15 14:05:04 -08:00
< Button
type = 'button'
theme = 'outline'
size = 'sm'
icon = { require ( '@tabler/icons/headset.svg' ) }
>
{ intl . formatMessage ( messages . contact ) }
< / Button >
< / a >
) }
< / >
) : null }
< Button
type = 'button'
theme = 'outline'
size = 'sm'
icon = { require ( '@tabler/icons/eye.svg' ) }
onClick = { toggleVisibility }
>
{ intl . formatMessage ( messages . show ) }
< / Button >
{ ( isUnderReview && isOwnStatus ) ? (
< DropdownMenu
items = { menu }
src = { require ( '@tabler/icons/dots.svg' ) }
/ >
) : null }
< / 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
2022-11-17 05:03:15 -08:00
export default SensitiveContentOverlay ;