sforkowany z mirror/soapbox
Admin: refactor fetchUsers() action
rodzic
3043924045
commit
732fba73f5
|
@ -125,17 +125,19 @@ export function closeReports(ids) {
|
||||||
return patchReports(ids, 'closed');
|
return patchReports(ids, 'closed');
|
||||||
}
|
}
|
||||||
|
|
||||||
export function fetchUsers(params) {
|
export function fetchUsers(filters = [], page = 1, pageSize = 50) {
|
||||||
return (dispatch, getState) => {
|
return (dispatch, getState) => {
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, params });
|
const params = { filters: filters.join(), page, page_size: pageSize };
|
||||||
|
|
||||||
|
dispatch({ type: ADMIN_USERS_FETCH_REQUEST, filters, page, pageSize });
|
||||||
return api(getState)
|
return api(getState)
|
||||||
.get('/api/pleroma/admin/users', { params })
|
.get('/api/pleroma/admin/users', { params })
|
||||||
.then(({ data: { users, count, page_size: pageSize } }) => {
|
.then(({ data: { users, count, page_size: pageSize } }) => {
|
||||||
dispatch(fetchRelationships(users.map(user => user.id)));
|
dispatch(fetchRelationships(users.map(user => user.id)));
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, params });
|
dispatch({ type: ADMIN_USERS_FETCH_SUCCESS, users, count, pageSize, filters, page });
|
||||||
return { users, count, pageSize };
|
return { users, count, pageSize };
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, params });
|
dispatch({ type: ADMIN_USERS_FETCH_FAIL, error, filters, page, pageSize });
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,7 @@ class AwaitingApproval extends ImmutablePureComponent {
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
const { dispatch } = this.props;
|
const { dispatch } = this.props;
|
||||||
const params = { page: 1, filters: 'local,need_approval' };
|
dispatch(fetchUsers(['local', 'need_approval']))
|
||||||
dispatch(fetchUsers(params))
|
|
||||||
.then(() => this.setState({ isLoading: false }))
|
.then(() => this.setState({ isLoading: false }))
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,9 @@ class UserIndex extends ImmutablePureComponent {
|
||||||
|
|
||||||
fetchNextPage = () => {
|
fetchNextPage = () => {
|
||||||
const nextPage = this.state.page + 1;
|
const nextPage = this.state.page + 1;
|
||||||
const filters = this.state.filters.toJS().join();
|
const filters = this.state.filters.toJS();
|
||||||
|
|
||||||
this.props.dispatch(fetchUsers({ filters, page: nextPage }))
|
this.props.dispatch(fetchUsers(filters, nextPage))
|
||||||
.then(({ users, count }) => {
|
.then(({ users, count }) => {
|
||||||
const newIds = users.map(user => user.id);
|
const newIds = users.map(user => user.id);
|
||||||
|
|
||||||
|
|
|
@ -430,7 +430,7 @@ class UI extends React.PureComponent {
|
||||||
|
|
||||||
if (isStaff(account)) {
|
if (isStaff(account)) {
|
||||||
this.props.dispatch(fetchReports({ state: 'open' }));
|
this.props.dispatch(fetchReports({ state: 'open' }));
|
||||||
this.props.dispatch(fetchUsers({ page: 1, filters: 'local,need_approval' }));
|
this.props.dispatch(fetchUsers(['local', 'need_approval']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isAdmin(account)) {
|
if (isAdmin(account)) {
|
||||||
|
|
Ładowanie…
Reference in New Issue