gab-social/app/javascript/gabsocial/features/home_timeline.js

75 lines
1.8 KiB
JavaScript
Raw Normal View History

2020-02-19 23:57:07 +00:00
import { defineMessages, injectIntl } from 'react-intl'
2020-03-25 03:08:43 +00:00
import { expandHomeTimeline } from '../actions/timelines'
2020-04-11 23:29:19 +01:00
import StatusList from '../components/status_list'
2019-07-02 08:10:25 +01:00
const messages = defineMessages({
title: { id: 'column.home', defaultMessage: 'Home' },
empty: { id: 'empty_timeline.home', defaultMessage: 'Your home timeline is empty. Start following other users to receive their content here.' },
2020-02-19 23:57:07 +00:00
})
2019-07-02 08:10:25 +01:00
2020-04-11 23:29:19 +01:00
const mapStateToProps = (state) => ({
2019-07-02 08:10:25 +01:00
isPartial: state.getIn(['timelines', 'home', 'isPartial']),
2020-02-19 23:57:07 +00:00
})
2019-07-02 08:10:25 +01:00
2020-02-24 21:56:07 +00:00
export default
@connect(mapStateToProps)
2019-07-02 08:10:25 +01:00
@injectIntl
class HomeTimeline extends PureComponent {
2019-07-02 08:10:25 +01:00
static propTypes = {
dispatch: PropTypes.func.isRequired,
intl: PropTypes.object.isRequired,
isPartial: PropTypes.bool,
2020-02-19 23:57:07 +00:00
}
2019-07-02 08:10:25 +01:00
2020-05-07 05:03:34 +01:00
handleLoadMore = (maxId) => {
2020-02-19 23:57:07 +00:00
this.props.dispatch(expandHomeTimeline({ maxId }))
2019-07-02 08:10:25 +01:00
}
componentDidMount () {
2020-02-19 23:57:07 +00:00
this._checkIfReloadNeeded(false, this.props.isPartial)
2019-07-02 08:10:25 +01:00
}
componentDidUpdate (prevProps) {
2020-02-19 23:57:07 +00:00
this._checkIfReloadNeeded(prevProps.isPartial, this.props.isPartial)
2019-07-02 08:10:25 +01:00
}
componentWillUnmount () {
2020-02-19 23:57:07 +00:00
this._stopPolling()
2019-07-02 08:10:25 +01:00
}
_checkIfReloadNeeded (wasPartial, isPartial) {
2020-02-19 23:57:07 +00:00
const { dispatch } = this.props
2019-07-02 08:10:25 +01:00
2020-02-19 23:57:07 +00:00
if (!wasPartial && isPartial) {
2019-07-02 08:10:25 +01:00
this.polling = setInterval(() => {
2020-02-19 23:57:07 +00:00
dispatch(expandHomeTimeline())
}, 3000)
2019-07-02 08:10:25 +01:00
} else if (wasPartial && !isPartial) {
2020-02-19 23:57:07 +00:00
this._stopPolling()
2019-07-02 08:10:25 +01:00
}
}
_stopPolling () {
if (this.polling) {
2020-02-19 23:57:07 +00:00
clearInterval(this.polling)
this.polling = null
2019-07-02 08:10:25 +01:00
}
}
render () {
2020-02-19 23:57:07 +00:00
const { intl } = this.props
const emptyMessage = intl.formatMessage(messages.empty)
2019-07-02 08:10:25 +01:00
return (
2020-04-11 23:29:19 +01:00
<StatusList
2020-02-19 23:57:07 +00:00
scrollKey='home_timeline'
onLoadMore={this.handleLoadMore}
timelineId='home'
emptyMessage={emptyMessage}
/>
)
2019-07-02 08:10:25 +01:00
}
2020-03-25 03:08:43 +00:00
}