diff options
author | Hailey <me@haileyok.com> | 2024-08-20 15:43:40 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-20 15:43:40 -0700 |
commit | 723896a45f0fdf9612e5b6bb2a82ac7e894928ba (patch) | |
tree | 3822c9fa69da8d9ad771a2da49c69af9ca435669 /src/components/Error.tsx | |
parent | e54298ec2c9a04aabe40ee7719962e2e33be23ec (diff) | |
download | voidsky-723896a45f0fdf9612e5b6bb2a82ac7e894928ba.tar.zst |
Add `list hidden` screen (#4958)
Co-authored-by: Hailey <me@haileyok.com> Co-authored-by: Eric Bailey <git@esb.lol>
Diffstat (limited to 'src/components/Error.tsx')
-rw-r--r-- | src/components/Error.tsx | 32 |
1 files changed, 4 insertions, 28 deletions
diff --git a/src/components/Error.tsx b/src/components/Error.tsx index 481532434..59d219831 100644 --- a/src/components/Error.tsx +++ b/src/components/Error.tsx @@ -2,21 +2,18 @@ import React from 'react' import {View} from 'react-native' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' -import {useNavigation} from '@react-navigation/core' -import {StackActions} from '@react-navigation/native' -import {NavigationProp} from 'lib/routes/types' +import {useGoBack} from 'lib/hooks/useGoBack' import {CenteredView} from 'view/com/util/Views' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {Button, ButtonText} from '#/components/Button' import {Text} from '#/components/Typography' -import {router} from '#/routes' export function Error({ title, message, onRetry, - onGoBack: onGoBackProp, + onGoBack, hideBackButton, sideBorders = true, }: { @@ -27,31 +24,10 @@ export function Error({ hideBackButton?: boolean sideBorders?: boolean }) { - const navigation = useNavigation<NavigationProp>() const {_} = useLingui() const t = useTheme() const {gtMobile} = useBreakpoints() - - const canGoBack = navigation.canGoBack() - const onGoBack = React.useCallback(() => { - if (onGoBackProp) { - onGoBackProp() - return - } - 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, onGoBackProp]) + const goBack = useGoBack(onGoBack) return ( <CenteredView @@ -96,7 +72,7 @@ export function Error({ variant="solid" color={onRetry ? 'secondary' : 'primary'} label={_(msg`Return to previous page`)} - onPress={onGoBack} + onPress={goBack} size="large" style={[a.rounded_sm, a.overflow_hidden, {paddingVertical: 10}]}> <ButtonText> |