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