tooot/src/components/Timelines/Timeline/Empty.tsx

77 lines
2.1 KiB
TypeScript
Raw Normal View History

2020-12-26 23:05:17 +01:00
import Button from '@components/Button'
import { Feather } from '@expo/vector-icons'
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'
import { Chase } from 'react-native-animated-spinkit'
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()
const { t, i18n } = useTranslation('timeline')
2020-12-12 12:49:29 +01:00
2020-12-13 01:24:25 +01:00
const children = useMemo(() => {
switch (status) {
case 'loading':
return (
<Chase size={StyleConstants.Font.Size.L} color={theme.secondary} />
)
2020-12-13 01:24:25 +01:00
case 'error':
return (
<>
<Feather
name='frown'
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')}
onPress={() => refetch()}
/>
2020-12-13 01:24:25 +01:00
</>
)
case 'success':
return (
<>
<Feather
name='smartphone'
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])
2020-12-13 01:24:25 +01:00
return <View style={styles.base} 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