Merge branch 'rm-groups-path' into 'main'
Remove useGroupsPath hook Closes #1667 See merge request soapbox-pub/soapbox!3038
This commit is contained in:
commit
28c48cd476
|
@ -11,7 +11,7 @@ import { useAccount } from 'soapbox/api/hooks';
|
||||||
import Account from 'soapbox/components/account';
|
import Account from 'soapbox/components/account';
|
||||||
import { Stack, Divider, HStack, Icon, IconButton, Text } from 'soapbox/components/ui';
|
import { Stack, Divider, HStack, Icon, IconButton, Text } from 'soapbox/components/ui';
|
||||||
import ProfileStats from 'soapbox/features/ui/components/profile-stats';
|
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 { makeGetOtherAccounts } from 'soapbox/selectors';
|
||||||
|
|
||||||
import type { List as ImmutableList } from 'immutable';
|
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 sidebarOpen = useAppSelector((state) => state.sidebar.sidebarOpen);
|
||||||
const settings = useAppSelector((state) => getSettings(state));
|
const settings = useAppSelector((state) => getSettings(state));
|
||||||
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
||||||
const groupsPath = useGroupsPath();
|
|
||||||
const instance = useInstance();
|
const instance = useInstance();
|
||||||
|
|
||||||
const closeButtonRef = React.useRef(null);
|
const closeButtonRef = React.useRef(null);
|
||||||
|
@ -210,7 +209,7 @@ const SidebarMenu: React.FC = (): JSX.Element | null => {
|
||||||
|
|
||||||
{features.groups && (
|
{features.groups && (
|
||||||
<SidebarLink
|
<SidebarLink
|
||||||
to={groupsPath}
|
to='/groups'
|
||||||
icon={require('@tabler/icons/outline/circles.svg')}
|
icon={require('@tabler/icons/outline/circles.svg')}
|
||||||
text={intl.formatMessage(messages.groups)}
|
text={intl.formatMessage(messages.groups)}
|
||||||
onClick={onClose}
|
onClick={onClose}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { defineMessages, FormattedMessage, useIntl } from 'react-intl';
|
||||||
import { Stack } from 'soapbox/components/ui';
|
import { Stack } from 'soapbox/components/ui';
|
||||||
import { useStatContext } from 'soapbox/contexts/stat-context';
|
import { useStatContext } from 'soapbox/contexts/stat-context';
|
||||||
import ComposeButton from 'soapbox/features/ui/components/compose-button';
|
import ComposeButton from 'soapbox/features/ui/components/compose-button';
|
||||||
import { useAppSelector, useGroupsPath, useFeatures, useOwnAccount, useSettings, useInstance } from 'soapbox/hooks';
|
import { useAppSelector, useFeatures, useOwnAccount, useSettings, useInstance } from 'soapbox/hooks';
|
||||||
|
|
||||||
import DropdownMenu, { Menu } from './dropdown-menu';
|
import DropdownMenu, { Menu } from './dropdown-menu';
|
||||||
import SidebarNavigationLink from './sidebar-navigation-link';
|
import SidebarNavigationLink from './sidebar-navigation-link';
|
||||||
|
@ -26,7 +26,6 @@ const SidebarNavigation = () => {
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const { isDeveloper } = useSettings();
|
const { isDeveloper } = useSettings();
|
||||||
const { account } = useOwnAccount();
|
const { account } = useOwnAccount();
|
||||||
const groupsPath = useGroupsPath();
|
|
||||||
|
|
||||||
const notificationCount = useAppSelector((state) => state.notifications.unread);
|
const notificationCount = useAppSelector((state) => state.notifications.unread);
|
||||||
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
const followRequestsCount = useAppSelector((state) => state.user_lists.follow_requests.items.count());
|
||||||
|
@ -142,7 +141,7 @@ const SidebarNavigation = () => {
|
||||||
|
|
||||||
{features.groups && (
|
{features.groups && (
|
||||||
<SidebarNavigationLink
|
<SidebarNavigationLink
|
||||||
to={groupsPath}
|
to='/groups'
|
||||||
icon={require('@tabler/icons/outline/circles.svg')}
|
icon={require('@tabler/icons/outline/circles.svg')}
|
||||||
activeIcon={require('@tabler/icons/filled/circles.svg')}
|
activeIcon={require('@tabler/icons/filled/circles.svg')}
|
||||||
text={<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />}
|
text={<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />}
|
||||||
|
|
|
@ -3,12 +3,11 @@ import { FormattedMessage } from 'react-intl';
|
||||||
|
|
||||||
import ThumbNavigationLink from 'soapbox/components/thumb-navigation-link';
|
import ThumbNavigationLink from 'soapbox/components/thumb-navigation-link';
|
||||||
import { useStatContext } from 'soapbox/contexts/stat-context';
|
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 ThumbNavigation: React.FC = (): JSX.Element => {
|
||||||
const { account } = useOwnAccount();
|
const { account } = useOwnAccount();
|
||||||
const features = useFeatures();
|
const features = useFeatures();
|
||||||
const groupsPath = useGroupsPath();
|
|
||||||
|
|
||||||
const { unreadChatsCount } = useStatContext();
|
const { unreadChatsCount } = useStatContext();
|
||||||
|
|
||||||
|
@ -60,7 +59,7 @@ const ThumbNavigation: React.FC = (): JSX.Element => {
|
||||||
src={require('@tabler/icons/outline/circles.svg')}
|
src={require('@tabler/icons/outline/circles.svg')}
|
||||||
activeSrc={require('@tabler/icons/filled/circles.svg')}
|
activeSrc={require('@tabler/icons/filled/circles.svg')}
|
||||||
text={<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />}
|
text={<FormattedMessage id='tabs_bar.groups' defaultMessage='Groups' />}
|
||||||
to={groupsPath}
|
to='/groups'
|
||||||
exact
|
exact
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { openModal } from 'soapbox/actions/modals';
|
||||||
import { useDeleteGroup, useGroup } from 'soapbox/api/hooks';
|
import { useDeleteGroup, useGroup } from 'soapbox/api/hooks';
|
||||||
import List, { ListItem } from 'soapbox/components/list';
|
import List, { ListItem } from 'soapbox/components/list';
|
||||||
import { CardBody, CardHeader, CardTitle, Column, Spinner, Text } from 'soapbox/components/ui';
|
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 { GroupRoles } from 'soapbox/schemas/group-member';
|
||||||
import toast from 'soapbox/toast';
|
import toast from 'soapbox/toast';
|
||||||
import { TRUTHSOCIAL } from 'soapbox/utils/features';
|
import { TRUTHSOCIAL } from 'soapbox/utils/features';
|
||||||
|
@ -38,7 +38,6 @@ const ManageGroup: React.FC<IManageGroup> = ({ params }) => {
|
||||||
|
|
||||||
const backend = useBackend();
|
const backend = useBackend();
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const groupsPath = useGroupsPath();
|
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const intl = useIntl();
|
const intl = useIntl();
|
||||||
|
|
||||||
|
@ -70,7 +69,7 @@ const ManageGroup: React.FC<IManageGroup> = ({ params }) => {
|
||||||
deleteGroup.mutate(group.id, {
|
deleteGroup.mutate(group.id, {
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
toast.success(intl.formatMessage(messages.deleteSuccess));
|
toast.success(intl.formatMessage(messages.deleteSuccess));
|
||||||
history.push(groupsPath);
|
history.push('/groups');
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
|
@ -7,7 +7,6 @@ export { useCompose } from './useCompose';
|
||||||
export { useDebounce } from './useDebounce';
|
export { useDebounce } from './useDebounce';
|
||||||
export { useDraggedFiles } from './useDraggedFiles';
|
export { useDraggedFiles } from './useDraggedFiles';
|
||||||
export { useGetState } from './useGetState';
|
export { useGetState } from './useGetState';
|
||||||
export { useGroupsPath } from './useGroupsPath';
|
|
||||||
export { useDimensions } from './useDimensions';
|
export { useDimensions } from './useDimensions';
|
||||||
export { useFeatures } from './useFeatures';
|
export { useFeatures } from './useFeatures';
|
||||||
export { useInstance } from './useInstance';
|
export { useInstance } from './useInstance';
|
||||||
|
|
|
@ -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');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -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 };
|
|
Loading…
Reference in New Issue