pleroma/app/soapbox/api/hooks/groups/useGroup.ts

28 lines
792 B
TypeScript
Raw Normal View History

2023-05-02 10:25:32 -07:00
import { Entities } from 'soapbox/entity-store/entities';
import { useEntity } from 'soapbox/entity-store/hooks';
import { useApi } from 'soapbox/hooks';
import { type Group, groupSchema } from 'soapbox/schemas';
import { useGroupRelationship } from './useGroupRelationship';
function useGroup(groupId: string, refetch = true) {
const api = useApi();
const { entity: group, ...result } = useEntity<Group>(
[Entities.GROUPS, groupId],
() => api.get(`/api/v1/groups/${groupId}`),
2023-06-08 06:00:49 -07:00
{
schema: groupSchema,
refetch,
enabled: !!groupId,
},
2023-05-02 10:25:32 -07:00
);
const { groupRelationship: relationship } = useGroupRelationship(groupId);
2023-05-02 10:25:32 -07:00
return {
...result,
group: group ? { ...group, relationship: relationship || null } : undefined,
};
}
export { useGroup };