Allow to manage instance relays
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -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';
|
||||
18
src/api/hooks/admin/useCreateRelay.ts
Normal file
18
src/api/hooks/admin/useCreateRelay.ts
Normal 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 };
|
||||
@ -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 };
|
||||
|
||||
19
src/api/hooks/admin/useDeleteRelay.ts
Normal file
19
src/api/hooks/admin/useDeleteRelay.ts
Normal 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 };
|
||||
25
src/api/hooks/admin/useRelays.ts
Normal file
25
src/api/hooks/admin/useRelays.ts
Normal 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 };
|
||||
Reference in New Issue
Block a user