bigbuffet-rw/app/soapbox/features/groups/timeline/index.js

113 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
import { Link } from 'react-router-dom';
2020-03-27 13:59:38 -07:00
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import StatusListContainer from '../../ui/containers/status_list_container';
import Column from '../../../components/column';
import { FormattedMessage, injectIntl } from 'react-intl';
import { connectGroupStream } from '../../../actions/streaming';
import { expandGroupTimeline } from '../../../actions/timelines';
import MissingIndicator from '../../../components/missing_indicator';
import LoadingIndicator from '../../../components/loading_indicator';
2020-05-28 15:52:07 -07:00
import ComposeFormContainer from '../../../../soapbox/features/compose/containers/compose_form_container';
2020-03-27 13:59:38 -07:00
import Avatar from '../../../components/avatar';
const mapStateToProps = (state, props) => {
2020-04-14 11:44:40 -07:00
const me = state.get('me');
return {
account: state.getIn(['accounts', me]),
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-03-27 13:59:38 -07:00
export default @connect(mapStateToProps)
@injectIntl
class GroupTimeline extends React.PureComponent {
2020-04-14 11:44:40 -07:00
2020-04-14 13:45:38 -07:00
static contextTypes = {
router: PropTypes.object,
};
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07: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,
account: ImmutablePropTypes.map,
intl: PropTypes.object.isRequired,
};
2020-03-27 13:59:38 -07:00
componentDidMount() {
2020-04-14 13:45:38 -07:00
const { dispatch } = this.props;
const { id } = this.props.params;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
dispatch(expandGroupTimeline(id));
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
this.disconnect = dispatch(connectGroupStream(id));
}
2020-03-27 13:59:38 -07:00
componentWillUnmount() {
2020-04-14 13:45:38 -07:00
if (this.disconnect) {
this.disconnect();
this.disconnect = null;
}
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
handleLoadMore = maxId => {
const { id } = this.props.params;
this.props.dispatch(expandGroupTimeline(id, { maxId }));
}
2020-03-27 13:59:38 -07:00
render() {
2020-04-14 13:45:38 -07:00
const { columnId, group, relationships, account } = this.props;
const { id } = this.props.params;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
if (typeof group === 'undefined' || !relationships) {
return (
<Column>
<LoadingIndicator />
</Column>
);
} else if (group === false) {
return (
<Column>
<MissingIndicator />
</Column>
);
}
2020-03-27 13:59:38 -07:00
const acct = account ? account.get('acct') : '';
2020-04-14 13:45:38 -07:00
return (
<div>
{relationships.get('member') && (
<div className='timeline-compose-block'>
<Link className='timeline-compose-block__avatar' to={`/@${acct}`}>
2020-04-14 13:45:38 -07:00
<Avatar account={account} size={46} />
</Link>
2020-04-14 13:45:38 -07:00
<ComposeFormContainer group={group} shouldCondense autoFocus={false} />
</div>
)}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
<div className='group__feed'>
<StatusListContainer
alwaysPrepend
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 make new posts, they will appear here.' />}
/>
</div>
</div>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}