Updated group sorting in frontend
• Updated: - group sorting in frontend
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import { Fragment } from 'react'
|
||||
import ImmutablePureComponent from 'react-immutable-pure-component'
|
||||
import ImmutablePropTypes from 'react-immutable-proptypes'
|
||||
import { injectIntl, defineMessages } from 'react-intl'
|
||||
import { me } from '../initial_state'
|
||||
import { GROUP_TIMELINE_SORTING_TYPE_TOP } from '../constants'
|
||||
import { connectGroupStream } from '../actions/streaming'
|
||||
import { expandGroupTimeline } from '../actions/timelines'
|
||||
import StatusList from '../components/status_list'
|
||||
import ColumnIndicator from '../components/column_indicator'
|
||||
import GroupSortBlock from '../components/group_sort_block'
|
||||
|
||||
const messages = defineMessages({
|
||||
empty: { id: 'empty_column.group', defaultMessage: 'There is nothing in this group yet.\nWhen members of this group post new statuses, they will appear here.' },
|
||||
@@ -13,6 +16,8 @@ const messages = defineMessages({
|
||||
|
||||
const mapStateToProps = (state, props) => ({
|
||||
group: state.getIn(['groups', props.params.id]),
|
||||
sortByValue: state.getIn(['group_lists', 'sortByValue']),
|
||||
sortByTopValue: state.getIn(['group_lists', 'sortByTopValue']),
|
||||
})
|
||||
|
||||
export default
|
||||
@@ -28,19 +33,34 @@ class GroupTimeline extends ImmutablePureComponent {
|
||||
PropTypes.bool,
|
||||
]),
|
||||
intl: PropTypes.object.isRequired,
|
||||
sortByValue: PropTypes.string.isRequired,
|
||||
sortByTopValue: PropTypes.string,
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const { dispatch } = this.props
|
||||
const {
|
||||
dispatch,
|
||||
sortByValue,
|
||||
sortByTopValue,
|
||||
} = this.props
|
||||
const { id } = this.props.params
|
||||
|
||||
dispatch(expandGroupTimeline(id))
|
||||
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
|
||||
const options = { sortBy }
|
||||
|
||||
dispatch(expandGroupTimeline(id, options))
|
||||
|
||||
if (!!me) {
|
||||
this.disconnect = dispatch(connectGroupStream(id))
|
||||
}
|
||||
}
|
||||
|
||||
componentDidUpdate(prevProps) {
|
||||
if (prevProps.sortByValue !== this.props.sortByValue || prevProps.sortByTopValue !== this.props.sortByTopValue) {
|
||||
this.handleLoadMore()
|
||||
}
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
if (this.disconnect && !!me) {
|
||||
this.disconnect()
|
||||
@@ -48,9 +68,18 @@ class GroupTimeline extends ImmutablePureComponent {
|
||||
}
|
||||
}
|
||||
|
||||
handleLoadMore = maxId => {
|
||||
handleLoadMore = (maxId) => {
|
||||
const {
|
||||
dispatch,
|
||||
sortByValue,
|
||||
sortByTopValue,
|
||||
} = this.props
|
||||
const { id } = this.props.params
|
||||
this.props.dispatch(expandGroupTimeline(id, { maxId }))
|
||||
|
||||
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
|
||||
const options = { sortBy, maxId }
|
||||
|
||||
dispatch(expandGroupTimeline(id, options))
|
||||
}
|
||||
|
||||
render() {
|
||||
@@ -64,12 +93,15 @@ class GroupTimeline extends ImmutablePureComponent {
|
||||
}
|
||||
|
||||
return (
|
||||
<StatusList
|
||||
scrollKey={`group-timeline-${id}`}
|
||||
timelineId={`group:${id}`}
|
||||
onLoadMore={this.handleLoadMore}
|
||||
emptyMessage={intl.formatMessage(messages.empty)}
|
||||
/>
|
||||
<Fragment>
|
||||
<GroupSortBlock groupId={id} />
|
||||
<StatusList
|
||||
scrollKey={`group-timeline-${id}`}
|
||||
timelineId={`group:${id}`}
|
||||
onLoadMore={this.handleLoadMore}
|
||||
emptyMessage={intl.formatMessage(messages.empty)}
|
||||
/>
|
||||
</Fragment>
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user