Fix useRelationships getting called while logged out

This commit is contained in:
Alex Gleason 2023-06-23 11:30:10 -05:00
parent 7bfde28b0c
commit ab5c4a4233
No known key found for this signature in database
GPG key ID: 7211D1F99744FBB7

View file

@ -1,15 +1,17 @@
import { Entities } from 'soapbox/entity-store/entities'; import { Entities } from 'soapbox/entity-store/entities';
import { useEntities } from 'soapbox/entity-store/hooks'; import { useEntities } from 'soapbox/entity-store/hooks';
import { useLoggedIn } from 'soapbox/hooks';
import { useApi } from 'soapbox/hooks/useApi'; import { useApi } from 'soapbox/hooks/useApi';
import { type Relationship, relationshipSchema } from 'soapbox/schemas'; import { type Relationship, relationshipSchema } from 'soapbox/schemas';
function useRelationships(ids: string[]) { function useRelationships(ids: string[]) {
const api = useApi(); const api = useApi();
const { isLoggedIn } = useLoggedIn();
const { entities: relationships, ...result } = useEntities<Relationship>( const { entities: relationships, ...result } = useEntities<Relationship>(
[Entities.RELATIONSHIPS], [Entities.RELATIONSHIPS],
() => api.get(`/api/v1/accounts/relationships?${ids.map(id => `id[]=${id}`).join('&')}`), () => api.get(`/api/v1/accounts/relationships?${ids.map(id => `id[]=${id}`).join('&')}`),
{ schema: relationshipSchema, enabled: ids.filter(Boolean).length > 0 }, { schema: relationshipSchema, enabled: isLoggedIn && ids.filter(Boolean).length > 0 },
); );
return { return {