Allow to manage instance relays

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak
2024-04-02 11:45:15 +02:00
parent 7320299b3c
commit 0fc158a7d0
14 changed files with 239 additions and 9 deletions

View File

@ -1,6 +1,9 @@
export { useCreateDomain, type CreateDomainParams } from './useCreateDomain';
export { useCreateRelay } from './useCreateRelay';
export { useDeleteDomain } from './useDeleteDomain';
export { useDeleteRelay } from './useDeleteRelay';
export { useDomains } from './useDomains';
export { useRelays } from './useRelays';
export { useSuggest } from './useSuggest';
export { useUpdateDomain } from './useUpdateDomain';
export { useVerify } from './useVerify';

View File

@ -0,0 +1,18 @@
import { Entities } from 'soapbox/entity-store/entities';
import { useCreateEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks';
import { relaySchema } from 'soapbox/schemas';
const useCreateRelay = () => {
const api = useApi();
const { createEntity, ...rest } = useCreateEntity([Entities.RELAYS], (relayUrl: string) =>
api.post('/api/v1/pleroma/admin/relay', { relay_url: relayUrl }), { schema: relaySchema });
return {
createRelay: createEntity,
...rest,
};
};
export { useCreateRelay };

View File

@ -2,11 +2,6 @@ import { Entities } from 'soapbox/entity-store/entities';
import { useDeleteEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks';
interface DeleteDomainParams {
domain: string;
public: boolean;
}
const useDeleteDomain = () => {
const api = useApi();
@ -23,4 +18,4 @@ const useDeleteDomain = () => {
};
};
export { useDeleteDomain, type DeleteDomainParams };
export { useDeleteDomain };

View File

@ -0,0 +1,19 @@
import { Entities } from 'soapbox/entity-store/entities';
import { useDeleteEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks';
const useDeleteRelay = () => {
const api = useApi();
const { deleteEntity, ...rest } = useDeleteEntity(Entities.RELAYS, (relayUrl: string) =>
api.delete('/api/v1/pleroma/admin/relay', {
data: { relay_url: relayUrl },
}));
return {
mutate: deleteEntity,
...rest,
};
};
export { useDeleteRelay };

View File

@ -0,0 +1,25 @@
import { useQuery } from '@tanstack/react-query';
import { useApi } from 'soapbox/hooks';
import { relaySchema, type Relay } from 'soapbox/schemas';
const useRelays = () => {
const api = useApi();
const getRelays = async () => {
const { data } = await api.get<{ relays: Relay[] }>('/api/v1/pleroma/admin/relay');
const normalizedData = data.relays?.map((relay) => relaySchema.parse(relay));
return normalizedData;
};
const result = useQuery<ReadonlyArray<Relay>>({
queryKey: ['relays'],
queryFn: getRelays,
placeholderData: [],
});
return result;
};
export { useRelays };