import React from 'react' import {CenteredView} from 'view/com/util/Views' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Text} from '#/components/Typography' import {View} from 'react-native' import {Button} from '#/components/Button' import {useNavigation} from '@react-navigation/core' import {NavigationProp} from 'lib/routes/types' import {StackActions} from '@react-navigation/native' import {router} from '#/routes' export function Error({ title, message, onRetry, }: { title?: string message?: string onRetry?: () => unknown }) { const navigation = useNavigation() const t = useTheme() const {gtMobile} = useBreakpoints() const canGoBack = navigation.canGoBack() const onGoBack = React.useCallback(() => { if (canGoBack) { navigation.goBack() } else { navigation.navigate('HomeTab') // Checking the state for routes ensures that web doesn't encounter errors while going back if (navigation.getState()?.routes) { navigation.dispatch(StackActions.push(...router.matchPath('/'))) } else { navigation.navigate('HomeTab') navigation.dispatch(StackActions.popToTop()) } } }, [navigation, canGoBack]) return ( {title} {message} {onRetry && ( )} ) }