77 lines
1.9 KiB
JavaScript
Raw Normal View History

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'
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'
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]),
})
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,
}
2020-02-29 10:42:47 -05:00
componentDidMount() {
const { dispatch } = this.props
const { id } = this.props.params
dispatch(expandGroupTimeline(id))
if (!!me) {
this.disconnect = dispatch(connectGroupStream(id))
}
2020-02-20 19:57:29 -05:00
}
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
2020-02-29 10:42:47 -05:00
handleLoadMore = maxId => {
const { id } = this.props.params
this.props.dispatch(expandGroupTimeline(id, { maxId }))
}
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 (
2020-04-28 01:33:58 -04:00
<StatusList
scrollKey={`group-timeline-${id}`}
2020-02-29 10:42:47 -05:00
timelineId={`group:${id}`}
onLoadMore={this.handleLoadMore}
emptyMessage={intl.formatMessage(messages.empty)}
/>
)
2020-02-20 19:57:29 -05:00
}
2020-02-29 10:42:47 -05:00
}