nicolium: move some stuff away from actions
Signed-off-by: nicole mikołajczyk <git@mkljczk.pl>
This commit is contained in:
@ -4,24 +4,6 @@ import { queryKeys } from '@/queries/keys';
|
||||
import { useComposeStore } from '@/stores/compose';
|
||||
import { useModalsStore } from '@/stores/modals';
|
||||
|
||||
const promoteToAdmin = (accountId: string) => getClient().admin.accounts.promoteToAdmin(accountId);
|
||||
|
||||
const promoteToModerator = (accountId: string) =>
|
||||
getClient().admin.accounts.promoteToModerator(accountId);
|
||||
|
||||
const demoteToUser = (accountId: string) => getClient().admin.accounts.demoteToUser(accountId);
|
||||
|
||||
const setRole = (accountId: string, role: 'user' | 'moderator' | 'admin') => {
|
||||
switch (role) {
|
||||
case 'user':
|
||||
return demoteToUser(accountId);
|
||||
case 'moderator':
|
||||
return promoteToModerator(accountId);
|
||||
case 'admin':
|
||||
return promoteToAdmin(accountId);
|
||||
}
|
||||
};
|
||||
|
||||
const redactStatus = (statusId: string) => {
|
||||
const status = queryClient.getQueryData(queryKeys.statuses.show(statusId));
|
||||
if (!status) return;
|
||||
@ -40,4 +22,4 @@ const redactStatus = (statusId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
export { setRole, redactStatus };
|
||||
export { redactStatus };
|
||||
|
||||
@ -326,16 +326,6 @@ const toggleMuteStatus = (status: Pick<Status, 'id' | 'muted'>) =>
|
||||
// handleTranslateMany();
|
||||
// };
|
||||
|
||||
const unfilterStatus = (statusId: string) => {
|
||||
updateStatus(
|
||||
statusId,
|
||||
(status) => {
|
||||
status.showFiltered = true;
|
||||
},
|
||||
queryClient,
|
||||
);
|
||||
};
|
||||
|
||||
export {
|
||||
createStatus,
|
||||
editStatus,
|
||||
@ -343,5 +333,4 @@ export {
|
||||
deleteStatus,
|
||||
deleteStatusFromGroup,
|
||||
toggleMuteStatus,
|
||||
unfilterStatus,
|
||||
};
|
||||
|
||||
@ -3,7 +3,6 @@ import clsx from 'clsx';
|
||||
import React, { useEffect, useMemo, useRef } from 'react';
|
||||
import { defineMessages, useIntl, FormattedList, FormattedMessage } from 'react-intl';
|
||||
|
||||
import { unfilterStatus } from '@/actions/statuses';
|
||||
import Card from '@/components/ui/card';
|
||||
import Icon from '@/components/ui/icon';
|
||||
import Text from '@/components/ui/text';
|
||||
@ -24,7 +23,7 @@ import {
|
||||
import { useComposeActions } from '@/stores/compose';
|
||||
import { useModalsActions } from '@/stores/modals';
|
||||
import { useSettings } from '@/stores/settings';
|
||||
import { useStatusMetaActions } from '@/stores/status-meta';
|
||||
import { useStatusMeta, useStatusMetaActions } from '@/stores/status-meta';
|
||||
import { textForScreenReader } from '@/utils/status';
|
||||
|
||||
import HashtagLink from '../hashtag-link';
|
||||
@ -206,7 +205,8 @@ const Status: React.FC<IStatus> = React.memo((props) => {
|
||||
const router = useRouter();
|
||||
const features = useFeatures();
|
||||
|
||||
const { toggleStatusesMediaHidden } = useStatusMetaActions();
|
||||
const { toggleStatusesMediaHidden, unfilterStatus } = useStatusMetaActions();
|
||||
const { showFiltered } = useStatusMeta(status.id);
|
||||
const { openModal } = useModalsActions();
|
||||
const { replyCompose, mentionCompose } = useComposeActions();
|
||||
const { boostModal } = useSettings();
|
||||
@ -524,7 +524,7 @@ const Status: React.FC<IStatus> = React.memo((props) => {
|
||||
if (status.deleted)
|
||||
return <Tombstone id={status.id} onMoveUp={onMoveUp} onMoveDown={onMoveDown} deleted />;
|
||||
|
||||
if (filtered && actualStatus.showFiltered !== true) {
|
||||
if (filtered && showFiltered !== true) {
|
||||
const body = (
|
||||
<div className={clsx('status__wrapper text-center')} ref={node}>
|
||||
<Text theme='muted'>
|
||||
|
||||
@ -134,7 +134,6 @@ const normalizeStatus = (
|
||||
poll_id: poll?.id ?? null,
|
||||
group_id: group?.id ?? null,
|
||||
expectsCard: false,
|
||||
showFiltered: null as null | boolean,
|
||||
deleted: false,
|
||||
...status,
|
||||
quote_id: status.quote_id ?? null,
|
||||
|
||||
@ -2,7 +2,6 @@ import { PLEROMA } from 'pl-api';
|
||||
import React, { type ChangeEventHandler, useMemo, useState } from 'react';
|
||||
import { defineMessages, FormattedMessage, type MessageDescriptor, useIntl } from 'react-intl';
|
||||
|
||||
import { setRole } from '@/actions/admin';
|
||||
import { useDeactivateUserModal, useDeleteUserModal } from '@/actions/moderation';
|
||||
import Account from '@/components/accounts/account';
|
||||
import List, { ListItem } from '@/components/list';
|
||||
@ -19,7 +18,7 @@ import { adminAccountRoute } from '@/features/ui/router';
|
||||
import { useFeatures } from '@/hooks/use-features';
|
||||
import { useOwnAccount } from '@/hooks/use-own-account';
|
||||
import { useAccount } from '@/queries/accounts/use-account';
|
||||
import { useAdminUpdateTagsMutation } from '@/queries/admin/use-accounts';
|
||||
import { useAdminSetRoleMutation, useAdminUpdateTagsMutation } from '@/queries/admin/use-accounts';
|
||||
import {
|
||||
useAdminSuggestAccountMutation,
|
||||
useAdminUnsuggestAccountMutation,
|
||||
@ -94,6 +93,8 @@ interface IStaffRolePicker {
|
||||
const StaffRolePicker: React.FC<IStaffRolePicker> = ({ account }) => {
|
||||
const intl = useIntl();
|
||||
|
||||
const { mutate: adminSetRole } = useAdminSetRoleMutation(account.id);
|
||||
|
||||
const roles: Record<AccountRole, string> = useMemo(
|
||||
() => ({
|
||||
user: intl.formatMessage(messages.roleUser),
|
||||
@ -106,8 +107,8 @@ const StaffRolePicker: React.FC<IStaffRolePicker> = ({ account }) => {
|
||||
const handleRoleChange: React.ChangeEventHandler<HTMLSelectElement> = (e) => {
|
||||
const role = e.target.value as AccountRole;
|
||||
|
||||
setRole(account.id, role)
|
||||
.then(() => {
|
||||
adminSetRole(role, {
|
||||
onSuccess: () => {
|
||||
let message: MessageDescriptor | undefined;
|
||||
|
||||
if (role === 'admin') {
|
||||
@ -123,8 +124,8 @@ const StaffRolePicker: React.FC<IStaffRolePicker> = ({ account }) => {
|
||||
if (message) {
|
||||
toast.success(intl.formatMessage(message, { acct: account.acct }));
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const accountRole = getRole(account);
|
||||
|
||||
@ -266,6 +266,28 @@ const useAdminUpdateTagsMutation = (accountId: string) => {
|
||||
});
|
||||
};
|
||||
|
||||
const useAdminSetRoleMutation = (accountId: string) => {
|
||||
const client = useClient();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationKey: ['admin', 'acounts', accountId, 'setRole'],
|
||||
mutationFn: (role: 'user' | 'moderator' | 'admin') => {
|
||||
switch (role) {
|
||||
case 'user':
|
||||
return client.admin.accounts.demoteToUser(accountId);
|
||||
case 'moderator':
|
||||
return client.admin.accounts.promoteToModerator(accountId);
|
||||
case 'admin':
|
||||
return client.admin.accounts.promoteToAdmin(accountId);
|
||||
}
|
||||
},
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: queryKeys.accounts.show(accountId) });
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export {
|
||||
useAdminAccount,
|
||||
useAdminAccounts,
|
||||
@ -281,4 +303,5 @@ export {
|
||||
useAdminTagUserMutation,
|
||||
useAdminUntagUserMutation,
|
||||
useAdminUpdateTagsMutation,
|
||||
useAdminSetRoleMutation,
|
||||
};
|
||||
|
||||
@ -11,6 +11,7 @@ type State = {
|
||||
targetLanguage?: string;
|
||||
localTargetLanguage?: string;
|
||||
showPollResults?: boolean;
|
||||
showFiltered?: boolean;
|
||||
}
|
||||
>;
|
||||
actions: {
|
||||
@ -25,6 +26,7 @@ type State = {
|
||||
hideLocalTranslation: (statusId: string) => void;
|
||||
setStatusLanguage: (statusId: string, language: string) => void;
|
||||
toggleShowPollResults: (statusId: string) => void;
|
||||
unfilterStatus: (statusId: string) => void;
|
||||
};
|
||||
};
|
||||
|
||||
@ -117,6 +119,13 @@ const useStatusMetaStore = create<State>()(
|
||||
state.statuses[statusId].showPollResults = !state.statuses[statusId].showPollResults;
|
||||
});
|
||||
},
|
||||
unfilterStatus: (statusId) => {
|
||||
set((state: State) => {
|
||||
if (!state.statuses[statusId]) state.statuses[statusId] = {};
|
||||
|
||||
state.statuses[statusId].showFiltered = true;
|
||||
});
|
||||
},
|
||||
},
|
||||
})),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user