From a77e495b6bc017b4fc7fa9d9a309b3cda23ec5b2 Mon Sep 17 00:00:00 2001 From: xmflsct Date: Thu, 29 Dec 2022 23:13:22 +0100 Subject: [PATCH] Fix admin options not showing up --- src/components/Instance/index.tsx | 2 +- src/screens/Tabs/Me/Push.tsx | 4 +- src/screens/Tabs/Notifications/Filters.tsx | 6 +- src/utils/push/constants.ts | 76 ++++++++++------------ src/utils/queryHooks/profile.ts | 6 +- 5 files changed, 48 insertions(+), 46 deletions(-) diff --git a/src/components/Instance/index.tsx b/src/components/Instance/index.tsx index 1b368a58..4ab99862 100644 --- a/src/components/Instance/index.tsx +++ b/src/components/Instance/index.tsx @@ -192,7 +192,7 @@ const ComponentInstance: React.FC = ({ const processUpdate = useCallback(() => { if (domain) { const accounts = getGlobalStorage.object('accounts') - if (accounts && accounts.filter(account => account.startsWith(`${domain}/`)).length) { + if (accounts?.filter(account => account.startsWith(`${domain}/`)).length) { Alert.alert( t('componentInstance:update.alert.title'), t('componentInstance:update.alert.message'), diff --git a/src/screens/Tabs/Me/Push.tsx b/src/screens/Tabs/Me/Push.tsx index 5a014699..be76f88d 100644 --- a/src/screens/Tabs/Me/Push.tsx +++ b/src/screens/Tabs/Me/Push.tsx @@ -66,7 +66,7 @@ const TabMePush: React.FC = () => { const alerts = () => push?.alerts - ? PUSH_DEFAULT.map(alert => ( + ? PUSH_DEFAULT().map(alert => ( { const profileQuery = useProfileQuery() const adminAlerts = () => profileQuery.data?.role?.permissions - ? PUSH_ADMIN.map(({ type }) => ( + ? PUSH_ADMIN().map(({ type }) => ( - {PUSH_DEFAULT.map((type, index) => ( + {PUSH_DEFAULT().map((type, index) => ( setFilters({ ...filters, [type]: !filters[type] })} /> ))} - {PUSH_ADMIN.map(({ type }) => ( + + + {PUSH_ADMIN().map(({ type }) => ( { - switch (type) { - case 'status': - return featureCheck('notification_type_status') - case 'update': - return featureCheck('notification_type_update') - default: - return true - } -}) as ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'update', 'status'] +export const PUSH_DEFAULT = () => + ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'update', 'status'].filter( + type => { + switch (type) { + case 'status': + return featureCheck('notification_type_status') + case 'update': + return featureCheck('notification_type_update') + default: + return true + } + } + ) as ['follow', 'follow_request', 'favourite', 'reblog', 'mention', 'poll', 'update', 'status'] -export const PUSH_ADMIN = [ - { type: 'admin.sign_up', permission: PERMISSION_MANAGE_USERS }, - { type: 'admin.report', permission: PERMISSION_MANAGE_REPORTS } -].filter(({ type, permission }) => { - const queryKeyProfile: QueryKeyProfile = ['Profile'] - const permissions = queryClient.getQueryData(queryKeyProfile)?.role?.permissions - switch (type) { - case 'admin.sign_up': - return ( - featureCheck('notification_type_admin_signup') && checkPermission(permission, permissions) - ) - case 'admin.report': - return ( - featureCheck('notification_type_admin_report') && checkPermission(permission, permissions) - ) - } -}) as { type: 'admin.sign_up' | 'admin.report'; permission: number }[] +export const PUSH_ADMIN = () => + [ + { type: 'admin.sign_up', permission: PERMISSION_MANAGE_USERS }, + { type: 'admin.report', permission: PERMISSION_MANAGE_REPORTS } + ].filter(({ type, permission }) => { + const queryKeyProfile: QueryKeyProfile = ['Profile'] + const permissions = + queryClient.getQueryData(queryKeyProfile)?.role?.permissions + switch (type) { + case 'admin.sign_up': + return ( + featureCheck('notification_type_admin_signup') && checkPermission(permission, permissions) + ) + case 'admin.report': + return ( + featureCheck('notification_type_admin_report') && checkPermission(permission, permissions) + ) + } + }) as { type: 'admin.sign_up' | 'admin.report'; permission: number }[] export const setChannels = async (reset: boolean | undefined = false, specificAccount?: string) => { const account = specificAccount || getGlobalStorage.string('account.active') @@ -76,18 +72,18 @@ export const setChannels = async (reset: boolean | undefined = false, specificAc if (!accountDetails.push.decode) { await setChannel('default') - for (const push of PUSH_DEFAULT) { + for (const push of PUSH_DEFAULT()) { await deleteChannel(push) } - for (const { type } of PUSH_ADMIN) { + for (const { type } of PUSH_ADMIN()) { await deleteChannel(type) } } else { await deleteChannel('default') - for (const push of PUSH_DEFAULT) { + for (const push of PUSH_DEFAULT()) { await setChannel(push) } - for (const { type } of PUSH_ADMIN) { + for (const { type } of PUSH_ADMIN()) { await setChannel(type) } } diff --git a/src/utils/queryHooks/profile.ts b/src/utils/queryHooks/profile.ts index 833a4f4b..35ee477d 100644 --- a/src/utils/queryHooks/profile.ts +++ b/src/utils/queryHooks/profile.ts @@ -26,7 +26,11 @@ const useProfileQuery = ( options: UseQueryOptions } | void ) => { - return useQuery(queryKey, queryFunctionProfile, params?.options) + return useQuery(queryKey, queryFunctionProfile, { + ...params?.options, + staleTime: Infinity, + cacheTime: Infinity + }) } type MutationVarsProfileBase =