Fix admin account filtering

Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1769
This commit is contained in:
Alex Gleason 2024-10-30 23:56:30 -05:00
parent 32f92b7559
commit bfb8351fc3
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
3 changed files with 29 additions and 19 deletions

View File

@ -3,29 +3,25 @@ import { useEntities } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks';
import { adminAccountSchema } from 'soapbox/schemas/admin-account';
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,
]);
interface MastodonAdminFilters {
local?: boolean;
remote?: boolean;
active?: boolean;
pending?: boolean;
disabled?: boolean;
silenced?: boolean;
suspended?: boolean;
sensitized?: boolean;
}
/** https://docs.joinmastodon.org/methods/admin/accounts/#v1 */
export function useAdminAccounts(filters: typeof allFilters, limit?: number) {
export function useAdminAccounts(filters: MastodonAdminFilters, limit?: number) {
const api = useApi();
const searchParams = new URLSearchParams();
for (const filter of allFilters) {
if (filters.has(filter)) {
searchParams.append(filter, 'true');
} else {
searchParams.append(filter, 'false');
}
for (const [name, value] of Object.entries(filters)) {
searchParams.append(name, value.toString());
}
if (typeof limit === 'number') {

View File

@ -18,7 +18,14 @@ const LatestAccountsPanel: React.FC<ILatestAccountsPanel> = ({ limit = 5 }) => {
const intl = useIntl();
const history = useHistory();
const { accounts } = useAdminAccounts(new Set(['local', 'active']), limit);
const { accounts } = useAdminAccounts({
local: true,
active: true,
pending: false,
disabled: false,
silenced: false,
suspended: false,
}, limit);
const handleAction = () => {
history.push('/soapbox/admin/users');

View File

@ -15,7 +15,14 @@ const messages = defineMessages({
const UserIndex: React.FC = () => {
const intl = useIntl();
const { accounts, isLoading, hasNextPage, fetchNextPage } = useAdminAccounts(new Set(['local']));
const { accounts, isLoading, hasNextPage, fetchNextPage } = useAdminAccounts({
local: true,
active: true,
pending: false,
disabled: false,
silenced: false,
suspended: false,
});
const handleLoadMore = () => {
if (!isLoading) {