Add validation support to features

develop^2
Chewbacca 2023-03-29 15:44:00 -04:00
rodzic 4886548889
commit 455030ef5b
2 zmienionych plików z 9 dodań i 2 usunięć

Wyświetl plik

@ -1,6 +1,7 @@
import { useQuery } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { useApi } from 'soapbox/hooks/useApi'; import { useApi } from 'soapbox/hooks/useApi';
import { useFeatures } from 'soapbox/hooks/useFeatures';
type Validation = { type Validation = {
error: string error: string
@ -13,6 +14,7 @@ const ValidationKeys = {
function useGroupValidation(name: string = '') { function useGroupValidation(name: string = '') {
const api = useApi(); const api = useApi();
const features = useFeatures();
const getValidation = async() => { const getValidation = async() => {
const { data } = await api.get<Validation>('/api/v1/groups/validate', { const { data } = await api.get<Validation>('/api/v1/groups/validate', {
@ -30,14 +32,14 @@ function useGroupValidation(name: string = '') {
}; };
const queryInfo = useQuery<Validation>(ValidationKeys.validation(name), getValidation, { const queryInfo = useQuery<Validation>(ValidationKeys.validation(name), getValidation, {
enabled: !!name, enabled: features.groupsValidation && !!name,
}); });
return { return {
...queryInfo, ...queryInfo,
data: { data: {
...queryInfo.data, ...queryInfo.data,
isValid: !queryInfo.data?.error, isValid: !queryInfo.data?.error ?? true,
}, },
}; };
} }

Wyświetl plik

@ -554,6 +554,11 @@ const getInstanceFeatures = (instance: Instance) => {
*/ */
groupsSearch: v.software === TRUTHSOCIAL, groupsSearch: v.software === TRUTHSOCIAL,
/**
* Can validate group names.
*/
groupsValidation: v.software === TRUTHSOCIAL,
/** /**
* Can hide follows/followers lists and counts. * Can hide follows/followers lists and counts.
* @see PATCH /api/v1/accounts/update_credentials * @see PATCH /api/v1/accounts/update_credentials