2022-06-09 11:56:14 -07:00
import React , { useEffect } from 'react' ;
import { defineMessages , FormattedMessage , useIntl } from 'react-intl' ;
import { Link } from 'react-router-dom' ;
import { changeSetting } from 'soapbox/actions/settings' ;
import { connectPublicStream } from 'soapbox/actions/streaming' ;
import { expandPublicTimeline } from 'soapbox/actions/timelines' ;
2022-07-13 18:13:37 -07:00
import PullToRefresh from 'soapbox/components/pull-to-refresh' ;
2022-11-15 08:00:49 -08:00
import SubNavigation from 'soapbox/components/sub-navigation' ;
2022-11-16 09:30:24 -08:00
import { Accordion , Column } from 'soapbox/components/ui' ;
2022-06-09 11:56:14 -07:00
import { useAppDispatch , useAppSelector , useSettings } from 'soapbox/hooks' ;
2022-11-15 11:00:40 -08:00
import PinnedHostsPicker from '../remote-timeline/components/pinned-hosts-picker' ;
2022-06-09 11:56:14 -07:00
import Timeline from '../ui/components/timeline' ;
const messages = defineMessages ( {
title : { id : 'column.public' , defaultMessage : 'Fediverse timeline' } ,
dismiss : { id : 'fediverse_tab.explanation_box.dismiss' , defaultMessage : 'Don\'t show again' } ,
} ) ;
const CommunityTimeline = ( ) = > {
const intl = useIntl ( ) ;
const dispatch = useAppDispatch ( ) ;
const settings = useSettings ( ) ;
const onlyMedia = settings . getIn ( [ 'public' , 'other' , 'onlyMedia' ] ) ;
const timelineId = 'public' ;
const siteTitle = useAppSelector ( ( state ) = > state . instance . title ) ;
const explanationBoxExpanded = settings . get ( 'explanationBox' ) ;
const showExplanationBox = settings . get ( 'showExplanationBox' ) ;
const explanationBoxMenu = ( ) = > {
return [ { text : intl.formatMessage ( messages . dismiss ) , action : dismissExplanationBox } ] ;
} ;
const dismissExplanationBox = ( ) = > {
dispatch ( changeSetting ( [ 'showExplanationBox' ] , false ) ) ;
} ;
const toggleExplanationBox = ( setting : boolean ) = > {
dispatch ( changeSetting ( [ 'explanationBox' ] , setting ) ) ;
} ;
const handleLoadMore = ( maxId : string ) = > {
dispatch ( expandPublicTimeline ( { maxId , onlyMedia } ) ) ;
} ;
const handleRefresh = ( ) = > {
return dispatch ( expandPublicTimeline ( { onlyMedia } as any ) ) ;
} ;
useEffect ( ( ) = > {
dispatch ( expandPublicTimeline ( { onlyMedia } as any ) ) ;
const disconnect = dispatch ( connectPublicStream ( { onlyMedia } ) ) ;
return ( ) = > {
disconnect ( ) ;
} ;
} , [ onlyMedia ] ) ;
return (
2022-07-15 15:03:21 -07:00
< Column label = { intl . formatMessage ( messages . title ) } transparent withHeader = { false } >
2022-11-03 17:56:03 -07:00
< div className = 'px-4 sm:p-0' >
< SubNavigation message = { intl . formatMessage ( messages . title ) } / >
< / div >
2022-06-09 11:56:14 -07:00
< PinnedHostsPicker / >
2022-11-03 17:56:03 -07:00
2022-06-09 11:56:14 -07:00
{ showExplanationBox && < div className = 'mb-4' >
< Accordion
headline = { < FormattedMessage id = 'fediverse_tab.explanation_box.title' defaultMessage = 'What is the Fediverse?' / > }
menu = { explanationBoxMenu ( ) }
expanded = { explanationBoxExpanded }
onToggle = { toggleExplanationBox }
>
< FormattedMessage
id = 'fediverse_tab.explanation_box.explanation'
defaultMessage = '{site_title} is part of the Fediverse, a social network made up of thousands of independent social media sites (aka "servers"). The posts you see here are from 3rd-party servers. You have the freedom to engage with them, or to block any server you don't like. Pay attention to the full username after the second @ symbol to know which server a post is from. To see only {site_title} posts, visit {local}.'
values = { {
site_title : siteTitle ,
local : (
< Link to = '/timeline/local' >
< FormattedMessage
id = 'empty_column.home.local_tab'
defaultMessage = 'the {site_title} tab'
values = { { site_title : siteTitle } }
/ >
< / Link >
) ,
} }
/ >
< / Accordion >
< / div > }
2022-07-13 18:13:37 -07:00
< PullToRefresh onRefresh = { handleRefresh } >
< Timeline
scrollKey = { ` ${ timelineId } _timeline ` }
timelineId = { ` ${ timelineId } ${ onlyMedia ? ':media' : '' } ` }
onLoadMore = { handleLoadMore }
emptyMessage = { < FormattedMessage id = 'empty_column.public' defaultMessage = 'There is nothing here! Write something publicly, or manually follow users from other servers to fill it up' / > }
divideType = 'space'
/ >
< / PullToRefresh >
2022-06-09 11:56:14 -07:00
< / Column >
) ;
} ;
export default CommunityTimeline ;