adjust redirect
This commit is contained in:
@@ -8,6 +8,7 @@ import {useNavigation} from '@react-navigation/native'
|
|||||||
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
import {NativeStackScreenProps} from '@react-navigation/native-stack'
|
||||||
import {useQueryClient} from '@tanstack/react-query'
|
import {useQueryClient} from '@tanstack/react-query'
|
||||||
|
|
||||||
|
import {logger} from '#/logger'
|
||||||
import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs'
|
import {useDeleteStarterPackMutation} from '#/state/queries/starter-packs'
|
||||||
import {HITSLOP_20} from 'lib/constants'
|
import {HITSLOP_20} from 'lib/constants'
|
||||||
import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links'
|
import {makeProfileLink, makeStarterPackLink} from 'lib/routes/links'
|
||||||
@@ -262,25 +263,34 @@ function OverflowMenu({
|
|||||||
const deleteDialogControl = useDialogControl()
|
const deleteDialogControl = useDialogControl()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const {
|
const {
|
||||||
mutateAsync: deleteStarterPack,
|
mutate: deleteStarterPack,
|
||||||
isPending: isDeletePending,
|
isPending: isDeletePending,
|
||||||
error: deleteError,
|
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 isOwn = starterPack.creator.did === currentAccount?.did
|
||||||
|
|
||||||
const onDeleteStarterPack = async () => {
|
const onDeleteStarterPack = async () => {
|
||||||
await deleteStarterPack({
|
deleteStarterPack({
|
||||||
rkey: routeParams.rkey,
|
rkey: routeParams.rkey,
|
||||||
// TODO need to fix types
|
// TODO need to fix types
|
||||||
listUri: starterPack.list!.uri,
|
listUri: starterPack.list!.uri,
|
||||||
})
|
})
|
||||||
|
|
||||||
logEvent('starterPack:delete', {})
|
logEvent('starterPack:delete', {})
|
||||||
|
|
||||||
deleteDialogControl.close(() => {
|
|
||||||
navigation.popToTop()
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -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 agent = useAgent()
|
||||||
const queryClient = useQueryClient()
|
const queryClient = useQueryClient()
|
||||||
|
|
||||||
@@ -277,6 +283,10 @@ export function useDeleteStarterPackMutation() {
|
|||||||
did: agent.session!.did,
|
did: agent.session!.did,
|
||||||
rkey,
|
rkey,
|
||||||
})
|
})
|
||||||
|
onSuccess()
|
||||||
|
},
|
||||||
|
onError: async error => {
|
||||||
|
onError(error)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user