From 181bf43bda9a82a5a59a177cf412c84b0fdc30e2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 25 May 2024 20:55:49 -0500 Subject: [PATCH] Remove useGroupsPath hook --- src/components/sidebar-menu.tsx | 5 +- src/components/sidebar-navigation.tsx | 5 +- src/components/thumb-navigation.tsx | 5 +- src/features/group/manage-group.tsx | 5 +- src/hooks/index.ts | 1 - src/hooks/useGroupsPath.test.ts | 80 --------------------------- src/hooks/useGroupsPath.ts | 23 -------- 7 files changed, 8 insertions(+), 116 deletions(-) delete mode 100644 src/hooks/useGroupsPath.test.ts delete mode 100644 src/hooks/useGroupsPath.ts diff --git a/src/components/sidebar-menu.tsx b/src/components/sidebar-menu.tsx index 847e8d79b..0b7993854 100644 --- a/src/components/sidebar-menu.tsx +++ b/src/components/sidebar-menu.tsx @@ -11,7 +11,7 @@ import { useAccount } from 'soapbox/api/hooks'; import Account from 'soapbox/components/account'; import { Stack, Divider, HStack, Icon, IconButton, Text } from 'soapbox/components/ui'; import ProfileStats from 'soapbox/features/ui/components/profile-stats'; -import { useAppDispatch, useAppSelector, useGroupsPath, useFeatures, useInstance } from 'soapbox/hooks'; +import { useAppDispatch, useAppSelector, useFeatures, useInstance } from 'soapbox/hooks'; import { makeGetOtherAccounts } from 'soapbox/selectors'; import type { List as ImmutableList } from 'immutable'; @@ -88,7 +88,6 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { const sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen); const settings = useAppSelector((state) => getSettings(state)); const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count()); - const groupsPath = useGroupsPath(); const instance = useInstance(); const closeButtonRef = React.useRef(null); @@ -210,7 +209,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => { {features.groups && ( { const features = useFeatures(); const { isDeveloper } = useSettings(); const { account } = useOwnAccount(); - const groupsPath = useGroupsPath(); const notificationCount = useAppSelector((state) => state.notifications.unread); const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count()); @@ -142,7 +141,7 @@ const SidebarNavigation = () => { {features.groups && ( } diff --git a/src/components/thumb-navigation.tsx b/src/components/thumb-navigation.tsx index 4c13b010e..08d792e22 100644 --- a/src/components/thumb-navigation.tsx +++ b/src/components/thumb-navigation.tsx @@ -3,12 +3,11 @@ import { FormattedMessage } from 'react-intl'; import ThumbNavigationLink from 'soapbox/components/thumb-navigation-link'; import { useStatContext } from 'soapbox/contexts/stat-context'; -import { useAppSelector, useFeatures, useGroupsPath, useOwnAccount } from 'soapbox/hooks'; +import { useAppSelector, useFeatures, useOwnAccount } from 'soapbox/hooks'; const ThumbNavigation: React.FC = (): JSX.Element => { const { account } = useOwnAccount(); const features = useFeatures(); - const groupsPath = useGroupsPath(); const { unreadChatsCount } = useStatContext(); @@ -60,7 +59,7 @@ const ThumbNavigation: React.FC = (): JSX.Element => { src={require('@tabler/icons/outline/circles.svg')} activeSrc={require('@tabler/icons/filled/circles.svg')} text={} - to={groupsPath} + to='/groups' exact /> )} diff --git a/src/features/group/manage-group.tsx b/src/features/group/manage-group.tsx index 1fa02f174..bf857996a 100644 --- a/src/features/group/manage-group.tsx +++ b/src/features/group/manage-group.tsx @@ -6,7 +6,7 @@ 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 { useAppDispatch, useBackend } from 'soapbox/hooks'; import { GroupRoles } from 'soapbox/schemas/group-member'; import toast from 'soapbox/toast'; import { TRUTHSOCIAL } from 'soapbox/utils/features'; @@ -38,7 +38,6 @@ const ManageGroup: React.FC = ({ params }) => { const backend = useBackend(); const dispatch = useAppDispatch(); - const groupsPath = useGroupsPath(); const history = useHistory(); const intl = useIntl(); @@ -70,7 +69,7 @@ const ManageGroup: React.FC = ({ params }) => { deleteGroup.mutate(group.id, { onSuccess() { toast.success(intl.formatMessage(messages.deleteSuccess)); - history.push(groupsPath); + history.push('/groups'); }, }); }, diff --git a/src/hooks/index.ts b/src/hooks/index.ts index 1da5fb9e4..8d3b7a510 100644 --- a/src/hooks/index.ts +++ b/src/hooks/index.ts @@ -7,7 +7,6 @@ export { useCompose } from './useCompose'; export { useDebounce } from './useDebounce'; export { useDraggedFiles } from './useDraggedFiles'; export { useGetState } from './useGetState'; -export { useGroupsPath } from './useGroupsPath'; export { useDimensions } from './useDimensions'; export { useFeatures } from './useFeatures'; export { useInstance } from './useInstance'; diff --git a/src/hooks/useGroupsPath.test.ts b/src/hooks/useGroupsPath.test.ts deleted file mode 100644 index 72af53731..000000000 --- a/src/hooks/useGroupsPath.test.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { __stub } from 'soapbox/api'; -import { buildAccount, buildGroup, buildGroupRelationship } from 'soapbox/jest/factory'; -import { renderHook, waitFor } from 'soapbox/jest/test-helpers'; -import { instanceSchema } from 'soapbox/schemas'; - -import { useGroupsPath } from './useGroupsPath'; - -describe('useGroupsPath()', () => { - test('without the groupsDiscovery feature', () => { - const store = { - instance: instanceSchema.parse({ - version: '2.7.2 (compatible; Pleroma 2.3.0)', - }), - }; - - const { result } = renderHook(useGroupsPath, undefined, store); - - expect(result.current).toEqual('/groups'); - }); - - describe('with the "groupsDiscovery" feature', () => { - let store: any; - - beforeEach(() => { - const userId = '1'; - store = { - instance: instanceSchema.parse({ - version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)', - }), - me: userId, - accounts: { - [userId]: buildAccount({ - id: userId, - acct: 'justin-username', - display_name: 'Justin L', - avatar: 'test.jpg', - source: { - chats_onboarded: false, - }, - }), - }, - }; - }); - - describe('when the user has no groups', () => { - test('should default to the discovery page', () => { - const { result } = renderHook(useGroupsPath, undefined, store); - - expect(result.current).toEqual('/groups/discover'); - }); - }); - - describe('when the user has groups', () => { - beforeEach(() => { - __stub((mock) => { - mock.onGet('/api/v1/groups').reply(200, [ - buildGroup({ - display_name: 'Group', - id: '1', - }), - ]); - - mock.onGet('/api/v1/groups/relationships?id[]=1').reply(200, [ - buildGroupRelationship({ - id: '1', - }), - ]); - }); - }); - - test('should default to the "My Groups" page', async () => { - const { result } = renderHook(useGroupsPath, undefined, store); - - await waitFor(() => { - expect(result.current).toEqual('/groups'); - }); - }); - }); - }); -}); diff --git a/src/hooks/useGroupsPath.ts b/src/hooks/useGroupsPath.ts deleted file mode 100644 index 71aa3c8da..000000000 --- a/src/hooks/useGroupsPath.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { useGroups } from 'soapbox/api/hooks/groups/useGroups'; - -import { useFeatures } from './useFeatures'; - -/** - * Determine the correct URL to use for /groups. - * If the user does not have any Groups, let's default to the discovery tab. - * Otherwise, let's default to My Groups. - * - * @returns String (as link) - */ -const useGroupsPath = () => { - const features = useFeatures(); - const { groups } = useGroups(); - - if (!features.groupsDiscovery) { - return '/groups'; - } - - return groups.length > 0 ? '/groups' : '/groups/discover'; -}; - -export { useGroupsPath }; \ No newline at end of file