Fix useRelationships hook

This commit is contained in:
Alex Gleason 2023-06-25 16:11:00 -05:00
parent 989d99f908
commit bfe6ab3c26
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -7,12 +7,16 @@ import { type Relationship, relationshipSchema } from 'soapbox/schemas';
function useRelationships(listKey: string[], ids: string[]) {
const api = useApi();
const { isLoggedIn } = useLoggedIn();
const q = ids.map(id => `id[]=${id}`).join('&');
function fetchRelationships(ids: string[]) {
const q = ids.map((id) => `id[]=${id}`).join('&');
return api.get(`/api/v1/accounts/relationships?${q}`);
}
const { entityMap: relationships, ...result } = useBatchedEntities<Relationship>(
[Entities.RELATIONSHIPS, ...listKey],
ids,
() => api.get(`/api/v1/accounts/relationships?${q}`),
fetchRelationships,
{ schema: relationshipSchema, enabled: isLoggedIn },
);