kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Add useGroupLookup hook
rodzic
17757ea326
commit
4e822a80dd
|
@ -1,6 +1,7 @@
|
|||
export { useEntities } from './useEntities';
|
||||
export { useEntity } from './useEntity';
|
||||
export { useEntityActions } from './useEntityActions';
|
||||
export { useEntityLookup } from './useEntityLookup';
|
||||
export { useCreateEntity } from './useCreateEntity';
|
||||
export { useDeleteEntity } from './useDeleteEntity';
|
||||
export { useDismissEntity } from './useDismissEntity';
|
||||
|
|
|
@ -63,4 +63,4 @@ function findEntity<TEntity extends Entity>(
|
|||
}
|
||||
}
|
||||
|
||||
export default useEntityLookup;
|
||||
export { useEntityLookup };
|
|
@ -0,0 +1,17 @@
|
|||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityLookup } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { groupSchema } from 'soapbox/schemas';
|
||||
|
||||
function useGroupLookup(slug: string) {
|
||||
const api = useApi();
|
||||
|
||||
return useEntityLookup(
|
||||
Entities.GROUPS,
|
||||
(group) => group.slug === slug,
|
||||
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
|
||||
{ schema: groupSchema },
|
||||
);
|
||||
}
|
||||
|
||||
export { useGroupLookup };
|
|
@ -28,6 +28,7 @@ const groupSchema = z.object({
|
|||
members_count: z.number().catch(0),
|
||||
note: z.string().transform(note => note === '<p></p>' ? '' : note).catch(''),
|
||||
relationship: groupRelationshipSchema.nullable().catch(null), // Dummy field to be overwritten later
|
||||
slug: z.string().catch(''), // TruthSocial
|
||||
statuses_visibility: z.string().catch('public'),
|
||||
tags: z.array(groupTagSchema).catch([]),
|
||||
uri: z.string().catch(''),
|
||||
|
|
Ładowanie…
Reference in New Issue