Fix admin account filtering
Fixes https://gitlab.com/soapbox-pub/soapbox/-/issues/1769
This commit is contained in:
parent
32f92b7559
commit
bfb8351fc3
|
@ -3,29 +3,25 @@ import { useEntities } from 'soapbox/entity-store/hooks';
|
||||||
import { useApi } from 'soapbox/hooks';
|
import { useApi } from 'soapbox/hooks';
|
||||||
import { adminAccountSchema } from 'soapbox/schemas/admin-account';
|
import { adminAccountSchema } from 'soapbox/schemas/admin-account';
|
||||||
|
|
||||||
const allFilters = new Set([
|
interface MastodonAdminFilters {
|
||||||
'local' as const,
|
local?: boolean;
|
||||||
'remote' as const,
|
remote?: boolean;
|
||||||
'active' as const,
|
active?: boolean;
|
||||||
'pending' as const,
|
pending?: boolean;
|
||||||
'disabled' as const,
|
disabled?: boolean;
|
||||||
'silenced' as const,
|
silenced?: boolean;
|
||||||
'suspended' as const,
|
suspended?: boolean;
|
||||||
'sensitized' as const,
|
sensitized?: boolean;
|
||||||
]);
|
}
|
||||||
|
|
||||||
/** https://docs.joinmastodon.org/methods/admin/accounts/#v1 */
|
/** 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 api = useApi();
|
||||||
|
|
||||||
const searchParams = new URLSearchParams();
|
const searchParams = new URLSearchParams();
|
||||||
|
|
||||||
for (const filter of allFilters) {
|
for (const [name, value] of Object.entries(filters)) {
|
||||||
if (filters.has(filter)) {
|
searchParams.append(name, value.toString());
|
||||||
searchParams.append(filter, 'true');
|
|
||||||
} else {
|
|
||||||
searchParams.append(filter, 'false');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof limit === 'number') {
|
if (typeof limit === 'number') {
|
||||||
|
|
|
@ -18,7 +18,14 @@ const LatestAccountsPanel: React.FC<ILatestAccountsPanel> = ({ limit = 5 }) => {
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
const history = useHistory();
|
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 = () => {
|
const handleAction = () => {
|
||||||
history.push('/soapbox/admin/users');
|
history.push('/soapbox/admin/users');
|
||||||
|
|
|
@ -15,7 +15,14 @@ const messages = defineMessages({
|
||||||
const UserIndex: React.FC = () => {
|
const UserIndex: React.FC = () => {
|
||||||
const intl = useIntl();
|
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 = () => {
|
const handleLoadMore = () => {
|
||||||
if (!isLoading) {
|
if (!isLoading) {
|
||||||
|
|
Loading…
Reference in New Issue