Updated group sorting in frontend
• Updated: - group sorting in frontend
This commit is contained in:
@@ -1,14 +1,17 @@
|
||||
import { Fragment } from 'react'
|
||||
import { injectIntl, defineMessages } from 'react-intl'
|
||||
import { me } from '../initial_state'
|
||||
import { GROUP_TIMELINE_SORTING_TYPE_TOP } from '../constants'
|
||||
import { connectGroupCollectionStream } from '../actions/streaming'
|
||||
import { expandGroupCollectionTimeline } from '../actions/timelines'
|
||||
import StatusList from '../components/status_list'
|
||||
import GroupSortBlock from '../components/group_sort_block'
|
||||
|
||||
const messages = defineMessages({
|
||||
empty: { id: 'empty_column.group_collection_timeline', defaultMessage: 'There are no gabs to display.' },
|
||||
})
|
||||
|
||||
const mapStateToProps = (state) = ({
|
||||
const mapStateToProps = (state) => ({
|
||||
sortByValue: state.getIn(['group_lists', 'sortByValue']),
|
||||
sortByTopValue: state.getIn(['group_lists', 'sortByTopValue']),
|
||||
})
|
||||
@@ -27,15 +30,29 @@ class GroupCollectionTimeline extends PureComponent {
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { collectionType, dispatch } = this.props
|
||||
const {
|
||||
collectionType,
|
||||
dispatch,
|
||||
sortByValue,
|
||||
sortByTopValue,
|
||||
} = this.props
|
||||
|
||||
dispatch(expandGroupCollectionTimeline(collectionType))
|
||||
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
|
||||
const options = { sortBy }
|
||||
|
||||
dispatch(expandGroupCollectionTimeline(collectionType, options))
|
||||
|
||||
if (!!me) {
|
||||
this.disconnect = dispatch(connectGroupCollectionStream(collectionType))
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (prevProps.sortByValue !== this.props.sortByValue || prevProps.sortByTopValue !== this.props.sortByTopValue) {
|
||||
this.handleLoadMore()
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.disconnect && !!me) {
|
||||
this.disconnect()
|
||||
@@ -44,8 +61,16 @@ class GroupCollectionTimeline extends PureComponent {
|
||||
}
|
||||
|
||||
handleLoadMore = (maxId) => {
|
||||
const { collectionType } = this.props
|
||||
this.props.dispatch(expandGroupCollectionTimeline(collectionType, { maxId }))
|
||||
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))
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -55,12 +80,15 @@ class GroupCollectionTimeline extends PureComponent {
|
||||
} = this.props
|
||||
|
||||
return (
|
||||
<StatusList
|
||||
scrollKey={`group-collection-timeline-${collectionType}`}
|
||||
timelineId={`group:collection:${collectionType}`}
|
||||
onLoadMore={this.handleLoadMore}
|
||||
emptyMessage={intl.formatMessage(messages.empty)}
|
||||
/>
|
||||
<Fragment>
|
||||
<GroupSortBlock collectionType={collectionType} />
|
||||
<StatusList
|
||||
scrollKey={`group-collection-timeline-${collectionType}`}
|
||||
timelineId={`group:collection:${collectionType}`}
|
||||
onLoadMore={this.handleLoadMore}
|
||||
emptyMessage={intl.formatMessage(messages.empty)}
|
||||
/>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user