2019-08-13 11:54:29 -04:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import {
expandCommunityTimeline ,
expandPublicTimeline ,
} from '../../actions/timelines' ;
import {
connectCommunityStream ,
connectPublicStream ,
} from '../../actions/streaming' ;
2020-01-29 11:45:17 -05:00
import StatusListContainer from '../../containers/status_list_container' ; ;
// import ColumnSettingsContainer from '.containers/column_settings_container';
import Column from '../../components/column' ;
// import { HomeColumnHeader } from '../../components/column_header';
2019-08-13 11:54:29 -04:00
const messages = defineMessages ( {
title : { id : 'column.community' , defaultMessage : 'Community timeline' } ,
} ) ;
const mapStateToProps = state => {
const allFediverse = state . getIn ( [ 'settings' , 'community' , 'other' , 'allFediverse' ] ) ;
const onlyMedia = state . getIn ( [ 'settings' , 'community' , 'other' , 'onlyMedia' ] ) ;
const timelineId = allFediverse ? 'public' : 'community' ;
return {
timelineId ,
allFediverse ,
onlyMedia ,
hasUnread : state . getIn ( [ 'timelines' , ` ${ timelineId } ${ onlyMedia ? ':media' : '' } ` , 'unread' ] ) > 0 ,
} ;
} ;
export default @ connect ( mapStateToProps )
@ injectIntl
2020-01-29 16:54:39 -05:00
class CommunityTimeline extends PureComponent {
2019-08-13 11:54:29 -04:00
static contextTypes = {
router : PropTypes . object ,
} ;
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
onlyMedia : PropTypes . bool ,
allFediverse : PropTypes . bool ,
timelineId : PropTypes . string ,
} ;
componentDidMount ( ) {
const { dispatch , onlyMedia , allFediverse } = this . props ;
if ( allFediverse ) {
dispatch ( expandPublicTimeline ( { onlyMedia } ) ) ;
this . disconnect = dispatch ( connectPublicStream ( { onlyMedia } ) ) ;
}
else {
dispatch ( expandCommunityTimeline ( { onlyMedia } ) ) ;
this . disconnect = dispatch ( connectCommunityStream ( { onlyMedia } ) ) ;
}
}
componentDidUpdate ( prevProps ) {
if ( prevProps . onlyMedia !== this . props . onlyMedia || prevProps . allFediverse !== this . props . allFediverse ) {
const { dispatch , onlyMedia , allFediverse } = this . props ;
this . disconnect ( ) ;
if ( allFediverse ) {
dispatch ( expandPublicTimeline ( { onlyMedia } ) ) ;
this . disconnect = dispatch ( connectPublicStream ( { onlyMedia } ) ) ;
}
else {
dispatch ( expandCommunityTimeline ( { onlyMedia } ) ) ;
this . disconnect = dispatch ( connectCommunityStream ( { onlyMedia } ) ) ;
}
}
}
componentWillUnmount ( ) {
if ( this . disconnect ) {
this . disconnect ( ) ;
this . disconnect = null ;
}
}
handleLoadMore = maxId => {
const { dispatch , onlyMedia , allFediverse } = this . props ;
if ( allFediverse ) {
dispatch ( expandPublicTimeline ( { maxId , onlyMedia } ) ) ;
}
else {
dispatch ( expandCommunityTimeline ( { maxId , onlyMedia } ) ) ;
}
}
render ( ) {
const { intl , hasUnread , onlyMedia , timelineId , allFediverse } = this . props ;
return (
2020-01-28 11:29:37 -05:00
< Column label = { intl . formatMessage ( messages . title ) } >
2020-01-29 11:45:17 -05:00
{ / * < H o m e C o l u m n H e a d e r a c t i v e I t e m = ' a l l ' a c t i v e = { h a s U n r e a d } >
2020-01-28 11:29:37 -05:00
< ColumnSettingsContainer / >
2020-01-29 11:45:17 -05:00
< /HomeColumnHeader> */ }
2019-08-13 11:54:29 -04:00
< StatusListContainer
scrollKey = { ` ${ timelineId } _timeline ` }
timelineId = { ` ${ timelineId } ${ onlyMedia ? ':media' : '' } ` }
onLoadMore = { this . handleLoadMore }
emptyMessage = { < FormattedMessage id = 'empty_column.community' defaultMessage = 'The community timeline is empty. Write something publicly to get the ball rolling!' / > }
/ >
< / C o l u m n >
) ;
}
}