Merge branch 'dashboard' into 'main'
Extend dashboard, use hooks more See merge request soapbox-pub/soapbox!2989
This commit is contained in:
commit
9b63adc23f
29 changed files with 742 additions and 167 deletions
|
@ -55,10 +55,6 @@ const ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST = 'ADMIN_STATUS_TOGGLE_SENSITIVITY
|
|||
const ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS = 'ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS';
|
||||
const ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL = 'ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL';
|
||||
|
||||
const ADMIN_LOG_FETCH_REQUEST = 'ADMIN_LOG_FETCH_REQUEST';
|
||||
const ADMIN_LOG_FETCH_SUCCESS = 'ADMIN_LOG_FETCH_SUCCESS';
|
||||
const ADMIN_LOG_FETCH_FAIL = 'ADMIN_LOG_FETCH_FAIL';
|
||||
|
||||
const ADMIN_USERS_TAG_REQUEST = 'ADMIN_USERS_TAG_REQUEST';
|
||||
const ADMIN_USERS_TAG_SUCCESS = 'ADMIN_USERS_TAG_SUCCESS';
|
||||
const ADMIN_USERS_TAG_FAIL = 'ADMIN_USERS_TAG_FAIL';
|
||||
|
@ -423,19 +419,6 @@ const toggleStatusSensitivity = (id: string, sensitive: boolean) =>
|
|||
});
|
||||
};
|
||||
|
||||
const fetchModerationLog = (params?: Record<string, any>) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
dispatch({ type: ADMIN_LOG_FETCH_REQUEST });
|
||||
return api(getState)
|
||||
.get('/api/v1/pleroma/admin/moderation_log', { params })
|
||||
.then(({ data }) => {
|
||||
dispatch({ type: ADMIN_LOG_FETCH_SUCCESS, items: data.items, total: data.total });
|
||||
return data;
|
||||
}).catch(error => {
|
||||
dispatch({ type: ADMIN_LOG_FETCH_FAIL, error });
|
||||
});
|
||||
};
|
||||
|
||||
const tagUsers = (accountIds: string[], tags: string[]) =>
|
||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||
const nicknames = accountIdsToAccts(getState(), accountIds);
|
||||
|
@ -707,9 +690,6 @@ export {
|
|||
ADMIN_STATUS_TOGGLE_SENSITIVITY_REQUEST,
|
||||
ADMIN_STATUS_TOGGLE_SENSITIVITY_SUCCESS,
|
||||
ADMIN_STATUS_TOGGLE_SENSITIVITY_FAIL,
|
||||
ADMIN_LOG_FETCH_REQUEST,
|
||||
ADMIN_LOG_FETCH_SUCCESS,
|
||||
ADMIN_LOG_FETCH_FAIL,
|
||||
ADMIN_USERS_TAG_REQUEST,
|
||||
ADMIN_USERS_TAG_SUCCESS,
|
||||
ADMIN_USERS_TAG_FAIL,
|
||||
|
@ -757,7 +737,6 @@ export {
|
|||
approveUsers,
|
||||
deleteStatus,
|
||||
toggleStatusSensitivity,
|
||||
fetchModerationLog,
|
||||
tagUsers,
|
||||
untagUsers,
|
||||
setTags,
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export { useCreateDomain, type CreateDomainParams } from './useCreateDomain';
|
||||
export { useDeleteDomain } from './useDeleteDomain';
|
||||
export { useDomains } from './useDomains';
|
||||
export { useModerationLog } from './useModerationLog';
|
||||
export { useRelays } from './useRelays';
|
||||
export { useRules } from './useRules';
|
||||
export { useSuggest } from './useSuggest';
|
||||
export { useUpdateDomain } from './useUpdateDomain';
|
||||
export { useVerify } from './useVerify';
|
|
@ -2,11 +2,6 @@ import { Entities } from 'soapbox/entity-store/entities';
|
|||
import { useDeleteEntity } from 'soapbox/entity-store/hooks';
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
|
||||
interface DeleteDomainParams {
|
||||
domain: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
const useDeleteDomain = () => {
|
||||
const api = useApi();
|
||||
|
||||
|
@ -23,4 +18,4 @@ const useDeleteDomain = () => {
|
|||
};
|
||||
};
|
||||
|
||||
export { useDeleteDomain, type DeleteDomainParams };
|
||||
export { useDeleteDomain };
|
||||
|
|
|
@ -1,8 +1,21 @@
|
|||
import { useQuery } from '@tanstack/react-query';
|
||||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { domainSchema, type Domain } from 'soapbox/schemas';
|
||||
|
||||
import type { AxiosResponse } from 'axios';
|
||||
|
||||
interface CreateDomainParams {
|
||||
domain: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
interface UpdateDomainParams {
|
||||
id: string;
|
||||
public: boolean;
|
||||
}
|
||||
|
||||
const useDomains = () => {
|
||||
const api = useApi();
|
||||
|
||||
|
@ -14,12 +27,56 @@ const useDomains = () => {
|
|||
};
|
||||
|
||||
const result = useQuery<ReadonlyArray<Domain>>({
|
||||
queryKey: ['domains'],
|
||||
queryKey: ['admin', 'domains'],
|
||||
queryFn: getDomains,
|
||||
placeholderData: [],
|
||||
});
|
||||
|
||||
return result;
|
||||
const {
|
||||
mutate: createDomain,
|
||||
isPending: isCreating,
|
||||
} = useMutation({
|
||||
mutationFn: (params: CreateDomainParams) => api.post('/api/v1/pleroma/admin/domains', params),
|
||||
retry: false,
|
||||
onSuccess: ({ data }: AxiosResponse) =>
|
||||
queryClient.setQueryData(['admin', 'domains'], (prevResult: ReadonlyArray<Domain>) =>
|
||||
[...prevResult, domainSchema.parse(data)],
|
||||
),
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: updateDomain,
|
||||
isPending: isUpdating,
|
||||
} = useMutation({
|
||||
mutationFn: ({ id, ...params }: UpdateDomainParams) => api.patch(`/api/v1/pleroma/admin/domains/${id}`, params),
|
||||
retry: false,
|
||||
onSuccess: ({ data }: AxiosResponse) =>
|
||||
queryClient.setQueryData(['admin', 'domains'], (prevResult: ReadonlyArray<Domain>) =>
|
||||
prevResult.map((domain) => domain.id === data.id ? domainSchema.parse(data) : domain),
|
||||
),
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: deleteDomain,
|
||||
isPending: isDeleting,
|
||||
} = useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/v1/pleroma/admin/domains/${id}`),
|
||||
retry: false,
|
||||
onSuccess: (_, id) =>
|
||||
queryClient.setQueryData(['admin', 'domains'], (prevResult: ReadonlyArray<Domain>) =>
|
||||
prevResult.filter(({ id: domainId }) => domainId !== id),
|
||||
),
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
createDomain,
|
||||
isCreating,
|
||||
updateDomain,
|
||||
isUpdating,
|
||||
deleteDomain,
|
||||
isDeleting,
|
||||
};
|
||||
};
|
||||
|
||||
export { useDomains };
|
||||
|
|
42
src/api/hooks/admin/useModerationLog.ts
Normal file
42
src/api/hooks/admin/useModerationLog.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { useInfiniteQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { moderationLogEntrySchema, type ModerationLogEntry } from 'soapbox/schemas';
|
||||
|
||||
interface ModerationLogResult {
|
||||
items: ModerationLogEntry[];
|
||||
total: number;
|
||||
}
|
||||
|
||||
const flattenPages = (pages?: ModerationLogResult[]): ModerationLogEntry[] => (pages || []).map(({ items }) => items).flat();
|
||||
|
||||
const useModerationLog = () => {
|
||||
const api = useApi();
|
||||
|
||||
const getModerationLog = async (page: number): Promise<ModerationLogResult> => {
|
||||
const { data } = await api.get<ModerationLogResult>('/api/v1/pleroma/admin/moderation_log', { params: { page } });
|
||||
|
||||
const normalizedData = data.items.map((domain) => moderationLogEntrySchema.parse(domain));
|
||||
|
||||
return {
|
||||
items: normalizedData,
|
||||
total: data.total,
|
||||
};
|
||||
};
|
||||
|
||||
const queryInfo = useInfiniteQuery({
|
||||
queryKey: ['admin', 'moderation_log'],
|
||||
queryFn: ({ pageParam }) => getModerationLog(pageParam),
|
||||
initialPageParam: 1,
|
||||
getNextPageParam: (page, allPages) => flattenPages(allPages)!.length >= page.total ? undefined : allPages.length + 1,
|
||||
});
|
||||
|
||||
const data = flattenPages(queryInfo.data?.pages);
|
||||
|
||||
return {
|
||||
...queryInfo,
|
||||
data,
|
||||
};
|
||||
};
|
||||
|
||||
export { useModerationLog };
|
60
src/api/hooks/admin/useRelays.ts
Normal file
60
src/api/hooks/admin/useRelays.ts
Normal file
|
@ -0,0 +1,60 @@
|
|||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { relaySchema, type Relay } from 'soapbox/schemas';
|
||||
|
||||
import type { AxiosResponse } from 'axios';
|
||||
|
||||
const useRelays = () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRelays = async () => {
|
||||
const { data } = await api.get<{ relays: Relay[] }>('/api/v1/pleroma/admin/relay');
|
||||
|
||||
const normalizedData = data.relays?.map((relay) => relaySchema.parse(relay));
|
||||
return normalizedData;
|
||||
};
|
||||
|
||||
const result = useQuery<ReadonlyArray<Relay>>({
|
||||
queryKey: ['admin', 'relays'],
|
||||
queryFn: getRelays,
|
||||
placeholderData: [],
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: followRelay,
|
||||
isPending: isPendingFollow,
|
||||
} = useMutation({
|
||||
mutationFn: (relayUrl: string) => api.post('/api/v1/pleroma/admin/relays', { relay_url: relayUrl }),
|
||||
retry: false,
|
||||
onSuccess: ({ data }: AxiosResponse) =>
|
||||
queryClient.setQueryData(['admin', 'relays'], (prevResult: ReadonlyArray<Relay>) =>
|
||||
[...prevResult, relaySchema.parse(data)],
|
||||
),
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: unfollowRelay,
|
||||
isPending: isPendingUnfollow,
|
||||
} = useMutation({
|
||||
mutationFn: (relayUrl: string) => api.delete('/api/v1/pleroma/admin/relays', {
|
||||
data: { relay_url: relayUrl },
|
||||
}),
|
||||
retry: false,
|
||||
onSuccess: (_, relayUrl) =>
|
||||
queryClient.setQueryData(['admin', 'relays'], (prevResult: ReadonlyArray<Relay>) =>
|
||||
prevResult.filter(({ actor }) => actor !== relayUrl),
|
||||
),
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
followRelay,
|
||||
isPendingFollow,
|
||||
unfollowRelay,
|
||||
isPendingUnfollow,
|
||||
};
|
||||
};
|
||||
|
||||
export { useRelays };
|
85
src/api/hooks/admin/useRules.ts
Normal file
85
src/api/hooks/admin/useRules.ts
Normal file
|
@ -0,0 +1,85 @@
|
|||
import { useMutation, useQuery } from '@tanstack/react-query';
|
||||
|
||||
import { useApi } from 'soapbox/hooks';
|
||||
import { queryClient } from 'soapbox/queries/client';
|
||||
import { adminRuleSchema, type AdminRule } from 'soapbox/schemas';
|
||||
|
||||
import type { AxiosResponse } from 'axios';
|
||||
|
||||
interface CreateRuleParams {
|
||||
priority?: number;
|
||||
text: string;
|
||||
hint?: string;
|
||||
}
|
||||
|
||||
interface UpdateRuleParams {
|
||||
id: string;
|
||||
priority?: number;
|
||||
text?: string;
|
||||
hint?: string;
|
||||
}
|
||||
|
||||
const useRules = () => {
|
||||
const api = useApi();
|
||||
|
||||
const getRules = async () => {
|
||||
const { data } = await api.get<AdminRule[]>('/api/v1/pleroma/admin/rules');
|
||||
|
||||
const normalizedData = data.map((rule) => adminRuleSchema.parse(rule));
|
||||
return normalizedData;
|
||||
};
|
||||
|
||||
const result = useQuery<ReadonlyArray<AdminRule>>({
|
||||
queryKey: ['admin', 'rules'],
|
||||
queryFn: getRules,
|
||||
placeholderData: [],
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: createRule,
|
||||
isPending: isCreating,
|
||||
} = useMutation({
|
||||
mutationFn: (params: CreateRuleParams) => api.post('/api/v1/pleroma/admin/rules', params),
|
||||
retry: false,
|
||||
onSuccess: ({ data }: AxiosResponse) =>
|
||||
queryClient.setQueryData(['admin', 'rules'], (prevResult: ReadonlyArray<AdminRule>) =>
|
||||
[...prevResult, adminRuleSchema.parse(data)],
|
||||
),
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: updateRule,
|
||||
isPending: isUpdating,
|
||||
} = useMutation({
|
||||
mutationFn: ({ id, ...params }: UpdateRuleParams) => api.patch(`/api/v1/pleroma/admin/rules/${id}`, params),
|
||||
retry: false,
|
||||
onSuccess: ({ data }: AxiosResponse) =>
|
||||
queryClient.setQueryData(['admin', 'rules'], (prevResult: ReadonlyArray<AdminRule>) =>
|
||||
prevResult.map((rule) => rule.id === data.id ? adminRuleSchema.parse(data) : rule),
|
||||
),
|
||||
});
|
||||
|
||||
const {
|
||||
mutate: deleteRule,
|
||||
isPending: isDeleting,
|
||||
} = useMutation({
|
||||
mutationFn: (id: string) => api.delete(`/api/v1/pleroma/admin/rules/${id}`),
|
||||
retry: false,
|
||||
onSuccess: (_, id) =>
|
||||
queryClient.setQueryData(['admin', 'rules'], (prevResult: ReadonlyArray<AdminRule>) =>
|
||||
prevResult.filter(({ id: ruleId }) => ruleId !== id),
|
||||
),
|
||||
});
|
||||
|
||||
return {
|
||||
...result,
|
||||
createRule,
|
||||
isCreating,
|
||||
updateRule,
|
||||
isUpdating,
|
||||
deleteRule,
|
||||
isDeleting,
|
||||
};
|
||||
};
|
||||
|
||||
export { useRules };
|
|
@ -4,7 +4,7 @@
|
|||
* @module soapbox/api
|
||||
*/
|
||||
|
||||
import axios, { AxiosInstance, AxiosResponse } from 'axios';
|
||||
import axios, { type AxiosInstance, type AxiosResponse } from 'axios';
|
||||
import LinkHeader from 'http-link-header';
|
||||
import { createSelector } from 'reselect';
|
||||
|
||||
|
|
|
@ -11,7 +11,9 @@ enum Entities {
|
|||
GROUP_TAGS = 'GroupTags',
|
||||
PATRON_USERS = 'PatronUsers',
|
||||
RELATIONSHIPS = 'Relationships',
|
||||
STATUSES = 'Statuses'
|
||||
RELAYS = 'Relays',
|
||||
RULES = 'Rules',
|
||||
STATUSES = 'Statuses',
|
||||
}
|
||||
|
||||
interface EntityTypes {
|
||||
|
@ -24,6 +26,8 @@ interface EntityTypes {
|
|||
[Entities.GROUP_TAGS]: Schemas.GroupTag;
|
||||
[Entities.PATRON_USERS]: Schemas.PatronUser;
|
||||
[Entities.RELATIONSHIPS]: Schemas.Relationship;
|
||||
[Entities.RELAYS]: Schemas.Relay;
|
||||
[Entities.RULES]: Schemas.AdminRule;
|
||||
[Entities.STATUSES]: Schemas.Status;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import React from 'react';
|
||||
import React, { useEffect } from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { openModal } from 'soapbox/actions/modals';
|
||||
import { useDeleteDomain, useDomains } from 'soapbox/api/hooks/admin';
|
||||
import { useDomains } from 'soapbox/api/hooks/admin';
|
||||
import { dateFormatOptions } from 'soapbox/components/relative-timestamp';
|
||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||
import { Button, Column, HStack, Stack, Text } from 'soapbox/components/ui';
|
||||
|
@ -30,23 +30,23 @@ const Domain: React.FC<IDomain> = ({ domain }) => {
|
|||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { mutate: deleteDomain } = useDeleteDomain();
|
||||
const { refetch } = useDomains();
|
||||
const { deleteDomain } = useDomains();
|
||||
|
||||
const handleEditDomain = (domain: DomainEntity) => () => {
|
||||
dispatch(openModal('EDIT_DOMAIN', { domainId: domain.id }));
|
||||
};
|
||||
|
||||
const handleDeleteDomain = (id: string) => () => {
|
||||
const handleDeleteDomain = () => () => {
|
||||
dispatch(openModal('CONFIRM', {
|
||||
heading: intl.formatMessage(messages.deleteHeading),
|
||||
message: intl.formatMessage(messages.deleteMessage),
|
||||
confirm: intl.formatMessage(messages.deleteConfirm),
|
||||
onConfirm: () => {
|
||||
deleteDomain(domain.id).then(() => {
|
||||
toast.success(messages.domainDeleteSuccess);
|
||||
refetch();
|
||||
}).catch(() => {});
|
||||
deleteDomain(domain.id, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.domainDeleteSuccess);
|
||||
},
|
||||
});
|
||||
},
|
||||
}));
|
||||
};
|
||||
|
@ -90,7 +90,7 @@ const Domain: React.FC<IDomain> = ({ domain }) => {
|
|||
<Button theme='primary' onClick={handleEditDomain(domain)}>
|
||||
<FormattedMessage id='admin.domains.edit' defaultMessage='Edit' />
|
||||
</Button>
|
||||
<Button theme='primary' onClick={handleDeleteDomain(domain.id)}>
|
||||
<Button theme='primary' onClick={handleDeleteDomain()}>
|
||||
<FormattedMessage id='admin.domains.delete' defaultMessage='Delete' />
|
||||
</Button>
|
||||
</HStack>
|
||||
|
@ -103,12 +103,16 @@ const Domains: React.FC = () => {
|
|||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { data: domains, isFetching } = useDomains();
|
||||
const { data: domains, isFetching, refetch } = useDomains();
|
||||
|
||||
const handleCreateDomain = () => {
|
||||
dispatch(openModal('EDIT_DOMAIN'));
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (!isFetching) refetch();
|
||||
}, []);
|
||||
|
||||
const emptyMessage = <FormattedMessage id='empty_column.admin.domains' defaultMessage='There are no domains yet.' />;
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
import React, { useEffect, useState } from 'react';
|
||||
import React from 'react';
|
||||
import { defineMessages, FormattedDate, useIntl } from 'react-intl';
|
||||
|
||||
import { fetchModerationLog } from 'soapbox/actions/admin';
|
||||
import { useModerationLog } from 'soapbox/api/hooks/admin';
|
||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||
import { Column, Stack, Text } from 'soapbox/components/ui';
|
||||
import { useAppDispatch, useAppSelector } from 'soapbox/hooks';
|
||||
import { AdminLog } from 'soapbox/types/entities';
|
||||
|
||||
import type { ModerationLogEntry } from 'soapbox/schemas';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.admin.moderation_log', defaultMessage: 'Moderation Log' },
|
||||
|
@ -14,37 +14,18 @@ const messages = defineMessages({
|
|||
|
||||
const ModerationLog = () => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const items = useAppSelector((state) => {
|
||||
return state.admin_log.index.map((i) => state.admin_log.items.get(String(i)));
|
||||
});
|
||||
const {
|
||||
data,
|
||||
hasNextPage,
|
||||
isLoading,
|
||||
fetchNextPage,
|
||||
} = useModerationLog();
|
||||
|
||||
const hasMore = useAppSelector((state) => state.admin_log.total - state.admin_log.index.count() > 0);
|
||||
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [lastPage, setLastPage] = useState(0);
|
||||
|
||||
const showLoading = isLoading && items.count() === 0;
|
||||
|
||||
useEffect(() => {
|
||||
dispatch(fetchModerationLog())
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
setLastPage(1);
|
||||
})
|
||||
.catch(() => { });
|
||||
}, []);
|
||||
const showLoading = isLoading && data.length === 0;
|
||||
|
||||
const handleLoadMore = () => {
|
||||
const page = lastPage + 1;
|
||||
|
||||
setIsLoading(true);
|
||||
dispatch(fetchModerationLog({ page }))
|
||||
.then(() => {
|
||||
setIsLoading(false);
|
||||
setLastPage(page);
|
||||
}).catch(() => { });
|
||||
fetchNextPage();
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -54,11 +35,11 @@ const ModerationLog = () => {
|
|||
showLoading={showLoading}
|
||||
scrollKey='moderation-log'
|
||||
emptyMessage={intl.formatMessage(messages.emptyMessage)}
|
||||
hasMore={hasMore}
|
||||
hasMore={hasNextPage}
|
||||
onLoadMore={handleLoadMore}
|
||||
listClassName='divide-y divide-solid divide-gray-200 dark:divide-gray-800'
|
||||
>
|
||||
{items.map(item => item && (
|
||||
{data.map(item => item && (
|
||||
<LogItem key={item.id} log={item} />
|
||||
))}
|
||||
</ScrollableList>
|
||||
|
@ -67,7 +48,7 @@ const ModerationLog = () => {
|
|||
};
|
||||
|
||||
interface ILogItem {
|
||||
log: AdminLog;
|
||||
log: ModerationLogEntry;
|
||||
}
|
||||
|
||||
const LogItem: React.FC<ILogItem> = ({ log }) => {
|
||||
|
|
139
src/features/admin/relays.tsx
Normal file
139
src/features/admin/relays.tsx
Normal file
|
@ -0,0 +1,139 @@
|
|||
import React from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { useRelays } from 'soapbox/api/hooks/admin';
|
||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||
import { Button, Column, Form, HStack, Input, Stack, Text } from 'soapbox/components/ui';
|
||||
import { useTextField } from 'soapbox/hooks/forms';
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
import type { Relay as RelayEntity } from 'soapbox/schemas';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.admin.relays', defaultMessage: 'Instance relays' },
|
||||
relayDeleteSuccess: { id: 'admin.relays.deleted', defaultMessage: 'Relay unfollowed' },
|
||||
label: { id: 'admin.relays.new.url_placeholder', defaultMessage: 'Instance relay URL' },
|
||||
createSuccess: { id: 'admin.relays.add.success', defaultMessage: 'Instance relay followed' },
|
||||
createFail: { id: 'admin.relays.add.fail', defaultMessage: 'Failed to follow the instance relay' },
|
||||
});
|
||||
|
||||
interface IRelay {
|
||||
relay: RelayEntity;
|
||||
}
|
||||
|
||||
const Relay: React.FC<IRelay> = ({ relay }) => {
|
||||
const { unfollowRelay } = useRelays();
|
||||
|
||||
const handleDeleteRelay = () => () => {
|
||||
unfollowRelay(relay.actor, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.relayDeleteSuccess);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div key={relay.id} className='rounded-lg bg-gray-100 p-4 dark:bg-primary-800'>
|
||||
<Stack space={2}>
|
||||
<HStack alignItems='center' space={4} wrap>
|
||||
<Text size='sm'>
|
||||
<Text tag='span' size='sm' weight='medium'>
|
||||
<FormattedMessage id='admin.relays.url' defaultMessage='Instance URL:' />
|
||||
</Text>
|
||||
{' '}
|
||||
{relay.actor}
|
||||
</Text>
|
||||
{relay.followed_back && (
|
||||
<Text tag='span' size='sm' weight='medium'>
|
||||
<FormattedMessage id='admin.relays.followed_back' defaultMessage='Followed back' />
|
||||
</Text>
|
||||
)}
|
||||
</HStack>
|
||||
<HStack justifyContent='end' space={2}>
|
||||
<Button theme='primary' onClick={handleDeleteRelay()}>
|
||||
<FormattedMessage id='admin.relays.unfollow' defaultMessage='Unfollow' />
|
||||
</Button>
|
||||
</HStack>
|
||||
</Stack>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const NewRelayForm: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
|
||||
const name = useTextField();
|
||||
|
||||
const { followRelay, isPendingFollow } = useRelays();
|
||||
|
||||
const handleSubmit = (e: React.FormEvent<Element>) => {
|
||||
e.preventDefault();
|
||||
followRelay(name.value, {
|
||||
onSuccess() {
|
||||
toast.success(messages.createSuccess);
|
||||
},
|
||||
onError() {
|
||||
toast.error(messages.createFail);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const label = intl.formatMessage(messages.label);
|
||||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<HStack space={2} alignItems='center'>
|
||||
<label className='grow'>
|
||||
<span style={{ display: 'none' }}>{label}</span>
|
||||
|
||||
<Input
|
||||
type='text'
|
||||
placeholder={label}
|
||||
disabled={isPendingFollow}
|
||||
{...name}
|
||||
/>
|
||||
</label>
|
||||
|
||||
<Button
|
||||
disabled={isPendingFollow}
|
||||
onClick={handleSubmit}
|
||||
theme='primary'
|
||||
>
|
||||
<FormattedMessage id='admin.relays.new.follow' defaultMessage='Follow' />
|
||||
</Button>
|
||||
</HStack>
|
||||
</Form>
|
||||
);
|
||||
};
|
||||
|
||||
const Relays: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
|
||||
const { data: relays, isFetching } = useRelays();
|
||||
|
||||
const emptyMessage = <FormattedMessage id='empty_column.admin.relays' defaultMessage='There are no relays followed yet.' />;
|
||||
|
||||
return (
|
||||
<Column label={intl.formatMessage(messages.heading)}>
|
||||
<Stack className='gap-4'>
|
||||
<NewRelayForm />
|
||||
|
||||
{relays && (
|
||||
<ScrollableList
|
||||
scrollKey='relays'
|
||||
emptyMessage={emptyMessage}
|
||||
itemClassName='py-3 first:pt-0 last:pb-0'
|
||||
isLoading={isFetching}
|
||||
showLoading={isFetching && !relays?.length}
|
||||
>
|
||||
{relays.map((relay) => (
|
||||
<Relay key={relay.id} relay={relay} />
|
||||
))}
|
||||
</ScrollableList>
|
||||
)}
|
||||
</Stack>
|
||||
</Column>
|
||||
);
|
||||
};
|
||||
|
||||
export default Relays;
|
111
src/features/admin/rules.tsx
Normal file
111
src/features/admin/rules.tsx
Normal file
|
@ -0,0 +1,111 @@
|
|||
import React from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { openModal } from 'soapbox/actions/modals';
|
||||
import { useRules } from 'soapbox/api/hooks/admin';
|
||||
import ScrollableList from 'soapbox/components/scrollable-list';
|
||||
import { Button, Column, HStack, Stack, Text } from 'soapbox/components/ui';
|
||||
import { useAppDispatch } from 'soapbox/hooks';
|
||||
import { AdminRule } from 'soapbox/schemas';
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
const messages = defineMessages({
|
||||
heading: { id: 'column.admin.rules', defaultMessage: 'Instance rules' },
|
||||
deleteConfirm: { id: 'confirmations.admin.delete_rule.confirm', defaultMessage: 'Delete' },
|
||||
deleteHeading: { id: 'confirmations.admin.delete_rule.heading', defaultMessage: 'Delete rule' },
|
||||
deleteMessage: { id: 'confirmations.admin.delete_rule.message', defaultMessage: 'Are you sure you want to delete the rule?' },
|
||||
ruleDeleteSuccess: { id: 'admin.edit_rule.deleted', defaultMessage: 'Rule deleted' },
|
||||
});
|
||||
|
||||
interface IRule {
|
||||
rule: AdminRule;
|
||||
}
|
||||
|
||||
const Rule: React.FC<IRule> = ({ rule }) => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
const { deleteRule } = useRules();
|
||||
|
||||
const handleEditRule = (rule: AdminRule) => () => {
|
||||
dispatch(openModal('EDIT_RULE', { rule }));
|
||||
};
|
||||
|
||||
const handleDeleteRule = (id: string) => () => {
|
||||
dispatch(openModal('CONFIRM', {
|
||||
heading: intl.formatMessage(messages.deleteHeading),
|
||||
message: intl.formatMessage(messages.deleteMessage),
|
||||
confirm: intl.formatMessage(messages.deleteConfirm),
|
||||
onConfirm: () => deleteRule(id, {
|
||||
onSuccess: () => toast.success(messages.ruleDeleteSuccess),
|
||||
}),
|
||||
}));
|
||||
};
|
||||
|
||||
return (
|
||||
<div key={rule.id} className='rounded-lg bg-gray-100 p-4 dark:bg-primary-800'>
|
||||
<Stack space={2}>
|
||||
<Text>{rule.text}</Text>
|
||||
<Text tag='span' theme='muted' size='sm'>{rule.hint}</Text>
|
||||
{rule.priority !== null && (
|
||||
<Text size='sm'>
|
||||
<Text tag='span' size='sm' weight='medium'>
|
||||
<FormattedMessage id='admin.rule.priority' defaultMessage='Priority:' />
|
||||
</Text>
|
||||
{' '}
|
||||
{rule.priority}
|
||||
</Text>
|
||||
)}
|
||||
<HStack justifyContent='end' space={2}>
|
||||
<Button theme='primary' onClick={handleEditRule(rule)}>
|
||||
<FormattedMessage id='admin.rules.edit' defaultMessage='Edit' />
|
||||
</Button>
|
||||
<Button theme='primary' onClick={handleDeleteRule(rule.id)}>
|
||||
<FormattedMessage id='admin.rules.delete' defaultMessage='Delete' />
|
||||
</Button>
|
||||
</HStack>
|
||||
</Stack>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
const Rules: React.FC = () => {
|
||||
const intl = useIntl();
|
||||
const dispatch = useAppDispatch();
|
||||
|
||||
const { data, isLoading } = useRules();
|
||||
|
||||
const handleCreateRule = () => {
|
||||
dispatch(openModal('EDIT_RULE'));
|
||||
};
|
||||
|
||||
const emptyMessage = <FormattedMessage id='empty_column.admin.rules' defaultMessage='There are no instance rules yet.' />;
|
||||
|
||||
return (
|
||||
<Column label={intl.formatMessage(messages.heading)}>
|
||||
<Stack className='gap-4'>
|
||||
<Button
|
||||
className='sm:w-fit sm:self-end'
|
||||
icon={require('@tabler/icons/outline/plus.svg')}
|
||||
onClick={handleCreateRule}
|
||||
theme='secondary'
|
||||
block
|
||||
>
|
||||
<FormattedMessage id='admin.rules.action' defaultMessage='Create rule' />
|
||||
</Button>
|
||||
<ScrollableList
|
||||
scrollKey='rules'
|
||||
emptyMessage={emptyMessage}
|
||||
itemClassName='py-3 first:pt-0 last:pb-0'
|
||||
isLoading={isLoading}
|
||||
showLoading={isLoading}
|
||||
>
|
||||
{data!.map((rule) => (
|
||||
<Rule key={rule.id} rule={rule} />
|
||||
))}
|
||||
</ScrollableList>
|
||||
</Stack>
|
||||
</Column>
|
||||
);
|
||||
};
|
||||
|
||||
export default Rules;
|
|
@ -100,6 +100,13 @@ const Dashboard: React.FC = () => {
|
|||
/>
|
||||
)}
|
||||
|
||||
{features.adminRules && (
|
||||
<ListItem
|
||||
to='/soapbox/admin/rules'
|
||||
label={<FormattedMessage id='column.admin.rules' defaultMessage='Instance rules' />}
|
||||
/>
|
||||
)}
|
||||
|
||||
{features.domains && (
|
||||
<ListItem
|
||||
to='/soapbox/admin/domains'
|
||||
|
|
|
@ -37,7 +37,7 @@ const NewFolderForm: React.FC = () => {
|
|||
|
||||
return (
|
||||
<Form onSubmit={handleSubmit}>
|
||||
<HStack space={2}>
|
||||
<HStack space={2} alignItems='center'>
|
||||
<label className='grow'>
|
||||
<span style={{ display: 'none' }}>{label}</span>
|
||||
|
||||
|
|
|
@ -41,6 +41,7 @@ import {
|
|||
SelectBookmarkFolderModal,
|
||||
UnauthorizedModal,
|
||||
VideoModal,
|
||||
EditRuleModal,
|
||||
} from 'soapbox/features/ui/util/async-components';
|
||||
|
||||
import ModalLoading from './modal-loading';
|
||||
|
@ -63,6 +64,7 @@ const MODAL_COMPONENTS: Record<string, React.LazyExoticComponent<any>> = {
|
|||
'EDIT_BOOKMARK_FOLDER': EditBookmarkFolderModal,
|
||||
'EDIT_DOMAIN': EditDomainModal,
|
||||
'EDIT_FEDERATION': EditFederationModal,
|
||||
'EDIT_RULE': EditRuleModal,
|
||||
'EMBED': EmbedModal,
|
||||
'EVENT_MAP': EventMapModal,
|
||||
'EVENT_PARTICIPANTS': EventParticipantsModal,
|
||||
|
|
|
@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { closeModal } from 'soapbox/actions/modals';
|
||||
import { useCreateDomain, useDomains, useUpdateDomain } from 'soapbox/api/hooks/admin';
|
||||
import { useDomains } from 'soapbox/api/hooks/admin';
|
||||
import { Form, FormGroup, HStack, Input, Modal, Stack, Text, Toggle } from 'soapbox/components/ui';
|
||||
import { useAppDispatch } from 'soapbox/hooks';
|
||||
import { Domain } from 'soapbox/schemas';
|
||||
|
@ -24,9 +24,7 @@ const EditDomainModal: React.FC<IEditDomainModal> = ({ onClose, domainId }) => {
|
|||
const dispatch = useAppDispatch();
|
||||
const intl = useIntl();
|
||||
|
||||
const { data: domains, refetch } = useDomains();
|
||||
const { createDomain, isSubmitting: isCreating } = useCreateDomain();
|
||||
const { updateDomain, isSubmitting: isUpdating } = useUpdateDomain(domainId!);
|
||||
const { data: domains, createDomain, isCreating, updateDomain, isUpdating } = useDomains();
|
||||
|
||||
const [domain] = useState<Domain | null>(domainId ? domains!.find(({ id }) => domainId === id)! : null);
|
||||
const [domainName, setDomainName] = useState(domain?.domain || '');
|
||||
|
@ -39,21 +37,24 @@ const EditDomainModal: React.FC<IEditDomainModal> = ({ onClose, domainId }) => {
|
|||
const handleSubmit = () => {
|
||||
if (domainId) {
|
||||
updateDomain({
|
||||
id: domainId,
|
||||
public: isPublic,
|
||||
}).then(() => {
|
||||
toast.success(messages.domainUpdateSuccess);
|
||||
dispatch(closeModal('EDIT_DOMAIN'));
|
||||
refetch();
|
||||
}).catch(() => {});
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.domainUpdateSuccess);
|
||||
dispatch(closeModal('EDIT_DOMAIN'));
|
||||
},
|
||||
});
|
||||
} else {
|
||||
createDomain({
|
||||
domain: domainName,
|
||||
public: isPublic,
|
||||
}).then(() => {
|
||||
toast.success(messages.domainCreateSuccess);
|
||||
dispatch(closeModal('EDIT_DOMAIN'));
|
||||
refetch();
|
||||
}).catch(() => {});
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.domainCreateSuccess);
|
||||
dispatch(closeModal('EDIT_DOMAIN'));
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
|
92
src/features/ui/components/modals/edit-rule-modal.tsx
Normal file
92
src/features/ui/components/modals/edit-rule-modal.tsx
Normal file
|
@ -0,0 +1,92 @@
|
|||
import React from 'react';
|
||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||
|
||||
import { useRules } from 'soapbox/api/hooks/admin';
|
||||
import { Form, FormGroup, Input, Modal } from 'soapbox/components/ui';
|
||||
import { useTextField } from 'soapbox/hooks/forms';
|
||||
import { type AdminRule } from 'soapbox/schemas';
|
||||
import toast from 'soapbox/toast';
|
||||
|
||||
const messages = defineMessages({
|
||||
save: { id: 'admin.edit_rule.save', defaultMessage: 'Save' },
|
||||
ruleTextPlaceholder: { id: 'admin.edit_rule.fields.text_placeholder', defaultMessage: 'Instance rule text' },
|
||||
rulePriorityPlaceholder: { id: 'admin.edit_rule.fields.priority_placeholder', defaultMessage: 'Instance rule display priority' },
|
||||
ruleCreateSuccess: { id: 'admin.edit_rule.created', defaultMessage: 'Rule created' },
|
||||
ruleUpdateSuccess: { id: 'admin.edit_rule.updated', defaultMessage: 'Rule edited' },
|
||||
});
|
||||
|
||||
interface IEditRuleModal {
|
||||
onClose: (type?: string) => void;
|
||||
rule?: AdminRule;
|
||||
}
|
||||
|
||||
const EditRuleModal: React.FC<IEditRuleModal> = ({ onClose, rule }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const { createRule, updateRule } = useRules();
|
||||
|
||||
const text = useTextField(rule?.text);
|
||||
const priority = useTextField(rule?.priority?.toString());
|
||||
|
||||
const onClickClose = () => {
|
||||
onClose('EDIT_RULE');
|
||||
};
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (rule) {
|
||||
updateRule({
|
||||
id: rule.id,
|
||||
text: text.value,
|
||||
priority: isNaN(Number(priority.value)) ? undefined : Number(priority.value),
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.ruleUpdateSuccess);
|
||||
onClickClose();
|
||||
},
|
||||
});
|
||||
} else {
|
||||
createRule({
|
||||
text: text.value,
|
||||
priority: isNaN(Number(priority.value)) ? undefined : Number(priority.value),
|
||||
}, {
|
||||
onSuccess: () => {
|
||||
toast.success(messages.ruleUpdateSuccess);
|
||||
onClickClose();
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
onClose={onClickClose}
|
||||
title={rule
|
||||
? <FormattedMessage id='column.admin.edit_rule' defaultMessage='Edit rule' />
|
||||
: <FormattedMessage id='column.admin.create_rule' defaultMessage='Create rule' />}
|
||||
confirmationAction={handleSubmit}
|
||||
confirmationText={intl.formatMessage(messages.save)}
|
||||
>
|
||||
<Form>
|
||||
<FormGroup
|
||||
labelText={<FormattedMessage id='admin.edit_rule.fields.text_label' defaultMessage='Rule text' />}
|
||||
>
|
||||
<Input
|
||||
placeholder={intl.formatMessage(messages.ruleTextPlaceholder)}
|
||||
{...text}
|
||||
/>
|
||||
</FormGroup>
|
||||
<FormGroup
|
||||
labelText={<FormattedMessage id='admin.edit_rule.fields.priority_label' defaultMessage='Rule priority' />}
|
||||
>
|
||||
<Input
|
||||
placeholder={intl.formatMessage(messages.rulePriorityPlaceholder)}
|
||||
type='number'
|
||||
{...priority}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Form>
|
||||
</Modal>
|
||||
);
|
||||
};
|
||||
|
||||
export default EditRuleModal;
|
|
@ -141,6 +141,8 @@ import {
|
|||
Domains,
|
||||
NostrRelays,
|
||||
Bech32Redirect,
|
||||
Relays,
|
||||
Rules,
|
||||
} from './util/async-components';
|
||||
import GlobalHotkeys from './util/global-hotkeys';
|
||||
import { WrappedRoute } from './util/react-router-helpers';
|
||||
|
@ -331,8 +333,10 @@ const SwitchingColumnsArea: React.FC<ISwitchingColumnsArea> = ({ children }) =>
|
|||
<WrappedRoute path='/soapbox/admin/log' staffOnly page={AdminPage} component={ModerationLog} content={children} exact />
|
||||
<WrappedRoute path='/soapbox/admin/users' staffOnly page={AdminPage} component={UserIndex} content={children} exact />
|
||||
<WrappedRoute path='/soapbox/admin/theme' staffOnly page={AdminPage} component={ThemeEditor} content={children} exact />
|
||||
<WrappedRoute path='/soapbox/admin/relays' staffOnly page={AdminPage} component={Relays} content={children} exact />
|
||||
{features.adminAnnouncements && <WrappedRoute path='/soapbox/admin/announcements' staffOnly page={AdminPage} component={Announcements} content={children} exact />}
|
||||
{features.domains && <WrappedRoute path='/soapbox/admin/domains' staffOnly page={AdminPage} component={Domains} content={children} exact />}
|
||||
{features.adminRules && <WrappedRoute path='/soapbox/admin/rules' staffOnly page={AdminPage} component={Rules} content={children} exact />}
|
||||
<WrappedRoute path='/info' page={EmptyPage} component={ServerInfo} content={children} />
|
||||
|
||||
<WrappedRoute path='/developers/apps/create' developerOnly page={DefaultPage} component={CreateApp} content={children} />
|
||||
|
|
|
@ -171,4 +171,7 @@ export const EditIdentity = lazy(() => import('soapbox/features/edit-identity'))
|
|||
export const Domains = lazy(() => import('soapbox/features/admin/domains'));
|
||||
export const EditDomainModal = lazy(() => import('soapbox/features/ui/components/modals/edit-domain-modal'));
|
||||
export const NostrRelays = lazy(() => import('soapbox/features/nostr-relays'));
|
||||
export const Bech32Redirect = lazy(() => import('soapbox/features/nostr/Bech32Redirect'));
|
||||
export const Bech32Redirect = lazy(() => import('soapbox/features/nostr/Bech32Redirect'));
|
||||
export const Relays = lazy(() => import('soapbox/features/admin/relays'));
|
||||
export const Rules = lazy(() => import('soapbox/features/admin/rules'));
|
||||
export const EditRuleModal = lazy(() => import('soapbox/features/ui/components/modals/edit-rule-modal'));
|
||||
|
|
|
@ -135,14 +135,34 @@
|
|||
"admin.edit_domain.fields.public_label": "Public",
|
||||
"admin.edit_domain.save": "Save",
|
||||
"admin.edit_domain.updated": "Domain edited",
|
||||
"admin.edit_rule.created": "Rule created",
|
||||
"admin.edit_rule.deleted": "Rule deleted",
|
||||
"admin.edit_rule.fields.priority_label": "Rule priority",
|
||||
"admin.edit_rule.fields.priority_placeholder": "Instance rule display priority",
|
||||
"admin.edit_rule.fields.text_label": "Rule text",
|
||||
"admin.edit_rule.fields.text_placeholder": "Instance rule text",
|
||||
"admin.edit_rule.save": "Save",
|
||||
"admin.edit_rule.updated": "Rule edited",
|
||||
"admin.latest_accounts_panel.more": "Click to see {count, plural, one {# account} other {# accounts}}",
|
||||
"admin.latest_accounts_panel.title": "Latest Accounts",
|
||||
"admin.moderation_log.empty_message": "You have not performed any moderation actions yet. When you do, a history will be shown here.",
|
||||
"admin.relays.add.fail": "Failed to follow the instance relay",
|
||||
"admin.relays.add.success": "Instance relay followed",
|
||||
"admin.relays.deleted": "Relay unfollowed",
|
||||
"admin.relays.followed_back": "Followed back",
|
||||
"admin.relays.new.follow": "Follow",
|
||||
"admin.relays.new.url_placeholder": "Instance relay URL",
|
||||
"admin.relays.unfollow": "Unfollow",
|
||||
"admin.relays.url": "Instance URL:",
|
||||
"admin.reports.actions.close": "Close",
|
||||
"admin.reports.actions.view_status": "View post",
|
||||
"admin.reports.empty_message": "There are no open reports. If a user gets reported, they will show up here.",
|
||||
"admin.reports.report_closed_message": "Report on @{name} was closed",
|
||||
"admin.reports.report_title": "Report on {acct}",
|
||||
"admin.rule.priority": "Priority:",
|
||||
"admin.rules.action": "Create rule",
|
||||
"admin.rules.delete": "Delete",
|
||||
"admin.rules.edit": "Edit",
|
||||
"admin.software.backend": "Backend",
|
||||
"admin.software.frontend": "Frontend",
|
||||
"admin.statuses.actions.delete_status": "Delete post",
|
||||
|
@ -311,13 +331,17 @@
|
|||
"column.admin.awaiting_approval": "Awaiting Approval",
|
||||
"column.admin.create_announcement": "Create announcement",
|
||||
"column.admin.create_domain": "Create domaian",
|
||||
"column.admin.create_rule": "Create rule",
|
||||
"column.admin.dashboard": "Dashboard",
|
||||
"column.admin.domains": "Domains",
|
||||
"column.admin.edit_announcement": "Edit announcement",
|
||||
"column.admin.edit_domain": "Edit domain",
|
||||
"column.admin.edit_rule": "Edit rule",
|
||||
"column.admin.moderation_log": "Moderation Log",
|
||||
"column.admin.relays": "Instance relays",
|
||||
"column.admin.reports": "Reports",
|
||||
"column.admin.reports.menu.moderation_log": "Moderation Log",
|
||||
"column.admin.rules": "Instance rules",
|
||||
"column.admin.users": "Users",
|
||||
"column.aliases": "Account aliases",
|
||||
"column.aliases.create_error": "Error creating alias",
|
||||
|
@ -484,6 +508,9 @@
|
|||
"confirmations.admin.delete_domain.heading": "Delete domain",
|
||||
"confirmations.admin.delete_domain.message": "Are you sure you want to delete the domain?",
|
||||
"confirmations.admin.delete_local_user.checkbox": "I understand that I am about to delete a local user.",
|
||||
"confirmations.admin.delete_rule.confirm": "Delete",
|
||||
"confirmations.admin.delete_rule.heading": "Delete rule",
|
||||
"confirmations.admin.delete_rule.message": "Are you sure you want to delete the rule?",
|
||||
"confirmations.admin.delete_status.confirm": "Delete post",
|
||||
"confirmations.admin.delete_status.heading": "Delete post",
|
||||
"confirmations.admin.delete_status.message": "You are about to delete a post by @{acct}. This action cannot be undone.",
|
||||
|
@ -680,6 +707,8 @@
|
|||
"empty_column.account_unavailable": "Profile unavailable",
|
||||
"empty_column.admin.announcements": "There are no announcements yet.",
|
||||
"empty_column.admin.domains": "There are no domains yet.",
|
||||
"empty_column.admin.relays": "There are no relays followed yet.",
|
||||
"empty_column.admin.rules": "There are no instance rules yet.",
|
||||
"empty_column.aliases": "You haven't created any account alias yet.",
|
||||
"empty_column.aliases.suggestions": "There are no account suggestions available for the provided term.",
|
||||
"empty_column.blocks": "You haven't blocked any users yet.",
|
||||
|
|
|
@ -1,58 +0,0 @@
|
|||
import {
|
||||
Map as ImmutableMap,
|
||||
Record as ImmutableRecord,
|
||||
OrderedSet as ImmutableOrderedSet,
|
||||
} from 'immutable';
|
||||
|
||||
import { ADMIN_LOG_FETCH_SUCCESS } from 'soapbox/actions/admin';
|
||||
|
||||
import type { AnyAction } from 'redux';
|
||||
import type { APIEntity } from 'soapbox/types/entities';
|
||||
|
||||
export const LogEntryRecord = ImmutableRecord({
|
||||
data: ImmutableMap<string, any>(),
|
||||
id: 0,
|
||||
message: '',
|
||||
time: 0,
|
||||
});
|
||||
|
||||
const ReducerRecord = ImmutableRecord({
|
||||
items: ImmutableMap<string, LogEntry>(),
|
||||
index: ImmutableOrderedSet<number>(),
|
||||
total: 0,
|
||||
});
|
||||
|
||||
type LogEntry = ReturnType<typeof LogEntryRecord>;
|
||||
type State = ReturnType<typeof ReducerRecord>;
|
||||
type APIEntities = Array<APIEntity>;
|
||||
|
||||
const parseItems = (items: APIEntities) => {
|
||||
const ids: Array<number> = [];
|
||||
const map: Record<string, LogEntry> = {};
|
||||
|
||||
items.forEach(item => {
|
||||
ids.push(item.id);
|
||||
map[item.id] = LogEntryRecord(item);
|
||||
});
|
||||
|
||||
return { ids: ids, map: map };
|
||||
};
|
||||
|
||||
const importItems = (state: State, items: APIEntities, total: number) => {
|
||||
const { ids, map } = parseItems(items);
|
||||
|
||||
return state.withMutations(state => {
|
||||
state.update('index', v => v.union(ids));
|
||||
state.update('items', v => v.merge(map));
|
||||
state.set('total', total);
|
||||
});
|
||||
};
|
||||
|
||||
export default function admin_log(state = ReducerRecord(), action: AnyAction) {
|
||||
switch (action.type) {
|
||||
case ADMIN_LOG_FETCH_SUCCESS:
|
||||
return importItems(state, action.items, action.total);
|
||||
default:
|
||||
return state;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,6 @@ import entities from 'soapbox/entity-store/reducer';
|
|||
import accounts_meta from './accounts-meta';
|
||||
import admin from './admin';
|
||||
import admin_announcements from './admin-announcements';
|
||||
import admin_log from './admin-log';
|
||||
import admin_user_index from './admin-user-index';
|
||||
import aliases from './aliases';
|
||||
import announcements from './announcements';
|
||||
|
@ -68,7 +67,6 @@ const reducers = {
|
|||
accounts_meta,
|
||||
admin,
|
||||
admin_announcements,
|
||||
admin_log,
|
||||
admin_user_index,
|
||||
aliases,
|
||||
announcements,
|
||||
|
|
|
@ -12,10 +12,13 @@ export { groupRelationshipSchema, type GroupRelationship } from './group-relatio
|
|||
export { groupTagSchema, type GroupTag } from './group-tag';
|
||||
export { instanceSchema, type Instance } from './instance';
|
||||
export { mentionSchema, type Mention } from './mention';
|
||||
export { moderationLogEntrySchema, type ModerationLogEntry } from './moderation-log-entry';
|
||||
export { notificationSchema, type Notification } from './notification';
|
||||
export { patronUserSchema, type PatronUser } from './patron';
|
||||
export { pollSchema, type Poll, type PollOption } from './poll';
|
||||
export { relationshipSchema, type Relationship } from './relationship';
|
||||
export { relaySchema, type Relay } from './relay';
|
||||
export { ruleSchema, adminRuleSchema, type Rule, type AdminRule } from './rule';
|
||||
export { statusSchema, type Status } from './status';
|
||||
export { tagSchema, type Tag } from './tag';
|
||||
export { tombstoneSchema, type Tombstone } from './tombstone';
|
||||
|
|
12
src/schemas/moderation-log-entry.ts
Normal file
12
src/schemas/moderation-log-entry.ts
Normal file
|
@ -0,0 +1,12 @@
|
|||
import z from 'zod';
|
||||
|
||||
const moderationLogEntrySchema = z.object({
|
||||
id: z.coerce.string(),
|
||||
data: z.record(z.string(), z.any()).catch({}),
|
||||
time: z.number().catch(0),
|
||||
message: z.string().catch(''),
|
||||
});
|
||||
|
||||
type ModerationLogEntry = z.infer<typeof moderationLogEntrySchema>
|
||||
|
||||
export { moderationLogEntrySchema, type ModerationLogEntry };
|
13
src/schemas/relay.ts
Normal file
13
src/schemas/relay.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
import z from 'zod';
|
||||
|
||||
const relaySchema = z.preprocess((data: any) => {
|
||||
return { id: data.actor, ...data };
|
||||
}, z.object({
|
||||
actor: z.string().catch(''),
|
||||
id: z.string(),
|
||||
followed_back: z.boolean().catch(false),
|
||||
}));
|
||||
|
||||
type Relay = z.infer<typeof relaySchema>
|
||||
|
||||
export { relaySchema, type Relay };
|
|
@ -1,19 +1,25 @@
|
|||
import { z } from 'zod';
|
||||
|
||||
import { coerceObject } from './utils';
|
||||
const baseRuleSchema = z.object({
|
||||
id: z.string(),
|
||||
text: z.string().catch(''),
|
||||
hint: z.string().catch(''),
|
||||
rule_type: z.enum(['account', 'content', 'group']).nullable().catch(null),
|
||||
});
|
||||
|
||||
const ruleSchema = z.preprocess((data: any) => {
|
||||
return {
|
||||
...data,
|
||||
hint: data.hint || data.subtext,
|
||||
};
|
||||
}, coerceObject({
|
||||
id: z.string(),
|
||||
text: z.string().catch(''),
|
||||
hint: z.string().catch(''),
|
||||
rule_type: z.enum(['account', 'content', 'group']).nullable().catch(null),
|
||||
}));
|
||||
}, baseRuleSchema);
|
||||
|
||||
type Rule = z.infer<typeof ruleSchema>;
|
||||
|
||||
export { ruleSchema, type Rule };
|
||||
const adminRuleSchema = baseRuleSchema.extend({
|
||||
priority: z.number().nullable().catch(null),
|
||||
});
|
||||
|
||||
type AdminRule = z.infer<typeof adminRuleSchema>;
|
||||
|
||||
export { ruleSchema, adminRuleSchema, type Rule, type AdminRule };
|
|
@ -20,14 +20,12 @@ import {
|
|||
StatusRecord,
|
||||
TagRecord,
|
||||
} from 'soapbox/normalizers';
|
||||
import { LogEntryRecord } from 'soapbox/reducers/admin-log';
|
||||
import { Account as SchemaAccount } from 'soapbox/schemas';
|
||||
|
||||
import type { Record as ImmutableRecord } from 'immutable';
|
||||
import type { LegacyMap } from 'soapbox/utils/legacy';
|
||||
|
||||
type AdminAccount = ReturnType<typeof AdminAccountRecord>;
|
||||
type AdminLog = ReturnType<typeof LogEntryRecord>;
|
||||
type AdminReport = ReturnType<typeof AdminReportRecord>;
|
||||
type Announcement = ReturnType<typeof AnnouncementRecord>;
|
||||
type AnnouncementReaction = ReturnType<typeof AnnouncementReactionRecord>;
|
||||
|
@ -62,7 +60,6 @@ type EmbeddedEntity<T extends object> = null | string | ReturnType<ImmutableReco
|
|||
export {
|
||||
Account,
|
||||
AdminAccount,
|
||||
AdminLog,
|
||||
AdminReport,
|
||||
Announcement,
|
||||
AnnouncementReaction,
|
||||
|
|
|
@ -203,6 +203,15 @@ const getInstanceFeatures = (instance: Instance) => {
|
|||
*/
|
||||
adminFE: v.software === PLEROMA,
|
||||
|
||||
/**
|
||||
* Ability to manage instance rules by admins.
|
||||
* @see GET /api/v1/pleroma/admin/rules
|
||||
* @see POST /api/v1/pleroma/admin/rules
|
||||
* @see PATCH /api/v1/pleroma/admin/rules/:id
|
||||
* @see DELETE /api/v1/pleroma/admin/rules/:id
|
||||
*/
|
||||
adminRules: v.software === PLEROMA && v.build === REBASED && gte(v.version, '2.4.51'),
|
||||
|
||||
/**
|
||||
* Can display announcements set by admins.
|
||||
* @see GET /api/v1/announcements
|
||||
|
|
Loading…
Reference in a new issue