2019-08-07 06:02:36 +01:00
import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
2019-07-02 08:10:25 +01:00
import { expandHomeTimeline } from '../../actions/timelines' ;
2019-08-07 06:02:36 +01:00
import StatusListContainer from '../../containers/status_list_container' ;
import ColumnSettings from './components/column_settings' ;
2020-01-29 21:53:33 +00:00
import Column from '../../components/column' ;
import { HomeColumnHeader } from '../../components/column_header' ;
2019-07-02 08:10:25 +01:00
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' ] ) ,
} ) ;
export default @ connect ( mapStateToProps )
@ injectIntl
2019-07-29 20:20:00 +01:00
class HomeTimeline extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
dispatch : PropTypes . func . isRequired ,
intl : PropTypes . object . isRequired ,
hasUnread : PropTypes . bool ,
isPartial : PropTypes . bool ,
} ;
handleLoadMore = maxId => {
this . props . dispatch ( expandHomeTimeline ( { maxId } ) ) ;
}
componentDidMount ( ) {
this . _checkIfReloadNeeded ( false , this . props . isPartial ) ;
}
componentDidUpdate ( prevProps ) {
this . _checkIfReloadNeeded ( prevProps . isPartial , this . props . isPartial ) ;
}
componentWillUnmount ( ) {
this . _stopPolling ( ) ;
}
_checkIfReloadNeeded ( wasPartial , isPartial ) {
const { dispatch } = this . props ;
if ( wasPartial === isPartial ) {
return ;
} else if ( ! wasPartial && isPartial ) {
this . polling = setInterval ( ( ) => {
dispatch ( expandHomeTimeline ( ) ) ;
} , 3000 ) ;
} else if ( wasPartial && ! isPartial ) {
this . _stopPolling ( ) ;
}
}
_stopPolling ( ) {
if ( this . polling ) {
clearInterval ( this . polling ) ;
this . polling = null ;
}
}
render ( ) {
2019-07-10 19:20:31 +01:00
const { intl , hasUnread } = this . props ;
2019-07-02 08:10:25 +01:00
return (
2019-08-07 06:02:36 +01:00
< Column heading = { intl . formatMessage ( messages . title ) } >
2020-01-29 21:53:33 +00:00
< HomeColumnHeader activeItem = 'home' active = { hasUnread } >
2019-08-07 06:02:36 +01:00
< ColumnSettings / >
2020-01-29 21:53:33 +00:00
< / H o m e C o l u m n H e a d e r >
2019-07-02 08:10:25 +01:00
< StatusListContainer
2019-07-10 19:20:31 +01:00
scrollKey = 'home_timeline'
2019-07-02 08:10:25 +01:00
onLoadMore = { this . handleLoadMore }
timelineId = 'home'
emptyMessage = { < FormattedMessage id = 'empty_column.home' defaultMessage = 'Your home timeline is empty. Start following other users to recieve their content here.' / > }
/ >
< / C o l u m n >
) ;
}
}