From e0af6c4b2e78ec010973d279fc620e6299e5741a Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Mon, 1 May 2023 14:58:40 -0400 Subject: [PATCH 1/2] Move Group hooks to api folder --- .../{hooks/api => api/hooks/accounts}/useAccount.ts | 2 +- .../api => api/hooks/accounts}/useRelationships.ts | 3 +-- .../api => api/hooks}/groups/useBlockGroupMember.ts | 0 .../hooks}/groups/useCancelMembershipRequest.ts | 0 .../{hooks/api => api/hooks}/groups/useCreateGroup.ts | 0 .../{hooks/api => api/hooks}/groups/useDeleteGroup.ts | 0 .../api => api/hooks}/groups/useDemoteGroupMember.ts | 0 .../{hooks/api => api/hooks}/groups/useGroupLookup.ts | 0 .../{hooks/api => api/hooks}/groups/useGroupMedia.ts | 0 .../{hooks/api => api/hooks/groups}/useGroupMembers.ts | 2 +- .../hooks}/groups/useGroupMembershipRequests.ts | 0 .../{hooks/api => api/hooks}/groups/useGroupSearch.ts | 4 +--- .../{hooks/api => api/hooks}/groups/useGroupTag.ts | 0 .../{hooks/api => api/hooks}/groups/useGroupTags.ts | 0 .../api => api/hooks}/groups/useGroupValidation.ts | 0 app/soapbox/{hooks/api => api/hooks}/groups/useGroups.ts | 3 +-- .../{hooks/api => api/hooks}/groups/useGroupsFromTag.ts | 4 +--- .../{hooks/api => api/hooks}/groups/useJoinGroup.ts | 0 .../{hooks/api => api/hooks}/groups/useLeaveGroup.ts | 0 .../{hooks/api => api/hooks/groups}/usePopularGroups.ts | 7 ++++--- .../{hooks/api => api/hooks}/groups/usePopularTags.ts | 6 ++---- .../api => api/hooks}/groups/usePromoteGroupMember.ts | 0 .../api => api/hooks/groups}/useSuggestedGroups.ts | 7 +++---- .../{hooks/api => api/hooks}/groups/useUpdateGroup.ts | 0 .../{hooks/api => api/hooks}/groups/useUpdateGroupTag.ts | 0 app/soapbox/{hooks/api => api/hooks}/index.ts | 9 +++++++-- app/soapbox/components/hoc/group-lookup-hoc.tsx | 2 +- .../features/group/components/group-action-button.tsx | 2 +- .../features/group/components/group-member-list-item.tsx | 2 +- .../features/group/components/group-options-button.tsx | 2 +- .../features/group/components/group-tag-list-item.tsx | 2 +- app/soapbox/features/group/edit-group.tsx | 2 +- app/soapbox/features/group/group-blocked-members.tsx | 2 +- app/soapbox/features/group/group-gallery.tsx | 2 +- app/soapbox/features/group/group-members.tsx | 5 ++--- app/soapbox/features/group/group-membership-requests.tsx | 3 +-- app/soapbox/features/group/group-tag-timeline.tsx | 2 +- app/soapbox/features/group/group-tags.tsx | 2 +- app/soapbox/features/group/group-timeline.tsx | 2 +- app/soapbox/features/group/manage-group.tsx | 2 +- .../groups/components/discover/popular-groups.tsx | 2 +- .../features/groups/components/discover/popular-tags.tsx | 2 +- .../groups/components/discover/search/results.tsx | 2 +- .../groups/components/discover/search/search.tsx | 2 +- .../groups/components/discover/suggested-groups.tsx | 2 +- app/soapbox/features/groups/index.tsx | 2 +- app/soapbox/features/groups/popular.tsx | 2 +- app/soapbox/features/groups/suggested.tsx | 2 +- app/soapbox/features/groups/tag.tsx | 2 +- app/soapbox/features/groups/tags.tsx | 2 +- .../modals/manage-group-modal/create-group-modal.tsx | 2 +- .../modals/manage-group-modal/steps/details-step.tsx | 2 +- .../modals/manage-group-modal/steps/privacy-step.tsx | 2 +- .../features/ui/components/panels/my-groups-panel.tsx | 2 +- .../ui/components/panels/suggested-groups-panel.tsx | 2 +- app/soapbox/hooks/useGroupsPath.ts | 3 ++- app/soapbox/pages/group-page.tsx | 6 +++--- 57 files changed, 57 insertions(+), 61 deletions(-) rename app/soapbox/{hooks/api => api/hooks/accounts}/useAccount.ts (91%) rename app/soapbox/{hooks/api => api/hooks/accounts}/useRelationships.ts (88%) rename app/soapbox/{hooks/api => api/hooks}/groups/useBlockGroupMember.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useCancelMembershipRequest.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useCreateGroup.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useDeleteGroup.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useDemoteGroupMember.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupLookup.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupMedia.ts (100%) rename app/soapbox/{hooks/api => api/hooks/groups}/useGroupMembers.ts (89%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupMembershipRequests.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupSearch.ts (88%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupTag.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupTags.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupValidation.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroups.ts (97%) rename app/soapbox/{hooks/api => api/hooks}/groups/useGroupsFromTag.ts (87%) rename app/soapbox/{hooks/api => api/hooks}/groups/useJoinGroup.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useLeaveGroup.ts (100%) rename app/soapbox/{hooks/api => api/hooks/groups}/usePopularGroups.ts (79%) rename app/soapbox/{hooks/api => api/hooks}/groups/usePopularTags.ts (73%) rename app/soapbox/{hooks/api => api/hooks}/groups/usePromoteGroupMember.ts (100%) rename app/soapbox/{hooks/api => api/hooks/groups}/useSuggestedGroups.ts (74%) rename app/soapbox/{hooks/api => api/hooks}/groups/useUpdateGroup.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/groups/useUpdateGroupTag.ts (100%) rename app/soapbox/{hooks/api => api/hooks}/index.ts (77%) diff --git a/app/soapbox/hooks/api/useAccount.ts b/app/soapbox/api/hooks/accounts/useAccount.ts similarity index 91% rename from app/soapbox/hooks/api/useAccount.ts rename to app/soapbox/api/hooks/accounts/useAccount.ts index a222d8de4..2442ad642 100644 --- a/app/soapbox/hooks/api/useAccount.ts +++ b/app/soapbox/api/hooks/accounts/useAccount.ts @@ -1,8 +1,8 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntity } from 'soapbox/entity-store/hooks'; +import { useApi } from 'soapbox/hooks/useApi'; import { type Account, accountSchema } from 'soapbox/schemas'; -import { useApi } from '../useApi'; import { useRelationships } from './useRelationships'; diff --git a/app/soapbox/hooks/api/useRelationships.ts b/app/soapbox/api/hooks/accounts/useRelationships.ts similarity index 88% rename from app/soapbox/hooks/api/useRelationships.ts rename to app/soapbox/api/hooks/accounts/useRelationships.ts index fde5f1017..2103e2438 100644 --- a/app/soapbox/hooks/api/useRelationships.ts +++ b/app/soapbox/api/hooks/accounts/useRelationships.ts @@ -1,9 +1,8 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; +import { useApi } from 'soapbox/hooks/useApi'; import { type Relationship, relationshipSchema } from 'soapbox/schemas'; -import { useApi } from '../useApi'; - function useRelationships(ids: string[]) { const api = useApi(); diff --git a/app/soapbox/hooks/api/groups/useBlockGroupMember.ts b/app/soapbox/api/hooks/groups/useBlockGroupMember.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useBlockGroupMember.ts rename to app/soapbox/api/hooks/groups/useBlockGroupMember.ts diff --git a/app/soapbox/hooks/api/groups/useCancelMembershipRequest.ts b/app/soapbox/api/hooks/groups/useCancelMembershipRequest.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useCancelMembershipRequest.ts rename to app/soapbox/api/hooks/groups/useCancelMembershipRequest.ts diff --git a/app/soapbox/hooks/api/groups/useCreateGroup.ts b/app/soapbox/api/hooks/groups/useCreateGroup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useCreateGroup.ts rename to app/soapbox/api/hooks/groups/useCreateGroup.ts diff --git a/app/soapbox/hooks/api/groups/useDeleteGroup.ts b/app/soapbox/api/hooks/groups/useDeleteGroup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useDeleteGroup.ts rename to app/soapbox/api/hooks/groups/useDeleteGroup.ts diff --git a/app/soapbox/hooks/api/groups/useDemoteGroupMember.ts b/app/soapbox/api/hooks/groups/useDemoteGroupMember.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useDemoteGroupMember.ts rename to app/soapbox/api/hooks/groups/useDemoteGroupMember.ts diff --git a/app/soapbox/hooks/api/groups/useGroupLookup.ts b/app/soapbox/api/hooks/groups/useGroupLookup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupLookup.ts rename to app/soapbox/api/hooks/groups/useGroupLookup.ts diff --git a/app/soapbox/hooks/api/groups/useGroupMedia.ts b/app/soapbox/api/hooks/groups/useGroupMedia.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupMedia.ts rename to app/soapbox/api/hooks/groups/useGroupMedia.ts diff --git a/app/soapbox/hooks/api/useGroupMembers.ts b/app/soapbox/api/hooks/groups/useGroupMembers.ts similarity index 89% rename from app/soapbox/hooks/api/useGroupMembers.ts rename to app/soapbox/api/hooks/groups/useGroupMembers.ts index 3a1c99af5..a9b03e7f2 100644 --- a/app/soapbox/hooks/api/useGroupMembers.ts +++ b/app/soapbox/api/hooks/groups/useGroupMembers.ts @@ -3,7 +3,7 @@ import { useEntities } from 'soapbox/entity-store/hooks'; import { GroupMember, groupMemberSchema } from 'soapbox/schemas'; import { GroupRoles } from 'soapbox/schemas/group-member'; -import { useApi } from '../useApi'; +import { useApi } from '../../../hooks/useApi'; function useGroupMembers(groupId: string, role: GroupRoles) { const api = useApi(); diff --git a/app/soapbox/hooks/api/groups/useGroupMembershipRequests.ts b/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupMembershipRequests.ts rename to app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts diff --git a/app/soapbox/hooks/api/groups/useGroupSearch.ts b/app/soapbox/api/hooks/groups/useGroupSearch.ts similarity index 88% rename from app/soapbox/hooks/api/groups/useGroupSearch.ts rename to app/soapbox/api/hooks/groups/useGroupSearch.ts index 17c10e90f..508310911 100644 --- a/app/soapbox/hooks/api/groups/useGroupSearch.ts +++ b/app/soapbox/api/hooks/groups/useGroupSearch.ts @@ -1,10 +1,8 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; +import { useApi, useFeatures } from 'soapbox/hooks'; import { groupSchema } from 'soapbox/schemas'; -import { useApi } from '../../useApi'; -import { useFeatures } from '../../useFeatures'; - import { useGroupRelationships } from './useGroups'; import type { Group } from 'soapbox/schemas'; diff --git a/app/soapbox/hooks/api/groups/useGroupTag.ts b/app/soapbox/api/hooks/groups/useGroupTag.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupTag.ts rename to app/soapbox/api/hooks/groups/useGroupTag.ts diff --git a/app/soapbox/hooks/api/groups/useGroupTags.ts b/app/soapbox/api/hooks/groups/useGroupTags.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupTags.ts rename to app/soapbox/api/hooks/groups/useGroupTags.ts diff --git a/app/soapbox/hooks/api/groups/useGroupValidation.ts b/app/soapbox/api/hooks/groups/useGroupValidation.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useGroupValidation.ts rename to app/soapbox/api/hooks/groups/useGroupValidation.ts diff --git a/app/soapbox/hooks/api/groups/useGroups.ts b/app/soapbox/api/hooks/groups/useGroups.ts similarity index 97% rename from app/soapbox/hooks/api/groups/useGroups.ts rename to app/soapbox/api/hooks/groups/useGroups.ts index 9db3001ce..42904c142 100644 --- a/app/soapbox/hooks/api/groups/useGroups.ts +++ b/app/soapbox/api/hooks/groups/useGroups.ts @@ -5,11 +5,10 @@ import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; import { Entities } from 'soapbox/entity-store/entities'; import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; import { useApi, useAppDispatch } from 'soapbox/hooks'; +import { useFeatures } from 'soapbox/hooks/useFeatures'; import { groupSchema, Group } from 'soapbox/schemas/group'; import { groupRelationshipSchema, GroupRelationship } from 'soapbox/schemas/group-relationship'; -import { useFeatures } from '../../useFeatures'; - function useGroups(q: string = '') { const api = useApi(); const features = useFeatures(); diff --git a/app/soapbox/hooks/api/groups/useGroupsFromTag.ts b/app/soapbox/api/hooks/groups/useGroupsFromTag.ts similarity index 87% rename from app/soapbox/hooks/api/groups/useGroupsFromTag.ts rename to app/soapbox/api/hooks/groups/useGroupsFromTag.ts index a6b8540dc..f579c719e 100644 --- a/app/soapbox/hooks/api/groups/useGroupsFromTag.ts +++ b/app/soapbox/api/hooks/groups/useGroupsFromTag.ts @@ -1,10 +1,8 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; +import { useApi, useFeatures } from 'soapbox/hooks'; import { groupSchema } from 'soapbox/schemas'; -import { useApi } from '../../useApi'; -import { useFeatures } from '../../useFeatures'; - import { useGroupRelationships } from './useGroups'; import type { Group } from 'soapbox/schemas'; diff --git a/app/soapbox/hooks/api/groups/useJoinGroup.ts b/app/soapbox/api/hooks/groups/useJoinGroup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useJoinGroup.ts rename to app/soapbox/api/hooks/groups/useJoinGroup.ts diff --git a/app/soapbox/hooks/api/groups/useLeaveGroup.ts b/app/soapbox/api/hooks/groups/useLeaveGroup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useLeaveGroup.ts rename to app/soapbox/api/hooks/groups/useLeaveGroup.ts diff --git a/app/soapbox/hooks/api/usePopularGroups.ts b/app/soapbox/api/hooks/groups/usePopularGroups.ts similarity index 79% rename from app/soapbox/hooks/api/usePopularGroups.ts rename to app/soapbox/api/hooks/groups/usePopularGroups.ts index 385322500..ead72a79b 100644 --- a/app/soapbox/hooks/api/usePopularGroups.ts +++ b/app/soapbox/api/hooks/groups/usePopularGroups.ts @@ -2,9 +2,10 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; import { Group, groupSchema } from 'soapbox/schemas'; -import { useGroupRelationships } from '../api/groups/useGroups'; -import { useApi } from '../useApi'; -import { useFeatures } from '../useFeatures'; +import { useApi } from '../../../hooks/useApi'; +import { useFeatures } from '../../../hooks/useFeatures'; + +import { useGroupRelationships } from './useGroups'; function usePopularGroups() { const api = useApi(); diff --git a/app/soapbox/hooks/api/groups/usePopularTags.ts b/app/soapbox/api/hooks/groups/usePopularTags.ts similarity index 73% rename from app/soapbox/hooks/api/groups/usePopularTags.ts rename to app/soapbox/api/hooks/groups/usePopularTags.ts index 0bd272a2d..e0ec2c550 100644 --- a/app/soapbox/hooks/api/groups/usePopularTags.ts +++ b/app/soapbox/api/hooks/groups/usePopularTags.ts @@ -1,9 +1,7 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; -import { GroupTag, groupTagSchema } from 'soapbox/schemas'; - -import { useApi } from '../../useApi'; -import { useFeatures } from '../../useFeatures'; +import { useApi, useFeatures } from 'soapbox/hooks'; +import { type GroupTag, groupTagSchema } from 'soapbox/schemas'; function usePopularTags() { const api = useApi(); diff --git a/app/soapbox/hooks/api/groups/usePromoteGroupMember.ts b/app/soapbox/api/hooks/groups/usePromoteGroupMember.ts similarity index 100% rename from app/soapbox/hooks/api/groups/usePromoteGroupMember.ts rename to app/soapbox/api/hooks/groups/usePromoteGroupMember.ts diff --git a/app/soapbox/hooks/api/useSuggestedGroups.ts b/app/soapbox/api/hooks/groups/useSuggestedGroups.ts similarity index 74% rename from app/soapbox/hooks/api/useSuggestedGroups.ts rename to app/soapbox/api/hooks/groups/useSuggestedGroups.ts index 49f60c2b1..78b1ddb79 100644 --- a/app/soapbox/hooks/api/useSuggestedGroups.ts +++ b/app/soapbox/api/hooks/groups/useSuggestedGroups.ts @@ -1,10 +1,9 @@ import { Entities } from 'soapbox/entity-store/entities'; import { useEntities } from 'soapbox/entity-store/hooks'; -import { Group, groupSchema } from 'soapbox/schemas'; +import { useApi, useFeatures } from 'soapbox/hooks'; +import { type Group, groupSchema } from 'soapbox/schemas'; -import { useGroupRelationships } from '../api/groups/useGroups'; -import { useApi } from '../useApi'; -import { useFeatures } from '../useFeatures'; +import { useGroupRelationships } from './useGroups'; function useSuggestedGroups() { const api = useApi(); diff --git a/app/soapbox/hooks/api/groups/useUpdateGroup.ts b/app/soapbox/api/hooks/groups/useUpdateGroup.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useUpdateGroup.ts rename to app/soapbox/api/hooks/groups/useUpdateGroup.ts diff --git a/app/soapbox/hooks/api/groups/useUpdateGroupTag.ts b/app/soapbox/api/hooks/groups/useUpdateGroupTag.ts similarity index 100% rename from app/soapbox/hooks/api/groups/useUpdateGroupTag.ts rename to app/soapbox/api/hooks/groups/useUpdateGroupTag.ts diff --git a/app/soapbox/hooks/api/index.ts b/app/soapbox/api/hooks/index.ts similarity index 77% rename from app/soapbox/hooks/api/index.ts rename to app/soapbox/api/hooks/index.ts index c8e1f67c3..eba4f0d84 100644 --- a/app/soapbox/hooks/api/index.ts +++ b/app/soapbox/api/hooks/index.ts @@ -1,7 +1,8 @@ + /** * Accounts */ -export { useAccount } from './useAccount'; +export { useAccount } from './accounts/useAccount'; /** * Groups @@ -12,7 +13,9 @@ export { useCreateGroup, type CreateGroupParams } from './groups/useCreateGroup' export { useDeleteGroup } from './groups/useDeleteGroup'; export { useDemoteGroupMember } from './groups/useDemoteGroupMember'; export { useGroup, useGroups } from './groups/useGroups'; +export { useGroupLookup } from './groups/useGroupLookup'; export { useGroupMedia } from './groups/useGroupMedia'; +export { useGroupMembers } from './groups/useGroupMembers'; export { useGroupMembershipRequests } from './groups/useGroupMembershipRequests'; export { useGroupSearch } from './groups/useGroupSearch'; export { useGroupTag } from './groups/useGroupTag'; @@ -21,12 +24,14 @@ export { useGroupValidation } from './groups/useGroupValidation'; export { useGroupsFromTag } from './groups/useGroupsFromTag'; export { useJoinGroup } from './groups/useJoinGroup'; export { useLeaveGroup } from './groups/useLeaveGroup'; +export { usePopularGroups } from './groups/usePopularGroups'; export { usePopularTags } from './groups/usePopularTags'; export { usePromoteGroupMember } from './groups/usePromoteGroupMember'; +export { useSuggestedGroups } from './groups/useSuggestedGroups'; export { useUpdateGroup } from './groups/useUpdateGroup'; export { useUpdateGroupTag } from './groups/useUpdateGroupTag'; /** * Relationships */ -export { useRelationships } from './useRelationships'; +export { useRelationships } from './accounts/useRelationships'; \ No newline at end of file diff --git a/app/soapbox/components/hoc/group-lookup-hoc.tsx b/app/soapbox/components/hoc/group-lookup-hoc.tsx index a7c76eed6..07c2d475b 100644 --- a/app/soapbox/components/hoc/group-lookup-hoc.tsx +++ b/app/soapbox/components/hoc/group-lookup-hoc.tsx @@ -1,7 +1,7 @@ import React from 'react'; +import { useGroupLookup } from 'soapbox/api/hooks'; import ColumnLoading from 'soapbox/features/ui/components/column-loading'; -import { useGroupLookup } from 'soapbox/hooks/api/groups/useGroupLookup'; import { Layout } from '../ui'; diff --git a/app/soapbox/features/group/components/group-action-button.tsx b/app/soapbox/features/group/components/group-action-button.tsx index e9a47a962..005b9e245 100644 --- a/app/soapbox/features/group/components/group-action-button.tsx +++ b/app/soapbox/features/group/components/group-action-button.tsx @@ -3,11 +3,11 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; import { openModal } from 'soapbox/actions/modals'; +import { useCancelMembershipRequest, useJoinGroup, useLeaveGroup } from 'soapbox/api/hooks'; import { Button } from 'soapbox/components/ui'; import { importEntities } from 'soapbox/entity-store/actions'; import { Entities } from 'soapbox/entity-store/entities'; import { useAppDispatch, useOwnAccount } from 'soapbox/hooks'; -import { useCancelMembershipRequest, useJoinGroup, useLeaveGroup } from 'soapbox/hooks/api'; import { queryClient } from 'soapbox/queries/client'; import { GroupKeys } from 'soapbox/queries/groups'; import { GroupRoles } from 'soapbox/schemas/group-member'; diff --git a/app/soapbox/features/group/components/group-member-list-item.tsx b/app/soapbox/features/group/components/group-member-list-item.tsx index c88f4e58d..d2226879a 100644 --- a/app/soapbox/features/group/components/group-member-list-item.tsx +++ b/app/soapbox/features/group/components/group-member-list-item.tsx @@ -4,6 +4,7 @@ import { defineMessages, useIntl } from 'react-intl'; import { groupKick } from 'soapbox/actions/groups'; import { openModal } from 'soapbox/actions/modals'; +import { useAccount, useBlockGroupMember, useDemoteGroupMember, usePromoteGroupMember } from 'soapbox/api/hooks'; import Account from 'soapbox/components/account'; import DropdownMenu from 'soapbox/components/dropdown-menu/dropdown-menu'; import { HStack } from 'soapbox/components/ui'; @@ -11,7 +12,6 @@ import { deleteEntities } from 'soapbox/entity-store/actions'; import { Entities } from 'soapbox/entity-store/entities'; import PlaceholderAccount from 'soapbox/features/placeholder/components/placeholder-account'; import { useAppDispatch, useFeatures } from 'soapbox/hooks'; -import { useAccount, useBlockGroupMember, useDemoteGroupMember, usePromoteGroupMember } from 'soapbox/hooks/api'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; diff --git a/app/soapbox/features/group/components/group-options-button.tsx b/app/soapbox/features/group/components/group-options-button.tsx index 7f24a3668..597a751d7 100644 --- a/app/soapbox/features/group/components/group-options-button.tsx +++ b/app/soapbox/features/group/components/group-options-button.tsx @@ -3,10 +3,10 @@ import { defineMessages, useIntl } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; import { initReport, ReportableEntities } from 'soapbox/actions/reports'; +import { useLeaveGroup } from 'soapbox/api/hooks'; import DropdownMenu, { Menu } from 'soapbox/components/dropdown-menu'; import { IconButton } from 'soapbox/components/ui'; import { useAppDispatch, useOwnAccount } from 'soapbox/hooks'; -import { useLeaveGroup } from 'soapbox/hooks/api'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; diff --git a/app/soapbox/features/group/components/group-tag-list-item.tsx b/app/soapbox/features/group/components/group-tag-list-item.tsx index eab096747..7908bb13d 100644 --- a/app/soapbox/features/group/components/group-tag-list-item.tsx +++ b/app/soapbox/features/group/components/group-tag-list-item.tsx @@ -2,11 +2,11 @@ import React from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; +import { useUpdateGroupTag } from 'soapbox/api/hooks'; import { HStack, IconButton, Stack, Text, Tooltip } from 'soapbox/components/ui'; import { importEntities } from 'soapbox/entity-store/actions'; import { Entities } from 'soapbox/entity-store/entities'; import { useAppDispatch } from 'soapbox/hooks'; -import { useUpdateGroupTag } from 'soapbox/hooks/api'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; import { shortNumberFormat } from 'soapbox/utils/numbers'; diff --git a/app/soapbox/features/group/edit-group.tsx b/app/soapbox/features/group/edit-group.tsx index 184df76d5..c0e972604 100644 --- a/app/soapbox/features/group/edit-group.tsx +++ b/app/soapbox/features/group/edit-group.tsx @@ -1,9 +1,9 @@ import React, { useEffect, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; +import { useGroup, useUpdateGroup } from 'soapbox/api/hooks'; import { Button, Column, Form, FormActions, FormGroup, Icon, Input, Spinner, Textarea } from 'soapbox/components/ui'; import { useAppSelector, useInstance } from 'soapbox/hooks'; -import { useGroup, useUpdateGroup } from 'soapbox/hooks/api'; import { useImageField, useTextField } from 'soapbox/hooks/forms'; import toast from 'soapbox/toast'; import { isDefaultAvatar, isDefaultHeader } from 'soapbox/utils/accounts'; diff --git a/app/soapbox/features/group/group-blocked-members.tsx b/app/soapbox/features/group/group-blocked-members.tsx index 988b90b1b..f45e8259f 100644 --- a/app/soapbox/features/group/group-blocked-members.tsx +++ b/app/soapbox/features/group/group-blocked-members.tsx @@ -2,11 +2,11 @@ import React, { useCallback, useEffect } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { fetchGroupBlocks, groupUnblock } from 'soapbox/actions/groups'; +import { useGroup } from 'soapbox/api/hooks'; import Account from 'soapbox/components/account'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Column, HStack, Spinner } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector } from 'soapbox/hooks'; -import { useGroup } from 'soapbox/hooks/api'; import { makeGetAccount } from 'soapbox/selectors'; import toast from 'soapbox/toast'; diff --git a/app/soapbox/features/group/group-gallery.tsx b/app/soapbox/features/group/group-gallery.tsx index 70a77680d..f0b2b95c7 100644 --- a/app/soapbox/features/group/group-gallery.tsx +++ b/app/soapbox/features/group/group-gallery.tsx @@ -2,11 +2,11 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; import { openModal } from 'soapbox/actions/modals'; +import { useGroup, useGroupMedia } from 'soapbox/api/hooks'; import LoadMore from 'soapbox/components/load-more'; import MissingIndicator from 'soapbox/components/missing-indicator'; import { Column, Spinner } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { useGroup, useGroupMedia } from 'soapbox/hooks/api'; import MediaItem from '../account-gallery/components/media-item'; diff --git a/app/soapbox/features/group/group-members.tsx b/app/soapbox/features/group/group-members.tsx index 36ccd05b7..1c2a892f3 100644 --- a/app/soapbox/features/group/group-members.tsx +++ b/app/soapbox/features/group/group-members.tsx @@ -1,12 +1,10 @@ import clsx from 'clsx'; import React, { useMemo } from 'react'; +import { useGroup, useGroupMembers, useGroupMembershipRequests } from 'soapbox/api/hooks'; import { PendingItemsRow } from 'soapbox/components/pending-items-row'; import ScrollableList from 'soapbox/components/scrollable-list'; import { useFeatures } from 'soapbox/hooks'; -import { useGroup } from 'soapbox/hooks/api'; -import { useGroupMembershipRequests } from 'soapbox/hooks/api/groups/useGroupMembershipRequests'; -import { useGroupMembers } from 'soapbox/hooks/api/useGroupMembers'; import { GroupRoles } from 'soapbox/schemas/group-member'; import PlaceholderAccount from '../placeholder/components/placeholder-account'; @@ -15,6 +13,7 @@ import GroupMemberListItem from './components/group-member-list-item'; import type { Group } from 'soapbox/types/entities'; + interface IGroupMembers { params: { groupId: string } } diff --git a/app/soapbox/features/group/group-membership-requests.tsx b/app/soapbox/features/group/group-membership-requests.tsx index c83d45b06..e50092887 100644 --- a/app/soapbox/features/group/group-membership-requests.tsx +++ b/app/soapbox/features/group/group-membership-requests.tsx @@ -1,12 +1,11 @@ import React, { useEffect } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; +import { useGroup, useGroupMembers, useGroupMembershipRequests } from 'soapbox/api/hooks'; import Account from 'soapbox/components/account'; import { AuthorizeRejectButtons } from 'soapbox/components/authorize-reject-buttons'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Column, HStack, Spinner } from 'soapbox/components/ui'; -import { useGroup, useGroupMembershipRequests } from 'soapbox/hooks/api'; -import { useGroupMembers } from 'soapbox/hooks/api/useGroupMembers'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; diff --git a/app/soapbox/features/group/group-tag-timeline.tsx b/app/soapbox/features/group/group-tag-timeline.tsx index f2ddee382..e79092e7a 100644 --- a/app/soapbox/features/group/group-tag-timeline.tsx +++ b/app/soapbox/features/group/group-tag-timeline.tsx @@ -2,9 +2,9 @@ import React, { useEffect } from 'react'; import { FormattedMessage } from 'react-intl'; import { expandGroupTimelineFromTag } from 'soapbox/actions/timelines'; +import { useGroup, useGroupTag } from 'soapbox/api/hooks'; import { Column, Icon, Stack, Text } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { useGroup, useGroupTag } from 'soapbox/hooks/api'; import Timeline from '../ui/components/timeline'; diff --git a/app/soapbox/features/group/group-tags.tsx b/app/soapbox/features/group/group-tags.tsx index 516fb94df..710a4fdb5 100644 --- a/app/soapbox/features/group/group-tags.tsx +++ b/app/soapbox/features/group/group-tags.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { useGroupTags } from 'soapbox/api/hooks'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Icon, Stack, Text } from 'soapbox/components/ui'; -import { useGroupTags } from 'soapbox/hooks/api'; import { useGroup } from 'soapbox/queries/groups'; import PlaceholderAccount from '../placeholder/components/placeholder-account'; diff --git a/app/soapbox/features/group/group-timeline.tsx b/app/soapbox/features/group/group-timeline.tsx index d189fdb68..a920a862c 100644 --- a/app/soapbox/features/group/group-timeline.tsx +++ b/app/soapbox/features/group/group-timeline.tsx @@ -6,10 +6,10 @@ import { Link } from 'react-router-dom'; import { groupCompose, setGroupTimelineVisible, uploadCompose } from 'soapbox/actions/compose'; import { connectGroupStream } from 'soapbox/actions/streaming'; import { expandGroupTimeline } from 'soapbox/actions/timelines'; +import { useGroup } from 'soapbox/api/hooks'; import { Avatar, HStack, Icon, Stack, Text, Toggle } from 'soapbox/components/ui'; import ComposeForm from 'soapbox/features/compose/components/compose-form'; import { useAppDispatch, useAppSelector, useDraggedFiles, useOwnAccount } from 'soapbox/hooks'; -import { useGroup } from 'soapbox/hooks/api'; import Timeline from '../ui/components/timeline'; diff --git a/app/soapbox/features/group/manage-group.tsx b/app/soapbox/features/group/manage-group.tsx index 5c3ee5c24..648593318 100644 --- a/app/soapbox/features/group/manage-group.tsx +++ b/app/soapbox/features/group/manage-group.tsx @@ -3,10 +3,10 @@ import { defineMessages, useIntl } from 'react-intl'; import { useHistory } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; +import { useDeleteGroup, useGroup } from 'soapbox/api/hooks'; import List, { ListItem } from 'soapbox/components/list'; import { CardBody, CardHeader, CardTitle, Column, Spinner, Text } from 'soapbox/components/ui'; import { useAppDispatch, useBackend, useGroupsPath } from 'soapbox/hooks'; -import { useDeleteGroup, useGroup } from 'soapbox/hooks/api'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; import { TRUTHSOCIAL } from 'soapbox/utils/features'; diff --git a/app/soapbox/features/groups/components/discover/popular-groups.tsx b/app/soapbox/features/groups/components/discover/popular-groups.tsx index 894542eb8..83426f553 100644 --- a/app/soapbox/features/groups/components/discover/popular-groups.tsx +++ b/app/soapbox/features/groups/components/discover/popular-groups.tsx @@ -1,10 +1,10 @@ import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; +import { usePopularGroups } from 'soapbox/api/hooks'; import Link from 'soapbox/components/link'; import { Carousel, HStack, Stack, Text } from 'soapbox/components/ui'; import PlaceholderGroupDiscover from 'soapbox/features/placeholder/components/placeholder-group-discover'; -import { usePopularGroups } from 'soapbox/hooks/api/usePopularGroups'; import GroupGridItem from './group-grid-item'; diff --git a/app/soapbox/features/groups/components/discover/popular-tags.tsx b/app/soapbox/features/groups/components/discover/popular-tags.tsx index 4cfed0bee..75ff36628 100644 --- a/app/soapbox/features/groups/components/discover/popular-tags.tsx +++ b/app/soapbox/features/groups/components/discover/popular-tags.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { usePopularTags } from 'soapbox/api/hooks'; import Link from 'soapbox/components/link'; import { HStack, Stack, Text } from 'soapbox/components/ui'; -import { usePopularTags } from 'soapbox/hooks/api'; import TagListItem from './tag-list-item'; diff --git a/app/soapbox/features/groups/components/discover/search/results.tsx b/app/soapbox/features/groups/components/discover/search/results.tsx index 2543f6ebc..3ae6b2179 100644 --- a/app/soapbox/features/groups/components/discover/search/results.tsx +++ b/app/soapbox/features/groups/components/discover/search/results.tsx @@ -3,8 +3,8 @@ import React, { useCallback, useState } from 'react'; import { FormattedMessage } from 'react-intl'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; +import { useGroupSearch } from 'soapbox/api/hooks'; import { HStack, Stack, Text } from 'soapbox/components/ui'; -import { useGroupSearch } from 'soapbox/hooks/api'; import GroupGridItem from '../group-grid-item'; import GroupListItem from '../group-list-item'; diff --git a/app/soapbox/features/groups/components/discover/search/search.tsx b/app/soapbox/features/groups/components/discover/search/search.tsx index 647f10fb5..0e2d7f00e 100644 --- a/app/soapbox/features/groups/components/discover/search/search.tsx +++ b/app/soapbox/features/groups/components/discover/search/search.tsx @@ -1,10 +1,10 @@ import React, { useEffect } from 'react'; import { FormattedMessage } from 'react-intl'; +import { useGroupSearch } from 'soapbox/api/hooks'; import { Stack } from 'soapbox/components/ui'; import PlaceholderGroupSearch from 'soapbox/features/placeholder/components/placeholder-group-search'; import { useDebounce, useOwnAccount } from 'soapbox/hooks'; -import { useGroupSearch } from 'soapbox/hooks/api'; import { saveGroupSearch } from 'soapbox/utils/groups'; import Blankslate from './blankslate'; diff --git a/app/soapbox/features/groups/components/discover/suggested-groups.tsx b/app/soapbox/features/groups/components/discover/suggested-groups.tsx index e0e26e874..5d73cc3f0 100644 --- a/app/soapbox/features/groups/components/discover/suggested-groups.tsx +++ b/app/soapbox/features/groups/components/discover/suggested-groups.tsx @@ -1,10 +1,10 @@ import React, { useState } from 'react'; import { FormattedMessage } from 'react-intl'; +import { useSuggestedGroups } from 'soapbox/api/hooks'; import Link from 'soapbox/components/link'; import { Carousel, HStack, Stack, Text } from 'soapbox/components/ui'; import PlaceholderGroupDiscover from 'soapbox/features/placeholder/components/placeholder-group-discover'; -import { useSuggestedGroups } from 'soapbox/hooks/api/useSuggestedGroups'; import GroupGridItem from './group-grid-item'; diff --git a/app/soapbox/features/groups/index.tsx b/app/soapbox/features/groups/index.tsx index 7528989f6..7b1c51c55 100644 --- a/app/soapbox/features/groups/index.tsx +++ b/app/soapbox/features/groups/index.tsx @@ -3,11 +3,11 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { Link } from 'react-router-dom'; import { openModal } from 'soapbox/actions/modals'; +import { useGroups } from 'soapbox/api/hooks'; import GroupCard from 'soapbox/components/group-card'; import ScrollableList from 'soapbox/components/scrollable-list'; import { Button, Input, Stack, Text } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector, useDebounce, useFeatures } from 'soapbox/hooks'; -import { useGroups } from 'soapbox/hooks/api'; import { PERMISSION_CREATE_GROUPS, hasPermission } from 'soapbox/utils/permissions'; import PlaceholderGroupCard from '../placeholder/components/placeholder-group-card'; diff --git a/app/soapbox/features/groups/popular.tsx b/app/soapbox/features/groups/popular.tsx index c2c11148c..2f417dd8f 100644 --- a/app/soapbox/features/groups/popular.tsx +++ b/app/soapbox/features/groups/popular.tsx @@ -3,8 +3,8 @@ import React, { useCallback, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; +import { usePopularGroups } from 'soapbox/api/hooks'; import { Column } from 'soapbox/components/ui'; -import { usePopularGroups } from 'soapbox/hooks/api/usePopularGroups'; import GroupGridItem from './components/discover/group-grid-item'; import GroupListItem from './components/discover/group-list-item'; diff --git a/app/soapbox/features/groups/suggested.tsx b/app/soapbox/features/groups/suggested.tsx index 4d1843598..89833a9a8 100644 --- a/app/soapbox/features/groups/suggested.tsx +++ b/app/soapbox/features/groups/suggested.tsx @@ -3,8 +3,8 @@ import React, { useCallback, useState } from 'react'; import { defineMessages, useIntl } from 'react-intl'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; +import { useSuggestedGroups } from 'soapbox/api/hooks'; import { Column } from 'soapbox/components/ui'; -import { useSuggestedGroups } from 'soapbox/hooks/api/useSuggestedGroups'; import GroupGridItem from './components/discover/group-grid-item'; import GroupListItem from './components/discover/group-list-item'; diff --git a/app/soapbox/features/groups/tag.tsx b/app/soapbox/features/groups/tag.tsx index 8b18053d3..ccc54bbb3 100644 --- a/app/soapbox/features/groups/tag.tsx +++ b/app/soapbox/features/groups/tag.tsx @@ -2,8 +2,8 @@ import clsx from 'clsx'; import React, { useCallback, useState } from 'react'; import { Components, Virtuoso, VirtuosoGrid } from 'react-virtuoso'; +import { useGroupTag, useGroupsFromTag } from 'soapbox/api/hooks'; import { Column, HStack, Icon } from 'soapbox/components/ui'; -import { useGroupTag, useGroupsFromTag } from 'soapbox/hooks/api'; import GroupGridItem from './components/discover/group-grid-item'; import GroupListItem from './components/discover/group-list-item'; diff --git a/app/soapbox/features/groups/tags.tsx b/app/soapbox/features/groups/tags.tsx index 1484665e4..aa37a514b 100644 --- a/app/soapbox/features/groups/tags.tsx +++ b/app/soapbox/features/groups/tags.tsx @@ -3,8 +3,8 @@ import React from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { Virtuoso } from 'react-virtuoso'; +import { usePopularTags } from 'soapbox/api/hooks'; import { Column, Text } from 'soapbox/components/ui'; -import { usePopularTags } from 'soapbox/hooks/api'; import TagListItem from './components/discover/tag-list-item'; diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx index f09232b42..d87126c74 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/create-group-modal.tsx @@ -2,9 +2,9 @@ import { AxiosError } from 'axios'; import React, { useMemo, useState } from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; +import { useCreateGroup, useGroupValidation, type CreateGroupParams } from 'soapbox/api/hooks'; import { Modal, Stack } from 'soapbox/components/ui'; import { useDebounce } from 'soapbox/hooks'; -import { useCreateGroup, useGroupValidation, type CreateGroupParams } from 'soapbox/hooks/api'; import { type Group } from 'soapbox/schemas'; import toast from 'soapbox/toast'; diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/details-step.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/details-step.tsx index d5e59e575..02dbf3279 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/details-step.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/details-step.tsx @@ -1,12 +1,12 @@ import React from 'react'; import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; +import { CreateGroupParams, useGroupValidation } from 'soapbox/api/hooks'; import { Form, FormGroup, Input, Textarea } from 'soapbox/components/ui'; import AvatarPicker from 'soapbox/features/group/components/group-avatar-picker'; import HeaderPicker from 'soapbox/features/group/components/group-header-picker'; import GroupTagsField from 'soapbox/features/group/components/group-tags-field'; import { useAppSelector, useDebounce, useInstance } from 'soapbox/hooks'; -import { CreateGroupParams, useGroupValidation } from 'soapbox/hooks/api'; import { usePreview } from 'soapbox/hooks/forms'; import resizeImage from 'soapbox/utils/resize-image'; diff --git a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/privacy-step.tsx b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/privacy-step.tsx index 4e42d0b58..951b1ea67 100644 --- a/app/soapbox/features/ui/components/modals/manage-group-modal/steps/privacy-step.tsx +++ b/app/soapbox/features/ui/components/modals/manage-group-modal/steps/privacy-step.tsx @@ -1,9 +1,9 @@ import React from 'react'; import { FormattedMessage } from 'react-intl'; +import { type CreateGroupParams } from 'soapbox/api/hooks'; import List, { ListItem } from 'soapbox/components/list'; import { Form, FormGroup, Stack, Text } from 'soapbox/components/ui'; -import { type CreateGroupParams } from 'soapbox/hooks/api'; interface IPrivacyStep { params: CreateGroupParams diff --git a/app/soapbox/features/ui/components/panels/my-groups-panel.tsx b/app/soapbox/features/ui/components/panels/my-groups-panel.tsx index e6434b1dd..c732f5ae7 100644 --- a/app/soapbox/features/ui/components/panels/my-groups-panel.tsx +++ b/app/soapbox/features/ui/components/panels/my-groups-panel.tsx @@ -1,9 +1,9 @@ import React from 'react'; +import { useGroups } from 'soapbox/api/hooks'; import { Widget } from 'soapbox/components/ui'; import GroupListItem from 'soapbox/features/groups/components/discover/group-list-item'; import PlaceholderGroupSearch from 'soapbox/features/placeholder/components/placeholder-group-search'; -import { useGroups } from 'soapbox/hooks/api'; const MyGroupsPanel = () => { const { groups, isFetching, isFetched, isError } = useGroups(); diff --git a/app/soapbox/features/ui/components/panels/suggested-groups-panel.tsx b/app/soapbox/features/ui/components/panels/suggested-groups-panel.tsx index 395a53f9c..5ef131047 100644 --- a/app/soapbox/features/ui/components/panels/suggested-groups-panel.tsx +++ b/app/soapbox/features/ui/components/panels/suggested-groups-panel.tsx @@ -1,9 +1,9 @@ import React from 'react'; +import { useSuggestedGroups } from 'soapbox/api/hooks'; import { Widget } from 'soapbox/components/ui'; import GroupListItem from 'soapbox/features/groups/components/discover/group-list-item'; import PlaceholderGroupSearch from 'soapbox/features/placeholder/components/placeholder-group-search'; -import { useSuggestedGroups } from 'soapbox/hooks/api/useSuggestedGroups'; const SuggestedGroupsPanel = () => { const { groups, isFetching, isFetched, isError } = useSuggestedGroups(); diff --git a/app/soapbox/hooks/useGroupsPath.ts b/app/soapbox/hooks/useGroupsPath.ts index a4c1efa19..7a101e463 100644 --- a/app/soapbox/hooks/useGroupsPath.ts +++ b/app/soapbox/hooks/useGroupsPath.ts @@ -1,4 +1,5 @@ -import { useGroups } from './api'; +import { useGroups } from 'soapbox/api/hooks'; + import { useFeatures } from './useFeatures'; /** diff --git a/app/soapbox/pages/group-page.tsx b/app/soapbox/pages/group-page.tsx index 9e11c34a9..e2d6e5755 100644 --- a/app/soapbox/pages/group-page.tsx +++ b/app/soapbox/pages/group-page.tsx @@ -2,6 +2,7 @@ import React, { useMemo } from 'react'; import { FormattedMessage, defineMessages, useIntl } from 'react-intl'; import { useRouteMatch } from 'react-router-dom'; +import { useGroup, useGroupMembershipRequests } from 'soapbox/api/hooks'; import GroupLookupHoc from 'soapbox/components/hoc/group-lookup-hoc'; import { Column, Icon, Layout, Stack, Text } from 'soapbox/components/ui'; import GroupHeader from 'soapbox/features/group/components/group-header'; @@ -14,12 +15,11 @@ import { SuggestedGroupsPanel, } from 'soapbox/features/ui/util/async-components'; import { useFeatures, useOwnAccount } from 'soapbox/hooks'; -import { useGroup } from 'soapbox/hooks/api'; -import { useGroupMembershipRequests } from 'soapbox/hooks/api/groups/useGroupMembershipRequests'; -import { Group } from 'soapbox/schemas'; import { Tabs } from '../components/ui'; +import type { Group } from 'soapbox/schemas'; + const messages = defineMessages({ all: { id: 'group.tabs.all', defaultMessage: 'All' }, members: { id: 'group.tabs.members', defaultMessage: 'Members' }, From 238c30acf8434791b669507ce19fffd138b6a1e5 Mon Sep 17 00:00:00 2001 From: Chewbacca Date: Tue, 2 May 2023 13:25:32 -0400 Subject: [PATCH 2/2] Split out hooks from 'useGroups' --- app/soapbox/api/hooks/groups/useGroup.ts | 24 ++++++ .../groups/useGroupMembershipRequests.ts | 2 +- .../api/hooks/groups/useGroupRelationship.ts | 32 ++++++++ .../api/hooks/groups/useGroupRelationships.ts | 27 +++++++ .../api/hooks/groups/useGroupSearch.ts | 2 +- app/soapbox/api/hooks/groups/useGroups.ts | 73 ++----------------- .../api/hooks/groups/useGroupsFromTag.ts | 2 +- .../api/hooks/groups/usePopularGroups.ts | 2 +- .../api/hooks/groups/useSuggestedGroups.ts | 2 +- app/soapbox/api/hooks/index.ts | 5 +- .../features/ui/components/compose-button.tsx | 2 +- .../ui/components/floating-action-button.tsx | 2 +- .../ui/components/modals/compose-modal.tsx | 2 +- 13 files changed, 101 insertions(+), 76 deletions(-) create mode 100644 app/soapbox/api/hooks/groups/useGroup.ts create mode 100644 app/soapbox/api/hooks/groups/useGroupRelationship.ts create mode 100644 app/soapbox/api/hooks/groups/useGroupRelationships.ts diff --git a/app/soapbox/api/hooks/groups/useGroup.ts b/app/soapbox/api/hooks/groups/useGroup.ts new file mode 100644 index 000000000..b66c0fee7 --- /dev/null +++ b/app/soapbox/api/hooks/groups/useGroup.ts @@ -0,0 +1,24 @@ +import { Entities } from 'soapbox/entity-store/entities'; +import { useEntity } from 'soapbox/entity-store/hooks'; +import { useApi } from 'soapbox/hooks'; +import { type Group, groupSchema } from 'soapbox/schemas'; + +import { useGroupRelationship } from './useGroupRelationship'; + +function useGroup(groupId: string, refetch = true) { + const api = useApi(); + + const { entity: group, ...result } = useEntity( + [Entities.GROUPS, groupId], + () => api.get(`/api/v1/groups/${groupId}`), + { schema: groupSchema, refetch }, + ); + const { entity: relationship } = useGroupRelationship(groupId); + + return { + ...result, + group: group ? { ...group, relationship: relationship || null } : undefined, + }; +} + +export { useGroup }; \ No newline at end of file diff --git a/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts b/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts index 171510338..16ff924c7 100644 --- a/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts +++ b/app/soapbox/api/hooks/groups/useGroupMembershipRequests.ts @@ -4,7 +4,7 @@ import { useApi } from 'soapbox/hooks/useApi'; import { accountSchema } from 'soapbox/schemas'; import { GroupRoles } from 'soapbox/schemas/group-member'; -import { useGroupRelationship } from './useGroups'; +import { useGroupRelationship } from './useGroupRelationship'; import type { ExpandedEntitiesPath } from 'soapbox/entity-store/hooks/types'; diff --git a/app/soapbox/api/hooks/groups/useGroupRelationship.ts b/app/soapbox/api/hooks/groups/useGroupRelationship.ts new file mode 100644 index 000000000..6b24c463c --- /dev/null +++ b/app/soapbox/api/hooks/groups/useGroupRelationship.ts @@ -0,0 +1,32 @@ +import { useEffect } from 'react'; +import { z } from 'zod'; + +import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; +import { Entities } from 'soapbox/entity-store/entities'; +import { useEntity } from 'soapbox/entity-store/hooks'; +import { useApi, useAppDispatch } from 'soapbox/hooks'; +import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; + +function useGroupRelationship(groupId: string) { + const api = useApi(); + const dispatch = useAppDispatch(); + + const { entity: groupRelationship, ...result } = useEntity( + [Entities.GROUP_RELATIONSHIPS, groupId], + () => api.get(`/api/v1/groups/relationships?id[]=${groupId}`), + { schema: z.array(groupRelationshipSchema).transform(arr => arr[0]) }, + ); + + useEffect(() => { + if (groupRelationship?.id) { + dispatch(fetchGroupRelationshipsSuccess([groupRelationship])); + } + }, [groupRelationship?.id]); + + return { + entity: groupRelationship, + ...result, + }; +} + +export { useGroupRelationship }; \ No newline at end of file diff --git a/app/soapbox/api/hooks/groups/useGroupRelationships.ts b/app/soapbox/api/hooks/groups/useGroupRelationships.ts new file mode 100644 index 000000000..c4106adda --- /dev/null +++ b/app/soapbox/api/hooks/groups/useGroupRelationships.ts @@ -0,0 +1,27 @@ +import { Entities } from 'soapbox/entity-store/entities'; +import { useEntities } from 'soapbox/entity-store/hooks'; +import { useApi } from 'soapbox/hooks'; +import { type GroupRelationship, groupRelationshipSchema } from 'soapbox/schemas'; + +function useGroupRelationships(groupIds: string[]) { + const api = useApi(); + const q = groupIds.map(id => `id[]=${id}`).join('&'); + + const { entities, ...result } = useEntities( + [Entities.GROUP_RELATIONSHIPS, ...groupIds], + () => api.get(`/api/v1/groups/relationships?${q}`), + { schema: groupRelationshipSchema, enabled: groupIds.length > 0 }, + ); + + const relationships = entities.reduce>((map, relationship) => { + map[relationship.id] = relationship; + return map; + }, {}); + + return { + ...result, + relationships, + }; +} + +export { useGroupRelationships }; \ No newline at end of file diff --git a/app/soapbox/api/hooks/groups/useGroupSearch.ts b/app/soapbox/api/hooks/groups/useGroupSearch.ts index 508310911..d1d8acf9c 100644 --- a/app/soapbox/api/hooks/groups/useGroupSearch.ts +++ b/app/soapbox/api/hooks/groups/useGroupSearch.ts @@ -3,7 +3,7 @@ import { useEntities } from 'soapbox/entity-store/hooks'; import { useApi, useFeatures } from 'soapbox/hooks'; import { groupSchema } from 'soapbox/schemas'; -import { useGroupRelationships } from './useGroups'; +import { useGroupRelationships } from './useGroupRelationships'; import type { Group } from 'soapbox/schemas'; diff --git a/app/soapbox/api/hooks/groups/useGroups.ts b/app/soapbox/api/hooks/groups/useGroups.ts index 42904c142..13ca45713 100644 --- a/app/soapbox/api/hooks/groups/useGroups.ts +++ b/app/soapbox/api/hooks/groups/useGroups.ts @@ -1,13 +1,10 @@ -import { useEffect } from 'react'; -import { z } from 'zod'; - -import { fetchGroupRelationshipsSuccess } from 'soapbox/actions/groups'; import { Entities } from 'soapbox/entity-store/entities'; -import { useEntities, useEntity } from 'soapbox/entity-store/hooks'; -import { useApi, useAppDispatch } from 'soapbox/hooks'; +import { useEntities } from 'soapbox/entity-store/hooks'; +import { useApi } from 'soapbox/hooks'; import { useFeatures } from 'soapbox/hooks/useFeatures'; -import { groupSchema, Group } from 'soapbox/schemas/group'; -import { groupRelationshipSchema, GroupRelationship } from 'soapbox/schemas/group-relationship'; +import { groupSchema, type Group } from 'soapbox/schemas/group'; + +import { useGroupRelationships } from './useGroupRelationships'; function useGroups(q: string = '') { const api = useApi(); @@ -31,62 +28,4 @@ function useGroups(q: string = '') { }; } -function useGroup(groupId: string, refetch = true) { - const api = useApi(); - - const { entity: group, ...result } = useEntity( - [Entities.GROUPS, groupId], - () => api.get(`/api/v1/groups/${groupId}`), - { schema: groupSchema, refetch }, - ); - const { entity: relationship } = useGroupRelationship(groupId); - - return { - ...result, - group: group ? { ...group, relationship: relationship || null } : undefined, - }; -} - -function useGroupRelationship(groupId: string) { - const api = useApi(); - const dispatch = useAppDispatch(); - - const { entity: groupRelationship, ...result } = useEntity( - [Entities.GROUP_RELATIONSHIPS, groupId], - () => api.get(`/api/v1/groups/relationships?id[]=${groupId}`), - { schema: z.array(groupRelationshipSchema).transform(arr => arr[0]) }, - ); - - useEffect(() => { - if (groupRelationship?.id) { - dispatch(fetchGroupRelationshipsSuccess([groupRelationship])); - } - }, [groupRelationship?.id]); - - return { - entity: groupRelationship, - ...result, - }; -} - -function useGroupRelationships(groupIds: string[]) { - const api = useApi(); - const q = groupIds.map(id => `id[]=${id}`).join('&'); - const { entities, ...result } = useEntities( - [Entities.GROUP_RELATIONSHIPS, ...groupIds], - () => api.get(`/api/v1/groups/relationships?${q}`), - { schema: groupRelationshipSchema, enabled: groupIds.length > 0 }, - ); - - const relationships = entities.reduce>((map, relationship) => { - map[relationship.id] = relationship; - return map; - }, {}); - - return { - ...result, - relationships, - }; -} - -export { useGroup, useGroups, useGroupRelationship, useGroupRelationships }; +export { useGroups }; diff --git a/app/soapbox/api/hooks/groups/useGroupsFromTag.ts b/app/soapbox/api/hooks/groups/useGroupsFromTag.ts index f579c719e..2c7e5a94f 100644 --- a/app/soapbox/api/hooks/groups/useGroupsFromTag.ts +++ b/app/soapbox/api/hooks/groups/useGroupsFromTag.ts @@ -3,7 +3,7 @@ import { useEntities } from 'soapbox/entity-store/hooks'; import { useApi, useFeatures } from 'soapbox/hooks'; import { groupSchema } from 'soapbox/schemas'; -import { useGroupRelationships } from './useGroups'; +import { useGroupRelationships } from './useGroupRelationships'; import type { Group } from 'soapbox/schemas'; diff --git a/app/soapbox/api/hooks/groups/usePopularGroups.ts b/app/soapbox/api/hooks/groups/usePopularGroups.ts index ead72a79b..b5959a335 100644 --- a/app/soapbox/api/hooks/groups/usePopularGroups.ts +++ b/app/soapbox/api/hooks/groups/usePopularGroups.ts @@ -5,7 +5,7 @@ import { Group, groupSchema } from 'soapbox/schemas'; import { useApi } from '../../../hooks/useApi'; import { useFeatures } from '../../../hooks/useFeatures'; -import { useGroupRelationships } from './useGroups'; +import { useGroupRelationships } from './useGroupRelationships'; function usePopularGroups() { const api = useApi(); diff --git a/app/soapbox/api/hooks/groups/useSuggestedGroups.ts b/app/soapbox/api/hooks/groups/useSuggestedGroups.ts index 78b1ddb79..be9b5a78e 100644 --- a/app/soapbox/api/hooks/groups/useSuggestedGroups.ts +++ b/app/soapbox/api/hooks/groups/useSuggestedGroups.ts @@ -3,7 +3,7 @@ import { useEntities } from 'soapbox/entity-store/hooks'; import { useApi, useFeatures } from 'soapbox/hooks'; import { type Group, groupSchema } from 'soapbox/schemas'; -import { useGroupRelationships } from './useGroups'; +import { useGroupRelationships } from './useGroupRelationships'; function useSuggestedGroups() { const api = useApi(); diff --git a/app/soapbox/api/hooks/index.ts b/app/soapbox/api/hooks/index.ts index eba4f0d84..ade03f799 100644 --- a/app/soapbox/api/hooks/index.ts +++ b/app/soapbox/api/hooks/index.ts @@ -12,15 +12,18 @@ export { useCancelMembershipRequest } from './groups/useCancelMembershipRequest' export { useCreateGroup, type CreateGroupParams } from './groups/useCreateGroup'; export { useDeleteGroup } from './groups/useDeleteGroup'; export { useDemoteGroupMember } from './groups/useDemoteGroupMember'; -export { useGroup, useGroups } from './groups/useGroups'; +export { useGroup } from './groups/useGroup'; export { useGroupLookup } from './groups/useGroupLookup'; export { useGroupMedia } from './groups/useGroupMedia'; export { useGroupMembers } from './groups/useGroupMembers'; export { useGroupMembershipRequests } from './groups/useGroupMembershipRequests'; +export { useGroupRelationship } from './groups/useGroupRelationship'; +export { useGroupRelationships } from './groups/useGroupRelationships'; export { useGroupSearch } from './groups/useGroupSearch'; export { useGroupTag } from './groups/useGroupTag'; export { useGroupTags } from './groups/useGroupTags'; export { useGroupValidation } from './groups/useGroupValidation'; +export { useGroups } from './groups/useGroups'; export { useGroupsFromTag } from './groups/useGroupsFromTag'; export { useJoinGroup } from './groups/useJoinGroup'; export { useLeaveGroup } from './groups/useLeaveGroup'; diff --git a/app/soapbox/features/ui/components/compose-button.tsx b/app/soapbox/features/ui/components/compose-button.tsx index a2944f699..b862d83fb 100644 --- a/app/soapbox/features/ui/components/compose-button.tsx +++ b/app/soapbox/features/ui/components/compose-button.tsx @@ -4,9 +4,9 @@ import { useLocation, useRouteMatch } from 'react-router-dom'; import { groupComposeModal } from 'soapbox/actions/compose'; import { openModal } from 'soapbox/actions/modals'; +import { useGroupLookup } from 'soapbox/api/hooks'; import { Avatar, Button, HStack } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { useGroupLookup } from 'soapbox/hooks/api/groups/useGroupLookup'; const ComposeButton = () => { const location = useLocation(); diff --git a/app/soapbox/features/ui/components/floating-action-button.tsx b/app/soapbox/features/ui/components/floating-action-button.tsx index 0e972ef40..ea6bd64ee 100644 --- a/app/soapbox/features/ui/components/floating-action-button.tsx +++ b/app/soapbox/features/ui/components/floating-action-button.tsx @@ -5,9 +5,9 @@ import { useLocation, useRouteMatch } from 'react-router-dom'; import { groupComposeModal } from 'soapbox/actions/compose'; import { openModal } from 'soapbox/actions/modals'; +import { useGroupLookup } from 'soapbox/api/hooks'; import { Avatar, HStack, Icon } from 'soapbox/components/ui'; import { useAppDispatch } from 'soapbox/hooks'; -import { useGroupLookup } from 'soapbox/hooks/api/groups/useGroupLookup'; const messages = defineMessages({ publish: { id: 'compose_form.publish', defaultMessage: 'Publish' }, diff --git a/app/soapbox/features/ui/components/modals/compose-modal.tsx b/app/soapbox/features/ui/components/modals/compose-modal.tsx index 358a6d648..2bbdb4a2e 100644 --- a/app/soapbox/features/ui/components/modals/compose-modal.tsx +++ b/app/soapbox/features/ui/components/modals/compose-modal.tsx @@ -4,10 +4,10 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl'; import { cancelReplyCompose, setGroupTimelineVisible, uploadCompose } from 'soapbox/actions/compose'; import { openModal, closeModal } from 'soapbox/actions/modals'; +import { useGroup } from 'soapbox/api/hooks'; import { checkComposeContent } from 'soapbox/components/modal-root'; import { HStack, Modal, Text, Toggle } from 'soapbox/components/ui'; import { useAppDispatch, useAppSelector, useCompose, useDraggedFiles } from 'soapbox/hooks'; -import { useGroup } from 'soapbox/hooks/api'; import ComposeForm from '../../../compose/components/compose-form';