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

94 lines
2.8 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
fetchRemovedAccounts,
expandRemovedAccounts,
removeRemovedAccount,
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';
import { defineMessages, injectIntl } from 'react-intl';
const messages = defineMessages({
2020-04-14 11:44:40 -07:00
remove: { id: 'groups.removed_accounts', defaultMessage: 'Allow joining' },
2020-03-27 13:59:38 -07:00
});
const mapStateToProps = (state, { params: { id } }) => ({
2020-04-14 11:44:40 -07:00
group: state.getIn(['groups', id]),
accountIds: state.getIn(['user_lists', 'groups_removed_accounts', id, 'items']),
hasMore: !!state.getIn(['user_lists', 'groups_removed_accounts', id, 'next']),
2020-03-27 13:59:38 -07:00
});
export default @connect(mapStateToProps)
@injectIntl
class GroupRemovedAccounts extends ImmutablePureComponent {
2020-04-14 13:45:38 -07:00
static propTypes = {
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
accountIds: ImmutablePropTypes.orderedSet,
2020-04-14 13:45:38 -07:00
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(fetchRemovedAccounts(id));
}
2020-03-27 13:59:38 -07:00
componentDidUpdate(prevProps) {
if (this.props.params.id !== prevProps.params.id) {
this.props.dispatch(fetchRemovedAccounts(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(expandRemovedAccounts(this.props.params.id));
}, 300, { leading: true });
2020-03-27 13:59:38 -07:00
2020-04-14 14:37:17 -07:00
handleOnActionClick = (group, id) => {
return () => {
this.props.dispatch(removeRemovedAccount(group.get('id'), id));
};
}
render() {
2020-04-14 13:45:38 -07:00
const { accountIds, hasMore, group, intl } = 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='removed_accounts'
hasMore={hasMore}
onLoadMore={this.handleLoadMore}
emptyMessage={<FormattedMessage id='group.removed_accounts.empty' defaultMessage='This group does not has any removed accounts.' />}
>
{accountIds.map(id => (<AccountContainer
key={id}
id={id}
2021-09-27 21:47:43 -07:00
actionIcon={require('@tabler/icons/icons/x.svg')}
2020-04-14 14:37:17 -07:00
onActionClick={this.handleOnActionClick(group, id)}
2020-04-14 13:45:38 -07:00
actionTitle={intl.formatMessage(messages.remove)}
/>))}
</ScrollableList>
</Column>
);
}
2020-04-14 11:44:40 -07:00
2020-03-27 13:59:38 -07:00
}