2020-03-27 13:59:38 -07:00
import React from 'react' ;
import { connect } from 'react-redux' ;
import { expandHomeTimeline } from '../../actions/timelines' ;
import PropTypes from 'prop-types' ;
import StatusListContainer from '../ui/containers/status_list_container' ;
import Column from '../../components/column' ;
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
import ColumnSettingsContainer from './containers/column_settings_container' ;
import HomeColumnHeader from '../../components/home_column_header' ;
import { Link } from 'react-router-dom' ;
const messages = defineMessages ( {
title : { id : 'column.home' , defaultMessage : 'Home' } ,
} ) ;
const mapStateToProps = state => ( {
hasUnread : state . getIn ( [ 'timelines' , 'home' , 'unread' ] ) > 0 ,
isPartial : state . getIn ( [ 'timelines' , 'home' , 'isPartial' ] ) ,
2020-04-01 13:31:40 -07:00
siteTitle : state . getIn ( [ 'instance' , 'title' ] ) ,
2020-03-27 13:59:38 -07:00
} ) ;
export default @ connect ( mapStateToProps )
@ injectIntl
class HomeTimeline extends React . PureComponent {
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
isPartial : PropTypes . bool ,
2020-04-14 14:37:17 -07:00
siteTitle : PropTypes . string ,
2020-03-27 13:59:38 -07:00
} ;
handleLoadMore = maxId => {
this . props . dispatch ( expandHomeTimeline ( { maxId } ) ) ;
}
2020-04-14 14:47:35 -07:00
componentDidMount ( ) {
2020-03-27 13:59:38 -07:00
this . _checkIfReloadNeeded ( false , this . props . isPartial ) ;
}
2020-04-14 14:47:35 -07:00
componentDidUpdate ( prevProps ) {
2020-03-27 13:59:38 -07:00
this . _checkIfReloadNeeded ( prevProps . isPartial , this . props . isPartial ) ;
}
2020-04-14 14:47:35 -07:00
componentWillUnmount ( ) {
2020-03-27 13:59:38 -07:00
this . _stopPolling ( ) ;
}
2020-04-14 14:47:35 -07:00
_checkIfReloadNeeded ( wasPartial , isPartial ) {
2020-03-27 13:59:38 -07:00
const { dispatch } = this . props ;
if ( wasPartial === isPartial ) {
return ;
} else if ( ! wasPartial && isPartial ) {
this . polling = setInterval ( ( ) => {
dispatch ( expandHomeTimeline ( ) ) ;
} , 3000 ) ;
} else if ( wasPartial && ! isPartial ) {
this . _stopPolling ( ) ;
}
}
2020-04-14 14:47:35 -07:00
_stopPolling ( ) {
2020-03-27 13:59:38 -07:00
if ( this . polling ) {
clearInterval ( this . polling ) ;
this . polling = null ;
}
}
2020-04-14 14:47:35 -07:00
render ( ) {
2020-04-14 11:44:40 -07:00
const { intl , hasUnread , siteTitle } = this . props ;
2020-03-27 13:59:38 -07:00
return (
< Column label = { intl . formatMessage ( messages . title ) } >
< HomeColumnHeader activeItem = 'home' active = { hasUnread } >
< ColumnSettingsContainer / >
< / H o m e C o l u m n H e a d e r >
< StatusListContainer
scrollKey = 'home_timeline'
onLoadMore = { this . handleLoadMore }
timelineId = 'home'
2020-04-14 11:44:40 -07:00
emptyMessage = { < FormattedMessage id = 'empty_column.home' defaultMessage = 'Your home timeline is empty! Visit {public} to get started and meet other users.' values = { { public : < Link to = '/timeline/local' > < FormattedMessage id = 'empty_column.home.local_tab' defaultMessage = 'the {site_title} tab' values = { { site _title : siteTitle } } / > < /Link> }} / > }
2020-03-27 13:59:38 -07:00
/ >
< / C o l u m n >
) ;
}
}