From 707490f1f0fe0f5cdff7987c72793f3700aed714 Mon Sep 17 00:00:00 2001 From: Bruno Lemos Date: Tue, 4 Dec 2018 20:00:28 -0200 Subject: [PATCH] Show error message when column fetch fails --- .../src/components/cards/EmptyCards.tsx | 70 ++++++++++++++++--- .../src/components/cards/EventCards.tsx | 17 +++-- .../components/cards/NotificationCards.tsx | 27 +++++-- .../src/containers/EventCardsContainer.tsx | 13 +++- .../containers/NotificationCardsContainer.tsx | 15 +++- packages/core/src/types/devhub.ts | 1 + 6 files changed, 118 insertions(+), 25 deletions(-) diff --git a/packages/components/src/components/cards/EmptyCards.tsx b/packages/components/src/components/cards/EmptyCards.tsx index 1bcbd2c6..3531b360 100644 --- a/packages/components/src/components/cards/EmptyCards.tsx +++ b/packages/components/src/components/cards/EmptyCards.tsx @@ -1,5 +1,11 @@ import React from 'react' -import { ActivityIndicator, Text, View } from 'react-native' +import { + ActivityIndicator, + Text, + TextStyle, + View, + ViewStyle, +} from 'react-native' import { LoadState } from '@devhub/core/src/types' import { contentPadding } from '../../styles/variables' @@ -33,14 +39,64 @@ const clearMessage = getRandomClearMessage() const emoji = getRandomEmoji() export interface EmptyCardsProps { + errorMessage?: string fetchNextPage: ((params?: { perPage?: number }) => void) | undefined loadState: LoadState + refresh: (() => void | Promise) | undefined } export function EmptyCards(props: EmptyCardsProps) { const theme = useTheme() - const { fetchNextPage, loadState } = props + const { errorMessage, fetchNextPage, loadState, refresh } = props + + const hasError = errorMessage || loadState === 'error' + + const renderContent = () => { + if (loadState === 'loading_first') { + return + } + + const containerStyle: ViewStyle = { width: '100%', padding: contentPadding } + const textStyle: TextStyle = { + lineHeight: 20, + fontSize: 14, + color: theme.foregroundColorMuted50, + textAlign: 'center', + } + + if (hasError) { + return ( + + + {`⚠️\nSomething went wrong`} + {!!errorMessage && ( + {`\nError: ${errorMessage}`} + )} + + + {!!refresh && ( + +