adjust redirect

This commit is contained in:
Hailey
2024-06-19 17:17:10 -07:00
parent 05ad9b267f
commit 735801738a
2 changed files with 29 additions and 9 deletions
+18 -8
View File
@@ -8,6 +8,7 @@ import {useNavigation} from '@react-navigation/native'
import {NativeStackScreenProps} from '@react-navigation/native-stack'
import {useQueryClient} from '@tanstack/react-query'
import {logger} from '#/logger'
import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs'
import {HITSLOP_20} from 'lib/constants'
import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links'
@@ -262,25 +263,34 @@ function OverflowMenu({
const deleteDialogControl = useDialogControl()
const navigation = useNavigation<NavigationProp>()
const {
mutateAsync: deleteStarterPack,
mutate: deleteStarterPack,
isPending: isDeletePending,
error: deleteError,
} = useDeleteStarterPackMutation()
} = useDeleteStarterPackMutation({
onSuccess: () => {
logEvent('starterPack:delete', {})
deleteDialogControl.close(() => {
if (navigation.canGoBack()) {
navigation.popToTop()
} else {
navigation.navigate('Home')
}
})
},
onError: e => {
logger.error('Failed to delete starter pack', {safeMessage: e})
},
})
const isOwn = starterPack.creator.did === currentAccount?.did
const onDeleteStarterPack = async () => {
await deleteStarterPack({
deleteStarterPack({
rkey: routeParams.rkey,
// TODO need to fix types
listUri: starterPack.list!.uri,
})
logEvent('starterPack:delete', {})
deleteDialogControl.close(() => {
navigation.popToTop()
})
}
return (
+11 -1
View File
@@ -246,7 +246,13 @@ export function useEditStarterPackMutation({
})
}
export function useDeleteStarterPackMutation() {
export function useDeleteStarterPackMutation({
onSuccess,
onError,
}: {
onSuccess: () => void
onError: (error: Error) => void
}) {
const agent = useAgent()
const queryClient = useQueryClient()
@@ -277,6 +283,10 @@ export function useDeleteStarterPackMutation() {
did: agent.session!.did,
rkey,
})
onSuccess()
},
onError: async error => {
onError(error)
},
})
}