From addd66b37f922fda12a99298a37a0166cf509f89 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 19 Mar 2024 12:10:10 -0700 Subject: `PostThread` cleanup (#3183) * cleanup PostThread rm some more unnecessary code cleanup some more pieces fix `isLoading` logic few fixes organize refactor `PostThread` allow chaining of `postThreadQuery` Update `Hashtag` screen with the component changes Make some changes to the List components adjust height and padding of bottom loader to account for bottom bar * rm unnecessary chaining logic * maxReplies logic * adjust error logic * use `<` instead of `<=` * add back warning comment * remove unused prop * adjust order * update prop name * don't show error if `isLoading` --- src/components/Lists.tsx | 177 +++++++++++++++++------------------------------ 1 file changed, 64 insertions(+), 113 deletions(-) (limited to 'src/components/Lists.tsx') diff --git a/src/components/Lists.tsx b/src/components/Lists.tsx index 8a889c15e..a74484b71 100644 --- a/src/components/Lists.tsx +++ b/src/components/Lists.tsx @@ -1,26 +1,28 @@ import React from 'react' import {atoms as a, useBreakpoints, useTheme} from '#/alf' import {View} from 'react-native' +import {useLingui} from '@lingui/react' + import {CenteredView} from 'view/com/util/Views' import {Loader} from '#/components/Loader' -import {Trans} from '@lingui/macro' +import {msg, 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' +import {Error} from '#/components/Error' export function ListFooter({ isFetching, isError, error, onRetry, + height, }: { - isFetching: boolean - isError: boolean + isFetching?: boolean + isError?: boolean error?: string onRetry?: () => Promise + height?: number }) { const t = useTheme() @@ -29,11 +31,10 @@ export function ListFooter({ style={[ a.w_full, a.align_center, - a.justify_center, a.border_t, a.pb_lg, t.atoms.border_contrast_low, - {height: 180}, + {height: height ?? 180, paddingTop: 30}, ]}> {isFetching ? ( @@ -53,7 +54,7 @@ function ListFooterMaybeError({ error, onRetry, }: { - isError: boolean + isError?: boolean error?: string onRetry?: () => Promise }) { @@ -128,121 +129,71 @@ export function ListMaybePlaceholder({ isLoading, isEmpty, isError, - empty, - error, - notFoundType = 'page', + emptyTitle, + emptyMessage, + errorTitle, + errorMessage, + emptyType = 'page', onRetry, }: { isLoading: boolean - isEmpty: boolean - isError: boolean - empty?: string - error?: string - notFoundType?: 'page' | 'results' + isEmpty?: boolean + isError?: boolean + emptyTitle?: string + emptyMessage?: string + errorTitle?: string + errorMessage?: string + emptyType?: 'page' | 'results' onRetry?: () => Promise }) { - const navigation = useNavigationDeduped() const t = useTheme() + const {_} = useLingui() 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 (!isLoading && isError) { + return ( + + ) + } - if (!isEmpty) return null - - return ( - - {isLoading ? ( + if (isLoading) { + return ( + - ) : ( - <> - - - {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 && ( - - )} - - - - )} - - ) + if (isEmpty) { + return ( + + ) + } } -- cgit 1.4.1