2022-09-29 07:44:06 -07:00
import classNames from 'clsx' ;
2022-10-20 07:48:41 -07:00
import React , { useEffect , useState } from 'react' ;
2022-09-29 07:44:06 -07:00
import { defineMessages , useIntl } from 'react-intl' ;
2022-10-20 07:48:41 -07:00
import { useSettings , useSoapboxConfig } from 'soapbox/hooks' ;
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-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-10-20 09:15:37 -07:00
const SensitiveContentOverlay = ( props : ISensitiveContentOverlay ) = > {
2022-10-20 07:48:41 -07:00
const { onToggleVisibility , status } = props ;
const isUnderReview = status . visibility === 'self' ;
const isSensitive = status . sensitive ;
const settings = useSettings ( ) ;
const displayMedia = settings . get ( 'displayMedia' ) as string | undefined ;
2022-09-29 07:44:06 -07:00
const intl = useIntl ( ) ;
const { links } = useSoapboxConfig ( ) ;
2022-10-20 07:48:41 -07:00
const [ visible , setVisible ] = useState < boolean > (
isUnderReview === true ? false : null
|| (
props . visible !== undefined
? props . visible
: ( displayMedia !== 'hide_all' && ! isSensitive || displayMedia === 'show_all' )
) ,
) ;
2022-09-29 07:44:06 -07: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-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
className = { classNames ( 'absolute z-40' , {
'cursor-default backdrop-blur-lg rounded-lg w-full h-full border-0 flex justify-center items-center' : ! visible ,
'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 ? (
< Button
text = { intl . formatMessage ( messages . hide ) }
icon = { require ( '@tabler/icons/eye-off.svg' ) }
onClick = { toggleVisibility }
2022-10-20 07:48:41 -07:00
theme = 'primary'
2022-09-29 07:44:06 -07:00
size = 'sm'
/ >
) : (
< div className = 'text-center w-3/4 mx-auto space-y-4' >
< div className = 'space-y-1' >
< Text theme = 'white' weight = 'semibold' >
2022-10-20 07:48:41 -07:00
{ intl . formatMessage ( isUnderReview ? messages.underReviewTitle : messages.sensitiveTitle ) }
2022-09-29 07:44:06 -07:00
< / Text >
< Text theme = 'white' size = 'sm' weight = 'medium' >
2022-10-20 07:48:41 -07:00
{ intl . formatMessage ( isUnderReview ? messages.underReviewSubtitle : messages.sensitiveSubtitle ) }
2022-09-29 07:44:06 -07:00
< / Text >
< / div >
< HStack alignItems = 'center' justifyContent = 'center' space = { 2 } >
2022-10-20 07:48:41 -07:00
{ isUnderReview ? (
< >
{ links . get ( 'support' ) && (
< a
href = { links . get ( 'support' ) }
target = '_blank'
onClick = { ( event ) = > event . stopPropagation ( ) }
>
< Button
type = 'button'
theme = 'outline'
size = 'sm'
icon = { require ( '@tabler/icons/headset.svg' ) }
>
{ intl . formatMessage ( messages . contact ) }
< / Button >
< / a >
) }
< / >
) : null }
2022-09-29 07:44:06 -07:00
< Button
type = 'button'
theme = 'outline'
size = 'sm'
icon = { require ( '@tabler/icons/eye.svg' ) }
onClick = { toggleVisibility }
>
{ intl . formatMessage ( messages . show ) }
< / Button >
< / HStack >
< / div >
) }
< / div >
) ;
} ;
2022-10-20 09:15:37 -07:00
export default SensitiveContentOverlay ;