diff --git a/app/soapbox/features/group/group-tags.tsx b/app/soapbox/features/group/group-tags.tsx index d5335e844..5ff48b2e0 100644 --- a/app/soapbox/features/group/group-tags.tsx +++ b/app/soapbox/features/group/group-tags.tsx @@ -1,10 +1,9 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; -import { useGroupTags } from 'soapbox/api/hooks'; +import { useGroup, useGroupTags } from 'soapbox/api/hooks'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Icon, Stack, Text } from 'soapbox/components/ui'; -import { useGroup } from 'soapbox/queries/groups'; import PlaceholderAccount from '../placeholder/components/placeholder-account'; diff --git a/app/soapbox/queries/groups.ts b/app/soapbox/queries/groups.ts deleted file mode 100644 index 9715e0614..000000000 --- a/app/soapbox/queries/groups.ts +++ /dev/null @@ -1,68 +0,0 @@ -import { useQuery } from '@tanstack/react-query'; -import { AxiosRequestConfig } from 'axios'; - -import { useApi, useFeatures } from 'soapbox/hooks'; -import { normalizeGroup, normalizeGroupRelationship } from 'soapbox/normalizers'; -import { Group, GroupRelationship } from 'soapbox/types/entities'; - -const GroupKeys = { - group: (id: string) => ['groups', 'group', id] as const, - pendingGroups: (userId: string) => ['groups', userId, 'pending'] as const, -}; - -const useGroupsApi = () => { - const api = useApi(); - - const getGroupRelationships = async (ids: string[]) => { - const queryString = ids.map((id) => `id[]=${id}`).join('&'); - const { data } = await api.get(`/api/v1/groups/relationships?${queryString}`); - - return data; - }; - - const fetchGroups = async (endpoint: string, params: AxiosRequestConfig['params'] = {}) => { - const response = await api.get(endpoint, { - params, - }); - const groups = [response.data].flat(); - const relationships = await getGroupRelationships(groups.map((group) => group.id)); - const result = groups.map((group) => { - const relationship = relationships.find((relationship) => relationship.id === group.id); - - return normalizeGroup({ - ...group, - relationship: relationship ? normalizeGroupRelationship(relationship) : null, - }); - }); - - return { - response, - groups: result, - }; - }; - - return { fetchGroups }; -}; - -const useGroup = (id: string) => { - const features = useFeatures(); - const { fetchGroups } = useGroupsApi(); - - const getGroup = async () => { - const { groups } = await fetchGroups(`/api/v1/groups/${id}`); - return groups[0]; - }; - - const queryInfo = useQuery(GroupKeys.group(id), getGroup, { - enabled: features.groups && !!id, - }); - - return { - ...queryInfo, - group: queryInfo.data, - }; -}; - -export { - useGroup, -};