Merge branch 'admin-filters' into 'main'
Fix admin account filters Closes #1769 See merge request soapbox-pub/soapbox!3200
This commit is contained in:
commit
cf1bbf084a
|
@ -3,16 +3,29 @@ import { useEntities } from 'soapbox/entity-store/hooks';
|
|||
import { useApi } from 'soapbox/hooks';
|
||||
import { adminAccountSchema } from 'soapbox/schemas/admin-account';
|
||||
|
||||
type Filter = 'local' | 'remote' | 'active' | 'pending' | 'disabled' | 'silenced' | 'suspended' | 'sensitized';
|
||||
const allFilters = new Set([
|
||||
'local' as const,
|
||||
'remote' as const,
|
||||
'active' as const,
|
||||
'pending' as const,
|
||||
'disabled' as const,
|
||||
'silenced' as const,
|
||||
'suspended' as const,
|
||||
'sensitized' as const,
|
||||
]);
|
||||
|
||||
/** https://docs.joinmastodon.org/methods/admin/accounts/#v1 */
|
||||
export function useAdminAccounts(filters: Filter[] = [], limit?: number) {
|
||||
export function useAdminAccounts(filters: typeof allFilters, limit?: number) {
|
||||
const api = useApi();
|
||||
|
||||
const searchParams = new URLSearchParams();
|
||||
|
||||
for (const filter of filters) {
|
||||
searchParams.append(filter, 'true');
|
||||
for (const filter of allFilters) {
|
||||
if (filters.has(filter)) {
|
||||
searchParams.append(filter, 'true');
|
||||
} else {
|
||||
searchParams.append(filter, 'false');
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof limit === 'number') {
|
||||
|
|
|
@ -18,7 +18,7 @@ const LatestAccountsPanel: React.FC<ILatestAccountsPanel> = ({ limit = 5 }) => {
|
|||
const intl = useIntl();
|
||||
const history = useHistory();
|
||||
|
||||
const { accounts } = useAdminAccounts(['local', 'active'], limit);
|
||||
const { accounts } = useAdminAccounts(new Set(['local', 'active']), limit);
|
||||
|
||||
const handleAction = () => {
|
||||
history.push('/soapbox/admin/users');
|
||||
|
|
|
@ -15,7 +15,7 @@ const messages = defineMessages({
|
|||
const UserIndex: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
|
||||
const { accounts, isLoading, hasNextPage, fetchNextPage } = useAdminAccounts(['local']);
|
||||
const { accounts, isLoading, hasNextPage, fetchNextPage } = useAdminAccounts(new Set(['local']));
|
||||
|
||||
const handleLoadMore = () => {
|
||||
if (!isLoading) {
|
||||
|
|
Loading…
Reference in New Issue