import React from 'react' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {View} from 'react-native' import {CenteredView} from 'view/com/util/Views' import {Loader} from '#/components/Loader' import {Trans} from '@lingui/macro' import {cleanError} from 'lib/strings/errors' import {Button} from '#/components/Button' import {Text} from '#/components/Typography' import {StackActions} from '@react-navigation/native' import {router} from '#/routes' import {useNavigationDeduped} from 'lib/hooks/useNavigationDeduped' export function ListFooter({ isFetching, isError, error, onRetry, }: { isFetching: boolean isError: boolean error?: string onRetry?: () => Promise }) { const t = useTheme() return ( {isFetching ? ( ) : ( )} ) } function ListFooterMaybeError({ isError, error, onRetry, }: { isError: boolean error?: string onRetry?: () => Promise }) { const t = useTheme() if (!isError) return null return ( {error ? ( cleanError(error) ) : ( Oops, something went wrong! )} ) } export function ListHeaderDesktop({ title, subtitle, }: { title: string subtitle?: string }) { const {gtTablet} = useBreakpoints() const t = useTheme() if (!gtTablet) return null return ( {title} {subtitle ? ( {subtitle} ) : undefined} ) } export function ListMaybePlaceholder({ isLoading, isEmpty, isError, empty, error, notFoundType = 'page', onRetry, }: { isLoading: boolean isEmpty: boolean isError: boolean empty?: string error?: string notFoundType?: 'page' | 'results' onRetry?: () => Promise }) { const navigation = useNavigationDeduped() const t = useTheme() const {gtMobile, gtTablet} = 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]) if (!isEmpty) return null return ( {isLoading ? ( ) : ( <> {isError ? ( Oops! ) : isEmpty ? ( <> {notFoundType === 'results' ? ( No results found ) : ( Page not found )} ) : undefined} {isError ? ( {error ? error : Something went wrong!} ) : isEmpty ? ( {empty ? ( empty ) : ( We're sorry! We can't find the page you were looking for. )} ) : undefined} {isError && onRetry && ( )} )} ) }