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

34 lines
898 B
TypeScript
Raw Normal View History

import { Entities } from 'soapbox/entity-store/entities';
import { useEntities } from 'soapbox/entity-store/hooks';
2023-05-01 11:58:40 -07:00
import { useApi, useFeatures } from 'soapbox/hooks';
import { type Group, groupSchema } from 'soapbox/schemas';
2023-05-02 10:25:32 -07:00
import { useGroupRelationships } from './useGroupRelationships';
function useSuggestedGroups() {
const api = useApi();
const features = useFeatures();
const { entities, ...result } = useEntities<Group>(
[Entities.GROUPS, 'suggested'],
2023-03-28 07:32:56 -07:00
() => api.get('/api/v1/truth/suggestions/groups'),
{
2023-03-14 07:11:20 -07:00
schema: groupSchema,
enabled: features.groupsDiscovery,
},
);
const { relationships } = useGroupRelationships(entities.map(entity => entity.id));
const groups = entities.map((group) => ({
...group,
relationship: relationships[group.id] || null,
}));
return {
...result,
groups,
};
}
export { useSuggestedGroups };