environments/review-group-comp-s3yeyp/deployments/2859
parent
50dadeb1b8
commit
7be8218f0c
@ -1,3 +1,4 @@
|
||||
export enum Entities {
|
||||
GROUP_MEMBERSHIPS = 'GroupMemberships'
|
||||
GROUP_MEMBERSHIPS = 'GroupMemberships',
|
||||
POPULAR_GROUPS = 'PopularGroups'
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useFeatures } from '../useFeatures';
|
||||
import { useGroupRelationships } from '../useGroups';
|
||||
|
||||
function usePopularGroups() {
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.POPULAR_GROUPS, ''],
|
||||
'/api/mock/groups', // '/api/v1/truth/trends/groups'
|
||||
{
|
||||
parser: parseGroup,
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
const parseGroup = (entity: unknown) => {
|
||||
const result = groupSchema.safeParse(entity);
|
||||
if (result.success) {
|
||||
return result.data;
|
||||
}
|
||||
};
|
||||
|
||||
export { usePopularGroups };
|
@ -0,0 +1,40 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useFeatures } from '../useFeatures';
|
||||
import { useGroupRelationships } from '../useGroups';
|
||||
|
||||
function useSuggestedGroups() {
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.POPULAR_GROUPS, ''],
|
||||
'/api/mock/groups', // '/api/v1/truth/suggestions/groups'
|
||||
{
|
||||
parser: parseGroup,
|
||||
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,
|
||||
};
|
||||
}
|
||||
|
||||
const parseGroup = (entity: unknown) => {
|
||||
const result = groupSchema.safeParse(entity);
|
||||
if (result.success) {
|
||||
return result.data;
|
||||
}
|
||||
};
|
||||
|
||||
export { useSuggestedGroups };
|
Loading…
Reference in new issue