2022-11-26 08:38:16 -08:00
import React , { useState , useCallback } from 'react' ;
2022-05-30 09:18:31 -07:00
import { defineMessages , useIntl } from 'react-intl' ;
2022-11-15 08:00:49 -08:00
import ScrollableList from 'soapbox/components/scrollable-list' ;
2022-11-16 09:30:24 -08:00
import { Accordion } from 'soapbox/components/ui' ;
2022-11-26 08:38:16 -08:00
import { useAppSelector , useInstance } from 'soapbox/hooks' ;
2022-05-30 09:18:31 -07:00
import { makeGetHosts } from 'soapbox/selectors' ;
import { federationRestrictionsDisclosed } from 'soapbox/utils/state' ;
import Column from '../ui/components/column' ;
2022-11-15 11:00:40 -08:00
import RestrictedInstance from './components/restricted-instance' ;
2022-05-30 09:18:31 -07:00
import type { OrderedSet as ImmutableOrderedSet } from 'immutable' ;
const messages = defineMessages ( {
heading : { id : 'column.federation_restrictions' , defaultMessage : 'Federation Restrictions' } ,
boxTitle : { id : 'federation_restrictions.explanation_box.title' , defaultMessage : 'Instance-specific policies' } ,
boxMessage : { id : 'federation_restrictions.explanation_box.message' , defaultMessage : 'Normally servers on the Fediverse can communicate freely. {siteTitle} has imposed restrictions on the following servers.' } ,
emptyMessage : { id : 'federation_restrictions.empty_message' , defaultMessage : '{siteTitle} has not restricted any instances.' } ,
notDisclosed : { id : 'federation_restrictions.not_disclosed_message' , defaultMessage : '{siteTitle} does not disclose federation restrictions through the API.' } ,
} ) ;
const FederationRestrictions = ( ) = > {
const intl = useIntl ( ) ;
2022-11-26 08:38:16 -08:00
const instance = useInstance ( ) ;
const getHosts = useCallback ( makeGetHosts ( ) , [ ] ) ;
2022-05-30 09:18:31 -07:00
const hosts = useAppSelector ( ( state ) = > getHosts ( state ) ) as ImmutableOrderedSet < string > ;
const disclosed = useAppSelector ( ( state ) = > federationRestrictionsDisclosed ( state ) ) ;
const [ explanationBoxExpanded , setExplanationBoxExpanded ] = useState ( true ) ;
const toggleExplanationBox = ( setting : boolean ) = > {
setExplanationBoxExpanded ( setting ) ;
} ;
const emptyMessage = disclosed ? messages.emptyMessage : messages.notDisclosed ;
return (
< Column icon = 'gavel' label = { intl . formatMessage ( messages . heading ) } >
2022-07-10 15:02:08 -07:00
< Accordion
headline = { intl . formatMessage ( messages . boxTitle ) }
expanded = { explanationBoxExpanded }
onToggle = { toggleExplanationBox }
>
2022-11-26 08:38:16 -08:00
{ intl . formatMessage ( messages . boxMessage , { siteTitle : instance.title } ) }
2022-07-10 15:02:08 -07:00
< / Accordion >
< div className = 'pt-4' >
2022-11-26 08:38:16 -08:00
< ScrollableList emptyMessage = { intl . formatMessage ( emptyMessage , { siteTitle : instance.title } ) } >
2022-05-30 09:18:31 -07:00
{ hosts . map ( ( host ) = > < RestrictedInstance key = { host } host = { host } / > ) }
< / ScrollableList >
< / div >
< / Column >
) ;
} ;
export default FederationRestrictions ;