gab-social/app/javascript/gabsocial/features/group_timeline.js

103 lines
2.8 KiB
JavaScript
Raw Normal View History

2020-02-29 15:42:47 +00:00
import ImmutablePureComponent from 'react-immutable-pure-component'
import ImmutablePropTypes from 'react-immutable-proptypes'
import { injectIntl, defineMessages } from 'react-intl'
import { Link } from 'react-router-dom'
import classNames from 'classnames'
import { me } from '../initial_state'
2020-03-04 22:26:01 +00:00
import { connectGroupStream } from '../actions/streaming'
import { expandGroupTimeline } from '../actions/timelines'
2020-04-11 23:29:19 +01:00
import StatusList from '../components/status_list'
2020-03-04 22:26:01 +00:00
import ColumnIndicator from '../components/column_indicator'
2020-02-21 00:57:29 +00:00
const messages = defineMessages({
2020-02-29 15:42:47 +00:00
tabLatest: { id: 'group.timeline.tab_latest', defaultMessage: 'Latest' },
show: { id: 'group.timeline.show_settings', defaultMessage: 'Show settings' },
hide: { id: 'group.timeline.hide_settings', defaultMessage: 'Hide settings' },
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]),
relationships: state.getIn(['group_relationships', props.params.id]),
hasUnread: state.getIn(['timelines', `group:${props.params.id}`, 'unread']) > 0,
})
2020-02-21 00:57:29 +00:00
2020-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
2020-02-21 00:57:29 +00:00
@injectIntl
2020-02-29 15:42:47 +00:00
class GroupTimeline extends ImmutablePureComponent {
static contextTypes = {
router: PropTypes.object,
}
2020-02-21 00:57:29 +00:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
2020-02-29 15:42:47 +00:00
columnId: PropTypes.string,
hasUnread: PropTypes.bool,
2020-04-23 07:13:29 +01:00
group: PropTypes.oneOfType([
ImmutablePropTypes.map,
PropTypes.bool,
]),
2020-02-29 15:42:47 +00:00
relationships: ImmutablePropTypes.map,
2020-02-21 00:57:29 +00:00
intl: PropTypes.object.isRequired,
}
2020-02-29 15:42:47 +00:00
state = {
collapsed: true,
2020-02-21 00:57:29 +00:00
}
2020-02-29 15:42:47 +00:00
componentDidMount() {
const { dispatch } = this.props
const { id } = this.props.params
dispatch(expandGroupTimeline(id))
if (!!me) {
this.disconnect = dispatch(connectGroupStream(id))
}
2020-02-21 00:57:29 +00:00
}
2020-02-29 15:42:47 +00:00
componentWillUnmount() {
if (this.disconnect && !!me) {
2020-02-29 15:42:47 +00:00
this.disconnect()
this.disconnect = null
}
}
2020-02-21 00:57:29 +00:00
2020-02-29 15:42:47 +00:00
handleLoadMore = maxId => {
const { id } = this.props.params
this.props.dispatch(expandGroupTimeline(id, { maxId }))
}
2020-02-21 00:57:29 +00:00
2020-02-29 15:42:47 +00:00
handleToggleClick = (e) => {
e.stopPropagation()
this.setState({ collapsed: !this.state.collapsed })
2020-02-21 00:57:29 +00:00
}
2020-02-29 15:42:47 +00:00
render() {
const { columnId, group, relationships, account, intl } = this.props
const { collapsed } = this.state
const { id } = this.props.params
if (typeof group === 'undefined') {
2020-02-29 15:42:47 +00:00
return <ColumnIndicator type='loading' />
} else if (group === false) {
return <ColumnIndicator type='missing' />
}
2020-02-21 00:57:29 +00:00
return (
2020-04-28 06:33:58 +01:00
<StatusList
2020-02-29 15:42:47 +00:00
alwaysPrepend
scrollKey={`group_timeline-${columnId}`}
timelineId={`group:${id}`}
onLoadMore={this.handleLoadMore}
group={group}
emptyMessage={intl.formatMessage(messages.empty)}
/>
)
2020-02-21 00:57:29 +00:00
}
2020-02-29 15:42:47 +00:00
}