109 lines
2.9 KiB
JavaScript
Raw Normal View History

import { Fragment } from 'react'
2020-02-29 10:42:47 -05:00
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'
2020-03-04 17:26:01 -05:00
import { connectGroupStream } from '../actions/streaming'
import { expandGroupTimeline } from '../actions/timelines'
2020-04-11 18:29:19 -04:00
import StatusList from '../components/status_list'
2020-03-04 17:26:01 -05:00
import ColumnIndicator from '../components/column_indicator'
import GroupSortBlock from '../components/group_sort_block'
2020-02-20 19:57:29 -05:00
const messages = defineMessages({
2020-02-29 10:42:47 -05:00
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.' },
})
const mapStateToProps = (state, props) => ({
group: state.getIn(['groups', props.params.id]),
sortByValue: state.getIn(['group_lists', 'sortByValue']),
sortByTopValue: state.getIn(['group_lists', 'sortByTopValue']),
2020-02-29 10:42:47 -05:00
})
2020-02-20 19:57:29 -05:00
2020-02-25 11:04:44 -05:00
export default
@connect(mapStateToProps)
2020-02-20 19:57:29 -05:00
@injectIntl
2020-02-29 10:42:47 -05:00
class GroupTimeline extends ImmutablePureComponent {
2020-02-20 19:57:29 -05:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
2020-04-23 02:13:29 -04:00
group: PropTypes.oneOfType([
ImmutablePropTypes.map,
PropTypes.bool,
]),
2020-02-20 19:57:29 -05:00
intl: PropTypes.object.isRequired,
sortByValue: PropTypes.string.isRequired,
sortByTopValue: PropTypes.string,
2020-02-20 19:57:29 -05:00
}
2020-02-29 10:42:47 -05:00
componentDidMount() {
const {
dispatch,
sortByValue,
sortByTopValue,
} = this.props
2020-02-29 10:42:47 -05:00
const { id } = this.props.params
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
const options = { sortBy }
dispatch(expandGroupTimeline(id, options))
2020-02-29 10:42:47 -05:00
if (!!me) {
this.disconnect = dispatch(connectGroupStream(id))
}
2020-02-20 19:57:29 -05:00
}
componentDidUpdate(prevProps) {
if (prevProps.sortByValue !== this.props.sortByValue || prevProps.sortByTopValue !== this.props.sortByTopValue) {
this.handleLoadMore()
}
}
2020-02-29 10:42:47 -05:00
componentWillUnmount() {
if (this.disconnect && !!me) {
2020-02-29 10:42:47 -05:00
this.disconnect()
this.disconnect = null
}
}
2020-02-20 19:57:29 -05:00
handleLoadMore = (maxId) => {
const {
dispatch,
sortByValue,
sortByTopValue,
} = this.props
2020-02-29 10:42:47 -05:00
const { id } = this.props.params
const sortBy = sortByValue === GROUP_TIMELINE_SORTING_TYPE_TOP ? `${sortByValue}_${sortByTopValue}` : sortByValue
const options = { sortBy, maxId }
dispatch(expandGroupTimeline(id, options))
2020-02-29 10:42:47 -05:00
}
2020-02-20 19:57:29 -05:00
2020-02-29 10:42:47 -05:00
render() {
const { group, intl } = this.props
2020-02-29 10:42:47 -05:00
const { id } = this.props.params
if (typeof group === 'undefined') {
2020-02-29 10:42:47 -05:00
return <ColumnIndicator type='loading' />
} else if (group === false) {
return <ColumnIndicator type='missing' />
}
2020-02-20 19:57:29 -05:00
return (
<Fragment>
<GroupSortBlock groupId={id} />
<StatusList
scrollKey={`group-timeline-${id}`}
timelineId={`group:${id}`}
onLoadMore={this.handleLoadMore}
emptyMessage={intl.formatMessage(messages.empty)}
/>
</Fragment>
2020-02-29 10:42:47 -05:00
)
2020-02-20 19:57:29 -05:00
}
2020-02-29 10:42:47 -05:00
}