87 lines
2.7 KiB
JavaScript
Raw Normal View History

2019-07-02 03:10:25 -04:00
import ImmutablePropTypes from 'react-immutable-proptypes';
2019-08-13 11:54:29 -04:00
import ImmutablePureComponent from 'react-immutable-pure-component';
import StatusListContainer from '../../../containers/status_list_container';
2019-07-02 03:10:25 -04:00
import { FormattedMessage, injectIntl } from 'react-intl';
import { connectGroupStream } from '../../../actions/streaming';
import { expandGroupTimeline } from '../../../actions/timelines';
import ColumnIndicator from '../../../components/column_indicator';
2019-08-13 11:54:29 -04:00
import TimelineComposeBlock from '../../../components/timeline_compose_block';
2019-07-02 03:10:25 -04:00
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,
2019-07-02 03:10:25 -04:00
});
export default @connect(mapStateToProps)
@injectIntl
2019-08-13 11:54:29 -04:00
class GroupTimeline extends ImmutablePureComponent {
2019-07-15 16:47:05 +03:00
static contextTypes = {
router: PropTypes.object,
2019-07-15 16:47:05 +03:00
};
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
columnId: PropTypes.string,
hasUnread: PropTypes.bool,
group: PropTypes.oneOfType([ImmutablePropTypes.map, PropTypes.bool]),
relationships: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
2019-07-15 16:47:05 +03:00
};
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
componentDidMount () {
const { dispatch } = this.props;
const { id } = this.props.params;
2019-07-02 03:10:25 -04:00
dispatch(expandGroupTimeline(id));
2019-07-02 03:10:25 -04:00
this.disconnect = dispatch(connectGroupStream(id));
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
componentWillUnmount () {
if (this.disconnect) {
this.disconnect();
this.disconnect = null;
}
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
handleLoadMore = maxId => {
const { id } = this.props.params;
this.props.dispatch(expandGroupTimeline(id, { maxId }));
2019-07-15 16:47:05 +03:00
}
2019-07-02 03:10:25 -04:00
2019-07-15 16:47:05 +03:00
render () {
2019-08-13 11:54:29 -04:00
const { columnId, group, relationships } = this.props;
const { id } = this.props.params;
2019-07-02 03:10:25 -04:00
if (typeof group === 'undefined' || !relationships) {
return (<ColumnIndicator type='loading' />);
} else if (group === false) {
return (<ColumnIndicator type='missing' />);
}
2019-07-02 03:10:25 -04:00
return (
2019-08-13 11:54:29 -04:00
<div>
{
relationships.get('member') &&
<TimelineComposeBlock size={46} group={group} shouldCondense={true} autoFocus={false} />
}
2019-07-02 03:10:25 -04:00
2019-08-13 11:54:29 -04:00
<div className='group__feed'>
<StatusListContainer
scrollKey={`group_timeline-${columnId}`}
timelineId={`group:${id}`}
onLoadMore={this.handleLoadMore}
group={group}
withGroupAdmin={relationships && relationships.get('admin')}
emptyMessage={<FormattedMessage id='empty_column.group' defaultMessage='There is nothing in this group yet. When members of this group post new statuses, they will appear here.' />}
2019-08-13 11:54:29 -04:00
/>
</div>
</div>
);
2019-07-15 16:47:05 +03:00
}
2019-07-15 19:08:36 +03:00
}