1
0
mirror of https://github.com/tooot-app/app synced 2025-06-05 22:19:13 +02:00

Believe #638 can be closed now!

This commit is contained in:
xmflsct
2023-01-04 22:39:29 +01:00
parent 62a6594f91
commit 06324ee51a
34 changed files with 278 additions and 346 deletions

View File

@ -3,7 +3,7 @@ import { displayMessage } from '@components/Message'
import { useNavigation } from '@react-navigation/native'
import { NativeStackNavigationProp } from '@react-navigation/native-stack'
import { useQueryClient } from '@tanstack/react-query'
import { TabSharedStackParamList } from '@utils/navigation/navigators'
import { TabSharedStackParamList, useNavState } from '@utils/navigation/navigators'
import { useAccountQuery } from '@utils/queryHooks/account'
import {
QueryKeyRelationship,
@ -12,7 +12,6 @@ import {
} from '@utils/queryHooks/relationship'
import {
MutationVarsTimelineUpdateAccountProperty,
QueryKeyTimeline,
useTimelineMutation
} from '@utils/queryHooks/timeline'
import { useAccountStorage } from '@utils/storage/actions'
@ -24,19 +23,16 @@ const menuAccount = ({
type,
openChange,
account,
status,
queryKey,
rootQueryKey
status
}: {
type: 'status' | 'account' // Where the action is coming from
openChange: boolean
account?: Partial<Mastodon.Account> & Pick<Mastodon.Account, 'id' | 'username' | 'acct' | 'url'>
status?: Mastodon.Status
queryKey?: QueryKeyTimeline
rootQueryKey?: QueryKeyTimeline
}): ContextMenu[][] => {
const navigation =
useNavigation<NativeStackNavigationProp<TabSharedStackParamList, any, undefined>>()
const navState = useNavState()
const { t } = useTranslation(['common', 'componentContextMenu', 'componentRelationship'])
const menus: ContextMenu[][] = [[]]
@ -101,8 +97,9 @@ const menuAccount = ({
})
},
onSettled: () => {
queryKey && queryClient.invalidateQueries(queryKey)
rootQueryKey && queryClient.invalidateQueries(rootQueryKey)
for (const key of navState) {
queryClient.invalidateQueries(key)
}
}
})
const queryKeyRelationship: QueryKeyRelationship = ['Relationship', { id: actualAccount?.id }]
@ -111,8 +108,10 @@ const menuAccount = ({
haptics('Success')
queryClient.setQueryData<Mastodon.Relationship[]>(queryKeyRelationship, [res])
if (action === 'block') {
const queryKey = ['Timeline', { page: 'Following' }]
queryClient.invalidateQueries({ queryKey, exact: false })
queryClient.invalidateQueries({
queryKey: ['Timeline', { page: 'Following' }],
exact: false
})
}
},
onError: (err: any, { payload: { action } }) => {
@ -203,7 +202,6 @@ const menuAccount = ({
actualAccount &&
timelineMutation.mutate({
type: 'updateAccountProperty',
queryKey,
id: actualAccount.id,
payload: { property: 'mute', currentValue: data?.muting }
}),
@ -236,7 +234,6 @@ const menuAccount = ({
actualAccount &&
timelineMutation.mutate({
type: 'updateAccountProperty',
queryKey,
id: actualAccount.id,
payload: { property: 'block', currentValue: data?.blocking }
})

View File

@ -8,12 +8,10 @@ import parse from 'url-parse'
const menuInstance = ({
status,
queryKey,
rootQueryKey
queryKey
}: {
status?: Mastodon.Status
queryKey?: QueryKeyTimeline
rootQueryKey?: QueryKeyTimeline
}): ContextMenu[][] => {
if (!status || !queryKey) return []
@ -29,7 +27,6 @@ const menuInstance = ({
})
})
queryClient.invalidateQueries(queryKey)
rootQueryKey && queryClient.invalidateQueries(rootQueryKey)
}
})
@ -51,11 +48,7 @@ const menuInstance = ({
text: t('common:buttons.confirm'),
style: 'destructive',
onPress: () => {
mutation.mutate({
type: 'domainBlock',
queryKey,
domain: instance
})
mutation.mutate({ type: 'domainBlock', domain: instance })
}
},
{

View File

@ -4,7 +4,7 @@ import { NativeStackNavigationProp } from '@react-navigation/native-stack'
import { useQueryClient } from '@tanstack/react-query'
import apiInstance from '@utils/api/instance'
import { featureCheck } from '@utils/helpers/featureCheck'
import { RootStackParamList } from '@utils/navigation/navigators'
import { RootStackParamList, useNavState } from '@utils/navigation/navigators'
import {
MutationVarsTimelineUpdateStatusProperty,
QueryKeyTimeline,
@ -17,12 +17,10 @@ import { Alert } from 'react-native'
const menuStatus = ({
status,
queryKey,
rootQueryKey
queryKey
}: {
status?: Mastodon.Status
queryKey?: QueryKeyTimeline
rootQueryKey?: QueryKeyTimeline
}): ContextMenu[][] => {
if (!status || !queryKey) return []
@ -30,6 +28,8 @@ const menuStatus = ({
const { theme } = useTheme()
const { t } = useTranslation(['common', 'componentContextMenu'])
const navigationState = useNavState()
const queryClient = useQueryClient()
const mutation = useTimelineMutation({
onMutate: true,
@ -90,8 +90,7 @@ const menuStatus = ({
spoiler_text: res.body.spoiler_text
},
...(replyToStatus && { replyToStatus }),
queryKey,
rootQueryKey
navigationState
})
})
},
@ -122,18 +121,13 @@ const menuStatus = ({
}).then(res => res.body)
}
mutation
.mutateAsync({
type: 'deleteItem',
source: 'statuses',
queryKey,
id: status.id
})
.mutateAsync({ type: 'deleteItem', source: 'statuses', id: status.id })
.then(res => {
navigation.navigate('Screen-Compose', {
type: 'deleteEdit',
incomingStatus: res.body as Mastodon.Status,
...(replyToStatus && { replyToStatus }),
queryKey
navigationState
})
})
}
@ -162,13 +156,7 @@ const menuStatus = ({
text: t('common:buttons.confirm'),
style: 'destructive',
onPress: async () => {
mutation.mutate({
type: 'deleteItem',
source: 'statuses',
queryKey,
rootQueryKey,
id: status.id
})
mutation.mutate({ type: 'deleteItem', source: 'statuses', id: status.id })
}
},
{
@ -193,8 +181,6 @@ const menuStatus = ({
onSelect: () =>
mutation.mutate({
type: 'updateStatusProperty',
queryKey,
rootQueryKey,
status,
payload: {
type: 'muted',
@ -218,8 +204,6 @@ const menuStatus = ({
// Also note that reblogs cannot be pinned.
mutation.mutate({
type: 'updateStatusProperty',
queryKey,
rootQueryKey,
status,
payload: {
type: 'pinned',