2020-12-26 23:05:17 +01:00
|
|
|
import Button from '@components/Button'
|
2021-01-03 02:00:26 +01:00
|
|
|
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'
|
|
|
|
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':
|
2020-12-27 00:32:51 +01:00
|
|
|
return (
|
|
|
|
<Chase size={StyleConstants.Font.Size.L} color={theme.secondary} />
|
|
|
|
)
|
2020-12-13 01:24:25 +01:00
|
|
|
case 'error':
|
|
|
|
return (
|
|
|
|
<>
|
2021-01-03 02:00:26 +01:00
|
|
|
<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')}
|
|
|
|
onPress={() => refetch()}
|
|
|
|
/>
|
2020-12-13 01:24:25 +01:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
case 'success':
|
|
|
|
return (
|
|
|
|
<>
|
2021-01-03 02:00:26 +01:00
|
|
|
<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])
|
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: {
|
2020-12-29 00:21:05 +01:00
|
|
|
...StyleConstants.FontStyle.M,
|
2020-12-12 12:49:29 +01:00
|
|
|
marginTop: StyleConstants.Spacing.S,
|
|
|
|
marginBottom: StyleConstants.Spacing.L
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export default TimelineEmpty
|