import { Entities } from 'soapbox/entity-store/entities'; import { useBatchedEntities } from 'soapbox/entity-store/hooks/useBatchedEntities'; import { useApi, useLoggedIn } from 'soapbox/hooks'; import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; function useGroupRelationships(listKey: string[], ids: string[]) { const api = useApi(); const { isLoggedIn } = useLoggedIn(); function fetchGroupRelationships(ids: string[]) { const q = ids.map((id) => `id[]=${id}`).join('&'); return api.get(`/api/v1/groups/relationships?${q}`); } const { entityMap: relationships, ...result } = useBatchedEntities( [Entities.RELATIONSHIPS, ...listKey], ids, fetchGroupRelationships, { schema: groupRelationshipSchema, enabled: isLoggedIn }, ); return { relationships, ...result }; } export { useGroupRelationships };