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

79 lines
2.3 KiB
JavaScript
Raw Normal View History

import ImmutablePureComponent from 'react-immutable-pure-component';
import ImmutablePropTypes from 'react-immutable-proptypes';
import { debounce } from 'lodash';
2020-03-04 23:08:08 +00:00
import ColumnIndicator from '../components/column_indicator';
import {
2020-02-24 23:25:55 +00:00
fetchRemovedAccounts,
expandRemovedAccounts,
removeRemovedAccount,
2020-03-04 23:08:08 +00:00
} from '../actions/groups';
import { FormattedMessage } from 'react-intl';
2020-03-04 23:08:08 +00:00
import AccountContainer from '../containers/account_container';
import ScrollableList from '../components/scrollable_list';
2019-07-16 21:18:23 +01:00
import { defineMessages, injectIntl } from 'react-intl';
const messages = defineMessages({
2020-02-24 23:25:55 +00:00
remove: { id: 'groups.removed_accounts', defaultMessage: 'Allow joining' },
2019-07-16 21:18:23 +01:00
});
const mapStateToProps = (state, { params: { id } }) => ({
2020-02-24 23:25:55 +00: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-02-25 16:04:44 +00:00
export default
@connect(mapStateToProps)
2019-07-16 21:18:23 +01:00
@injectIntl
class GroupRemovedAccounts extends ImmutablePureComponent {
static propTypes = {
2020-02-24 23:25:55 +00:00
params: PropTypes.object.isRequired,
dispatch: PropTypes.func.isRequired,
accountIds: ImmutablePropTypes.list,
hasMore: PropTypes.bool,
};
2020-02-24 23:25:55 +00:00
componentWillMount() {
const { params: { id } } = this.props;
2020-02-24 23:25:55 +00:00
this.props.dispatch(fetchRemovedAccounts(id));
}
2020-02-24 23:25:55 +00:00
componentWillReceiveProps(nextProps) {
if (nextProps.params.id !== this.props.params.id) {
this.props.dispatch(fetchRemovedAccounts(nextProps.params.id));
}
}
handleLoadMore = debounce(() => {
2020-02-24 23:25:55 +00:00
this.props.dispatch(expandRemovedAccounts(this.props.params.id));
}, 300, { leading: true });
2020-02-24 23:25:55 +00:00
render() {
const { accountIds, hasMore, group, intl } = this.props;
2020-02-24 23:25:55 +00:00
if (!group || !accountIds) {
return <ColumnIndicator type='loading' />
}
2020-02-24 23:25:55 +00:00
return (
<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}
actionIcon='remove'
onActionClick={() => this.props.dispatch(removeRemovedAccount(group.get('id'), id))}
actionTitle={intl.formatMessage(messages.remove)}
/>))}
</ScrollableList>
)
}
}