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

75 lines
2.1 KiB
JavaScript
Raw Normal View History

2020-03-27 13:59:38 -07:00
import React from 'react';
import { connect } from 'react-redux';
import ImmutablePureComponent from 'react-immutable-pure-component';
import PropTypes from 'prop-types';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { debounce } from 'lodash';
import LoadingIndicator from '../../../components/loading_indicator';
import {
2020-04-14 11:44:40 -07:00
fetchMembers,
expandMembers,
2020-03-27 13:59:38 -07:00
} from '../../../actions/groups';
import { FormattedMessage } from 'react-intl';
import AccountContainer from '../../../containers/account_container';
import Column from '../../ui/components/column';
import ScrollableList from '../../../components/scrollable_list';
const mapStateToProps = (state, { params: { id } }) => ({
2020-04-14 11:44:40 -07:00
group: state.getIn(['groups', id]),
accountIds: state.getIn(['user_lists', 'groups', id, 'items']),
hasMore: !!state.getIn(['user_lists', 'groups', id, 'next']),
2020-03-27 13:59:38 -07:00
});
export default @connect(mapStateToProps)
class GroupMembers extends ImmutablePureComponent {
2020-04-14 13:45:38 -07:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
accountIds: ImmutablePropTypes.list,
hasMore: PropTypes.bool,
};
2020-03-27 13:59:38 -07:00
componentDidMount() {
2020-04-14 13:45:38 -07:00
const { params: { id } } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
this.props.dispatch(fetchMembers(id));
}
2020-03-27 13:59:38 -07:00
componentDidUpdate(prevProps) {
if (this.props.params.id !== prevProps.params.id) {
this.props.dispatch(fetchMembers(this.props.params.id));
2020-04-14 13:45:38 -07:00
}
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
handleLoadMore = debounce(() => {
this.props.dispatch(expandMembers(this.props.params.id));
}, 300, { leading: true });
2020-03-27 13:59:38 -07:00
render() {
2020-04-14 13:45:38 -07:00
const { accountIds, hasMore, group } = this.props;
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
if (!group || !accountIds) {
return (
<Column>
<LoadingIndicator />
</Column>
);
}
2020-03-27 13:59:38 -07:00
2020-04-14 13:45:38 -07:00
return (
<Column>
<ScrollableList
scrollKey='members'
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='group.members.empty' defaultMessage='This group does not has any members.' />}
>
{accountIds.map(id => <AccountContainer key={id} id={id} withNote={false} />)}
</ScrollableList>
</Column>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}