2020-08-07 05:19:18 +01:00
|
|
|
import { Fragment } from 'react'
|
2020-08-06 06:07:46 +01:00
|
|
|
import { injectIntl, defineMessages } from 'react-intl'
|
|
|
|
import { me } from '../initial_state'
|
2020-08-07 05:19:18 +01:00
|
|
|
import { GROUP_TIMELINE_SORTING_TYPE_TOP } from '../constants'
|
2020-08-06 06:07:46 +01:00
|
|
|
import { connectGroupCollectionStream } from '../actions/streaming'
|
|
|
|
import { expandGroupCollectionTimeline } from '../actions/timelines'
|
|
|
|
import StatusList from '../components/status_list'
|
2020-08-07 05:19:18 +01:00
|
|
|
import GroupSortBlock from '../components/group_sort_block'
|
2020-08-06 06:07:46 +01:00
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
empty: { id: 'empty_column.group_collection_timeline', defaultMessage: 'There are no gabs to display.' },
|
|
|
|
})
|
|
|
|
|
2020-08-07 05:19:18 +01:00
|
|
|
const mapStateToProps = (state) => ({
|
2020-08-06 06:07:46 +01:00
|
|
|
sortByValue: state.getIn(['group_lists', 'sortByValue']),
|
|
|
|
sortByTopValue: state.getIn(['group_lists', 'sortByTopValue']),
|
|
|
|
})
|
|
|
|
|
|
|
|
export default
|
|
|
|
@injectIntl
|
|
|
|
@connect(mapStateToProps)
|
|
|
|
class GroupCollectionTimeline extends PureComponent {
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
params: PropTypes.object.isRequired,
|
|
|
|
dispatch: PropTypes.func.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
sortByValue: PropTypes.string.isRequired,
|
|
|
|
sortByTopValue: PropTypes.string,
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
2020-08-07 05:19:18 +01:00
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
dispatch,
|
|
|
|
sortByValue,
|
|
|
|
sortByTopValue,
|
|
|
|
} = this.props
|
2020-08-06 06:07:46 +01:00
|
|
|
|
2020-08-07 05:19:18 +01:00
|
|
|
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
|
|
|
|
const options = { sortBy }
|
|
|
|
|
|
|
|
dispatch(expandGroupCollectionTimeline(collectionType, options))
|
2020-08-06 06:07:46 +01:00
|
|
|
|
|
|
|
if (!!me) {
|
|
|
|
this.disconnect = dispatch(connectGroupCollectionStream(collectionType))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-07 05:19:18 +01:00
|
|
|
componentDidUpdate(prevProps) {
|
|
|
|
if (prevProps.sortByValue !== this.props.sortByValue || prevProps.sortByTopValue !== this.props.sortByTopValue) {
|
|
|
|
this.handleLoadMore()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-08-06 06:07:46 +01:00
|
|
|
componentWillUnmount() {
|
|
|
|
if (this.disconnect && !!me) {
|
|
|
|
this.disconnect()
|
|
|
|
this.disconnect = null
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
handleLoadMore = (maxId) => {
|
2020-08-07 05:19:18 +01:00
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
sortByValue,
|
|
|
|
sortByTopValue,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
|
|
|
|
const options = { sortBy, maxId }
|
|
|
|
|
|
|
|
this.props.dispatch(expandGroupCollectionTimeline(collectionType, options))
|
2020-08-06 06:07:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {
|
|
|
|
collectionType,
|
|
|
|
intl,
|
|
|
|
} = this.props
|
|
|
|
|
|
|
|
return (
|
2020-08-07 05:19:18 +01:00
|
|
|
<Fragment>
|
|
|
|
<GroupSortBlock collectionType={collectionType} />
|
|
|
|
<StatusList
|
|
|
|
scrollKey={`group-collection-timeline-${collectionType}`}
|
|
|
|
timelineId={`group:collection:${collectionType}`}
|
|
|
|
onLoadMore={this.handleLoadMore}
|
|
|
|
emptyMessage={intl.formatMessage(messages.empty)}
|
|
|
|
/>
|
|
|
|
</Fragment>
|
2020-08-06 06:07:46 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|