Remove Truth Social-specific features
Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
@ -1,42 +0,0 @@
|
||||
import { __stub } from 'soapbox/api';
|
||||
import { buildGroup } from 'soapbox/jest/factory';
|
||||
import { renderHook, rootState, waitFor } from 'soapbox/jest/test-helpers';
|
||||
|
||||
import { useGroupLookup } from './useGroupLookup';
|
||||
|
||||
const group = buildGroup({ id: '1', slug: 'soapbox' });
|
||||
const state = rootState.setIn(['instance', 'version'], '3.4.1 (compatible; TruthSocial 1.0.0)');
|
||||
|
||||
describe('useGroupLookup hook', () => {
|
||||
describe('with a successful request', () => {
|
||||
beforeEach(() => {
|
||||
__stub((mock) => {
|
||||
mock.onGet(`/api/v1/groups/lookup?name=${group.slug}`).reply(200, group);
|
||||
});
|
||||
});
|
||||
|
||||
it('is successful', async () => {
|
||||
const { result } = renderHook(() => useGroupLookup(group.slug), undefined, state);
|
||||
|
||||
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||
|
||||
expect(result.current.entity?.id).toBe(group.id);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with an unsuccessful query', () => {
|
||||
beforeEach(() => {
|
||||
__stub((mock) => {
|
||||
mock.onGet(`/api/v1/groups/lookup?name=${group.slug}`).networkError();
|
||||
});
|
||||
});
|
||||
|
||||
it('is has error state', async() => {
|
||||
const { result } = renderHook(() => useGroupLookup(group.slug), undefined, state);
|
||||
|
||||
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||
|
||||
expect(result.current.entity).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,39 +0,0 @@
|
||||
import { useEffect } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityLookup } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { useFeatures } from 'soapbox/hooks/useFeatures';
|
||||
import { groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useGroupRelationship } from './useGroupRelationship';
|
||||
|
||||
function useGroupLookup(slug: string) {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
const history = useHistory();
|
||||
|
||||
const { entity: group, isUnauthorized, ...result } = useEntityLookup(
|
||||
Entities.GROUPS,
|
||||
(group) => group.slug.toLowerCase() === slug.toLowerCase(),
|
||||
() => api.get(`/api/v1/groups/lookup?name=${slug}`),
|
||||
{ schema: groupSchema, enabled: features.groups && !!slug },
|
||||
);
|
||||
|
||||
const { groupRelationship: relationship } = useGroupRelationship(group?.id);
|
||||
|
||||
useEffect(() => {
|
||||
if (isUnauthorized) {
|
||||
history.push('/login');
|
||||
}
|
||||
}, [isUnauthorized]);
|
||||
|
||||
return {
|
||||
...result,
|
||||
isUnauthorized,
|
||||
entity: group ? { ...group, relationship: relationship || null } : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupLookup };
|
||||
@ -1,25 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useFeatures } from 'soapbox/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import type { Group } from 'soapbox/schemas';
|
||||
|
||||
function useGroupMutes() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUP_MUTES],
|
||||
() => api.get('/api/v1/groups/mutes'),
|
||||
{ schema: groupSchema, enabled: features.groupsMuting },
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
mutes: entities,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupMutes };
|
||||
@ -1,40 +0,0 @@
|
||||
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 { useGroupRelationships } from './useGroupRelationships';
|
||||
|
||||
import type { Group } from 'soapbox/schemas';
|
||||
|
||||
function useGroupSearch(search: string) {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'discover', 'search', search],
|
||||
() => api.get('/api/v1/groups/search', {
|
||||
params: {
|
||||
q: search,
|
||||
},
|
||||
}),
|
||||
{ enabled: features.groupsDiscovery && !!search, schema: groupSchema },
|
||||
);
|
||||
|
||||
const { relationships } = useGroupRelationships(
|
||||
['discover', 'search', search],
|
||||
entities.map(entity => entity.id),
|
||||
);
|
||||
|
||||
const groups = entities.map((group) => ({
|
||||
...group,
|
||||
relationship: relationships[group.id] || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
...result,
|
||||
groups,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupSearch };
|
||||
@ -1,21 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { type GroupTag, groupTagSchema } from 'soapbox/schemas';
|
||||
|
||||
function useGroupTag(tagId: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entity: tag, ...result } = useEntity<GroupTag>(
|
||||
[Entities.GROUP_TAGS, tagId],
|
||||
() => api.get(`/api/v1/tags/${tagId }`),
|
||||
{ schema: groupTagSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
tag,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupTag };
|
||||
@ -1,23 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { groupTagSchema } from 'soapbox/schemas';
|
||||
|
||||
import type { GroupTag } from 'soapbox/schemas';
|
||||
|
||||
function useGroupTags(groupId: string) {
|
||||
const api = useApi();
|
||||
|
||||
const { entities, ...result } = useEntities<GroupTag>(
|
||||
[Entities.GROUP_TAGS, groupId],
|
||||
() => api.get(`/api/v1/truth/trends/groups/${groupId}/tags`),
|
||||
{ schema: groupTagSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
tags: entities,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupTags };
|
||||
@ -1,49 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks/useApi';
|
||||
import { useFeatures } from 'soapbox/hooks/useFeatures';
|
||||
|
||||
type Validation = {
|
||||
error: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
const ValidationKeys = {
|
||||
validation: (name: string) => ['group', 'validation', name] as const,
|
||||
};
|
||||
|
||||
function useGroupValidation(name: string = '') {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const getValidation = async() => {
|
||||
const { data } = await api.get<Validation>('/api/v1/groups/validate', {
|
||||
params: { name },
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error.response.status === 422) {
|
||||
return { data: error.response.data };
|
||||
}
|
||||
|
||||
throw error;
|
||||
});
|
||||
|
||||
return data;
|
||||
};
|
||||
|
||||
const queryInfo = useQuery<Validation>({
|
||||
queryKey: ValidationKeys.validation(name),
|
||||
queryFn: getValidation,
|
||||
enabled: features.groupsValidation && !!name,
|
||||
});
|
||||
|
||||
return {
|
||||
...queryInfo,
|
||||
data: {
|
||||
...queryInfo.data,
|
||||
isValid: !queryInfo.data?.error,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupValidation };
|
||||
@ -6,17 +6,17 @@ import { groupSchema, type Group } from 'soapbox/schemas/group';
|
||||
|
||||
import { useGroupRelationships } from './useGroupRelationships';
|
||||
|
||||
function useGroups(q: string = '') {
|
||||
function useGroups() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'search', q],
|
||||
() => api.get('/api/v1/groups', { params: { q } }),
|
||||
[Entities.GROUPS, 'search', ''],
|
||||
() => api.get('/api/v1/groups'),
|
||||
{ enabled: features.groups, schema: groupSchema },
|
||||
);
|
||||
const { relationships } = useGroupRelationships(
|
||||
['search', q],
|
||||
['search', ''],
|
||||
entities.map(entity => entity.id),
|
||||
);
|
||||
|
||||
|
||||
@ -1,38 +0,0 @@
|
||||
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 { useGroupRelationships } from './useGroupRelationships';
|
||||
|
||||
import type { Group } from 'soapbox/schemas';
|
||||
|
||||
function useGroupsFromTag(tagId: string) {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'tags', tagId],
|
||||
() => api.get(`/api/v1/tags/${tagId}/groups`),
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
},
|
||||
);
|
||||
const { relationships } = useGroupRelationships(
|
||||
['tags', tagId],
|
||||
entities.map(entity => entity.id),
|
||||
);
|
||||
|
||||
const groups = entities.map((group) => ({
|
||||
...group,
|
||||
relationship: relationships[group.id] || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
...result,
|
||||
groups,
|
||||
};
|
||||
}
|
||||
|
||||
export { useGroupsFromTag };
|
||||
@ -1,18 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { type Group, groupRelationshipSchema } from 'soapbox/schemas';
|
||||
|
||||
function useMuteGroup(group?: Group) {
|
||||
const { createEntity, isSubmitting } = useEntityActions(
|
||||
[Entities.GROUP_RELATIONSHIPS, group?.id as string],
|
||||
{ post: `/api/v1/groups/${group?.id}/mute` },
|
||||
{ schema: groupRelationshipSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
mutate: createEntity,
|
||||
isSubmitting,
|
||||
};
|
||||
}
|
||||
|
||||
export { useMuteGroup };
|
||||
@ -1,64 +0,0 @@
|
||||
import { __stub } from 'soapbox/api';
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { buildAccount, buildGroup } from 'soapbox/jest/factory';
|
||||
import { renderHook, waitFor } from 'soapbox/jest/test-helpers';
|
||||
import { instanceSchema } from 'soapbox/schemas';
|
||||
|
||||
import { usePendingGroups } from './usePendingGroups';
|
||||
|
||||
const id = '1';
|
||||
const group = buildGroup({ id, display_name: 'soapbox' });
|
||||
const store = {
|
||||
instance: instanceSchema.parse({
|
||||
version: '3.4.1 (compatible; TruthSocial 1.0.0+unreleased)',
|
||||
}),
|
||||
me: '1',
|
||||
entities: {
|
||||
[Entities.ACCOUNTS]: {
|
||||
store: {
|
||||
[id]: buildAccount({
|
||||
id,
|
||||
acct: 'tiger',
|
||||
display_name: 'Tiger',
|
||||
avatar: 'test.jpg',
|
||||
verified: true,
|
||||
}),
|
||||
},
|
||||
lists: {},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
describe('usePendingGroups hook', () => {
|
||||
describe('with a successful request', () => {
|
||||
beforeEach(() => {
|
||||
__stub((mock) => {
|
||||
mock.onGet('/api/v1/groups').reply(200, [group]);
|
||||
});
|
||||
});
|
||||
|
||||
it('is successful', async () => {
|
||||
const { result } = renderHook(usePendingGroups, undefined, store);
|
||||
|
||||
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||
|
||||
expect(result.current.groups).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('with an unsuccessful query', () => {
|
||||
beforeEach(() => {
|
||||
__stub((mock) => {
|
||||
mock.onGet('/api/v1/groups').networkError();
|
||||
});
|
||||
});
|
||||
|
||||
it('is has error state', async() => {
|
||||
const { result } = renderHook(usePendingGroups, undefined, store);
|
||||
|
||||
await waitFor(() => expect(result.current.isFetching).toBe(false));
|
||||
|
||||
expect(result.current.groups).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -1,30 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useApi, useFeatures, useOwnAccount } from 'soapbox/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
function usePendingGroups() {
|
||||
const api = useApi();
|
||||
const { account } = useOwnAccount();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, account?.id!, 'pending'],
|
||||
() => api.get('/api/v1/groups', {
|
||||
params: {
|
||||
pending: true,
|
||||
},
|
||||
}),
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: !!account && features.groupsPending,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
groups: entities,
|
||||
};
|
||||
}
|
||||
|
||||
export { usePendingGroups };
|
||||
@ -1,36 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useApi } from '../../../hooks/useApi';
|
||||
import { useFeatures } from '../../../hooks/useFeatures';
|
||||
|
||||
import { useGroupRelationships } from './useGroupRelationships';
|
||||
|
||||
function usePopularGroups() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'popular'],
|
||||
() => api.get('/api/v1/truth/trends/groups'),
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
},
|
||||
);
|
||||
|
||||
const { relationships } = useGroupRelationships(['popular'], entities.map(entity => entity.id));
|
||||
|
||||
const groups = entities.map((group) => ({
|
||||
...group,
|
||||
relationship: relationships[group.id] || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
...result,
|
||||
groups,
|
||||
};
|
||||
}
|
||||
|
||||
export { usePopularGroups };
|
||||
@ -1,25 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useApi, useFeatures } from 'soapbox/hooks';
|
||||
import { type GroupTag, groupTagSchema } from 'soapbox/schemas';
|
||||
|
||||
function usePopularTags() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<GroupTag>(
|
||||
[Entities.GROUP_TAGS],
|
||||
() => api.get('/api/v1/groups/tags'),
|
||||
{
|
||||
schema: groupTagSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...result,
|
||||
tags: entities,
|
||||
};
|
||||
}
|
||||
|
||||
export { usePopularTags };
|
||||
@ -1,34 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntities } from 'soapbox/entity-store/hooks';
|
||||
import { useApi, useFeatures } from 'soapbox/hooks';
|
||||
import { type Group, groupSchema } from 'soapbox/schemas';
|
||||
|
||||
import { useGroupRelationships } from './useGroupRelationships';
|
||||
|
||||
function useSuggestedGroups() {
|
||||
const api = useApi();
|
||||
const features = useFeatures();
|
||||
|
||||
const { entities, ...result } = useEntities<Group>(
|
||||
[Entities.GROUPS, 'suggested'],
|
||||
() => api.get('/api/v1/truth/suggestions/groups'),
|
||||
{
|
||||
schema: groupSchema,
|
||||
enabled: features.groupsDiscovery,
|
||||
},
|
||||
);
|
||||
|
||||
const { relationships } = useGroupRelationships(['suggested'], entities.map(entity => entity.id));
|
||||
|
||||
const groups = entities.map((group) => ({
|
||||
...group,
|
||||
relationship: relationships[group.id] || null,
|
||||
}));
|
||||
|
||||
return {
|
||||
...result,
|
||||
groups,
|
||||
};
|
||||
}
|
||||
|
||||
export { useSuggestedGroups };
|
||||
@ -1,18 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
import { type Group, groupRelationshipSchema } from 'soapbox/schemas';
|
||||
|
||||
function useUnmuteGroup(group?: Group) {
|
||||
const { createEntity, isSubmitting } = useEntityActions(
|
||||
[Entities.GROUP_RELATIONSHIPS, group?.id as string],
|
||||
{ post: `/api/v1/groups/${group?.id}/unmute` },
|
||||
{ schema: groupRelationshipSchema },
|
||||
);
|
||||
|
||||
return {
|
||||
mutate: createEntity,
|
||||
isSubmitting,
|
||||
};
|
||||
}
|
||||
|
||||
export { useUnmuteGroup };
|
||||
@ -10,7 +10,6 @@ interface UpdateGroupParams {
|
||||
header?: File | '';
|
||||
group_visibility?: string;
|
||||
discoverable?: boolean;
|
||||
tags?: string[];
|
||||
}
|
||||
|
||||
function useUpdateGroup(groupId: string) {
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
import { Entities } from 'soapbox/entity-store/entities';
|
||||
import { useEntityActions } from 'soapbox/entity-store/hooks';
|
||||
|
||||
import type { GroupTag } from 'soapbox/schemas';
|
||||
|
||||
function useUpdateGroupTag(groupId: string, tagId: string) {
|
||||
const { updateEntity, ...rest } = useEntityActions<GroupTag>(
|
||||
[Entities.GROUP_TAGS, groupId, tagId],
|
||||
{ patch: `/api/v1/groups/${groupId}/tags/${tagId}` },
|
||||
);
|
||||
|
||||
return {
|
||||
updateGroupTag: updateEntity,
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
|
||||
export { useUpdateGroupTag };
|
||||
@ -19,30 +19,16 @@ export { useCreateGroup, type CreateGroupParams } from './groups/useCreateGroup'
|
||||
export { useDeleteGroup } from './groups/useDeleteGroup';
|
||||
export { useDemoteGroupMember } from './groups/useDemoteGroupMember';
|
||||
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 { useGroupMutes } from './groups/useGroupMutes';
|
||||
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 { useMuteGroup } from './groups/useMuteGroup';
|
||||
export { useLeaveGroup } from './groups/useLeaveGroup';
|
||||
export { usePendingGroups } from './groups/usePendingGroups';
|
||||
export { usePopularGroups } from './groups/usePopularGroups';
|
||||
export { usePopularTags } from './groups/usePopularTags';
|
||||
export { usePromoteGroupMember } from './groups/usePromoteGroupMember';
|
||||
export { useSuggestedGroups } from './groups/useSuggestedGroups';
|
||||
export { useUnmuteGroup } from './groups/useUnmuteGroup';
|
||||
export { useUpdateGroup } from './groups/useUpdateGroup';
|
||||
export { useUpdateGroupTag } from './groups/useUpdateGroupTag';
|
||||
|
||||
// Statuses
|
||||
export { useBookmarkFolders } from './statuses/useBookmarkFolders';
|
||||
|
||||
Reference in New Issue
Block a user