Improve error handling on Explore page (#9890)
This commit is contained in:
@@ -78,10 +78,14 @@ function LoadMore({item}: {item: ExploreScreenItems & {type: 'loadMore'}}) {
|
||||
const t = useTheme()
|
||||
const {_} = useLingui()
|
||||
|
||||
const handleOnPress = () => {
|
||||
void item.onLoadMore()
|
||||
}
|
||||
|
||||
return (
|
||||
<Button
|
||||
label={_(msg`Load more`)}
|
||||
onPress={item.onLoadMore}
|
||||
onPress={handleOnPress}
|
||||
style={[a.relative, a.w_full]}>
|
||||
{({hovered, pressed}) => (
|
||||
<>
|
||||
@@ -171,7 +175,7 @@ type ExploreScreenItems =
|
||||
key: string
|
||||
message: string
|
||||
isLoadingMore: boolean
|
||||
onLoadMore: () => void
|
||||
onLoadMore: () => void | Promise<void>
|
||||
}
|
||||
| {
|
||||
type: 'profilePlaceholder'
|
||||
@@ -358,7 +362,7 @@ export function Explore({
|
||||
i.push({
|
||||
type: 'tabbedHeader',
|
||||
key: 'suggested-accounts-header',
|
||||
title: _(msg`Suggested Accounts`),
|
||||
title: _(msg`Suggested accounts`),
|
||||
icon: Person,
|
||||
searchButton: {
|
||||
label: _(msg`Search for more accounts`),
|
||||
@@ -435,7 +439,7 @@ export function Explore({
|
||||
i.push({
|
||||
type: 'header',
|
||||
key: 'suggested-feeds-header',
|
||||
title: _(msg`Discover New Feeds`),
|
||||
title: _(msg`Discover new feeds`),
|
||||
icon: ListSparkle,
|
||||
searchButton: {
|
||||
label: _(msg`Search for more feeds`),
|
||||
@@ -463,9 +467,9 @@ export function Explore({
|
||||
if (suggestedFeedsError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'feedsError',
|
||||
key: 'suggestedFeedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
error: cleanError(feedsError),
|
||||
error: cleanError(suggestedFeedsError),
|
||||
})
|
||||
} else if (preferencesError) {
|
||||
i.push({
|
||||
@@ -512,9 +516,16 @@ export function Explore({
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'feedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
message: _(msg`Failed to load feeds`),
|
||||
error: cleanError(feedsError),
|
||||
})
|
||||
} else if (suggestedFeedsError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'suggestedFeedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
error: cleanError(suggestedFeedsError),
|
||||
})
|
||||
} else if (preferencesError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
@@ -550,9 +561,16 @@ export function Explore({
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'feedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
message: _(msg`Failed to load feeds`),
|
||||
error: cleanError(feedsError),
|
||||
})
|
||||
} else if (suggestedFeedsError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'suggestedFeedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
error: cleanError(suggestedFeedsError),
|
||||
})
|
||||
} else if (preferencesError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
@@ -589,9 +607,16 @@ export function Explore({
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'feedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
message: _(msg`Failed to load feeds`),
|
||||
error: cleanError(feedsError),
|
||||
})
|
||||
} else if (suggestedFeedsError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
key: 'feedsError',
|
||||
message: _(msg`Failed to load suggested feeds`),
|
||||
error: cleanError(suggestedFeedsError),
|
||||
})
|
||||
} else if (preferencesError) {
|
||||
i.push({
|
||||
type: 'error',
|
||||
@@ -714,6 +739,9 @@ export function Explore({
|
||||
|
||||
const renderItem = useCallback(
|
||||
({item, index}: {item: ExploreScreenItems; index: number}) => {
|
||||
const handleOnPressRetry = () => {
|
||||
void fetchNextPageFeedPreviews()
|
||||
}
|
||||
switch (item.type) {
|
||||
case 'topBorder':
|
||||
return (
|
||||
@@ -987,7 +1015,7 @@ export function Explore({
|
||||
label={_(
|
||||
msg`There was an issue fetching posts. Tap here to try again.`,
|
||||
)}
|
||||
onPress={fetchNextPageFeedPreviews}
|
||||
onPress={handleOnPressRetry}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1069,6 +1097,14 @@ export function Explore({
|
||||
[ax, suggestedFollowsModule],
|
||||
)
|
||||
|
||||
const handleOnEndReached = () => {
|
||||
void onLoadMoreFeedPreviews()
|
||||
}
|
||||
|
||||
const handleOnRefresh = () => {
|
||||
void onPTR()
|
||||
}
|
||||
|
||||
return (
|
||||
<List
|
||||
data={items}
|
||||
@@ -1081,7 +1117,7 @@ export function Explore({
|
||||
stickyHeaderIndices={native(stickyHeaderIndices)}
|
||||
viewabilityConfig={viewabilityConfig}
|
||||
onItemSeen={onItemSeen}
|
||||
onEndReached={onLoadMoreFeedPreviews}
|
||||
onEndReached={handleOnEndReached}
|
||||
/**
|
||||
* Default: 2
|
||||
*/
|
||||
@@ -1117,7 +1153,7 @@ export function Explore({
|
||||
*/
|
||||
updateCellsBatchingPeriod={50}
|
||||
refreshing={isPTR}
|
||||
onRefresh={onPTR}
|
||||
onRefresh={handleOnRefresh}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user