tooot/src/components/Timeline/Empty.tsx

86 lines
2.3 KiB
TypeScript
Raw Normal View History

2021-01-24 02:25:43 +01:00
import analytics from '@components/analytics'
2020-12-26 23:05:17 +01:00
import Button from '@components/Button'
import Icon from '@components/Icon'
2020-12-13 14:04:25 +01:00
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
2021-01-01 23:10:47 +01:00
import React, { useMemo } from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text, View } from 'react-native'
2021-02-08 23:47:20 +01:00
import { Circle } from 'react-native-animated-spinkit'
2021-01-01 23:10:47 +01:00
import { QueryStatus } from 'react-query'
2020-12-12 12:49:29 +01:00
export interface Props {
2020-12-13 01:24:25 +01:00
status: QueryStatus
2020-12-12 12:49:29 +01:00
refetch: () => void
}
2020-12-13 01:24:25 +01:00
const TimelineEmpty: React.FC<Props> = ({ status, refetch }) => {
2021-01-01 23:10:47 +01:00
const { mode, theme } = useTheme()
2021-01-19 01:13:45 +01:00
const { t, i18n } = useTranslation('componentTimeline')
2020-12-12 12:49:29 +01:00
2020-12-13 01:24:25 +01:00
const children = useMemo(() => {
switch (status) {
case 'loading':
return (
2021-02-08 23:47:20 +01:00
<Circle size={StyleConstants.Font.Size.L} color={theme.secondary} />
)
2020-12-13 01:24:25 +01:00
case 'error':
return (
<>
<Icon
name='Frown'
2020-12-13 01:24:25 +01:00
size={StyleConstants.Font.Size.L}
color={theme.primary}
/>
<Text style={[styles.error, { color: theme.primary }]}>
2021-01-01 23:10:47 +01:00
{t('empty.error.message')}
2020-12-13 01:24:25 +01:00
</Text>
2021-01-01 23:10:47 +01:00
<Button
type='text'
content={t('empty.error.button')}
2021-01-24 02:25:43 +01:00
onPress={() => {
analytics('timeline_error_press_refetch')
refetch()
}}
2021-01-01 23:10:47 +01:00
/>
2020-12-13 01:24:25 +01:00
</>
)
case 'success':
return (
<>
<Icon
name='Smartphone'
2020-12-13 01:24:25 +01:00
size={StyleConstants.Font.Size.L}
color={theme.primary}
/>
<Text style={[styles.error, { color: theme.primary }]}>
2021-01-01 23:10:47 +01:00
{t('empty.success.message')}
2020-12-13 01:24:25 +01:00
</Text>
</>
)
}
2021-01-01 23:10:47 +01:00
}, [mode, i18n.language, status])
2021-02-08 23:47:20 +01:00
return (
<View
style={[styles.base, { backgroundColor: theme.background }]}
children={children}
/>
)
2020-12-12 12:49:29 +01:00
}
const styles = StyleSheet.create({
base: {
flex: 1,
minHeight: '100%',
justifyContent: 'center',
alignItems: 'center'
},
error: {
...StyleConstants.FontStyle.M,
2020-12-12 12:49:29 +01:00
marginTop: StyleConstants.Spacing.S,
marginBottom: StyleConstants.Spacing.L
}
})
export default TimelineEmpty