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'
|
2021-01-03 02:00:26 +01:00
|
|
|
import Icon from '@components/Icon'
|
2021-02-27 16:33:54 +01:00
|
|
|
import { QueryKeyTimeline, useTimelineQuery } from '@utils/queryHooks/timeline'
|
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'
|
2020-12-12 12:49:29 +01:00
|
|
|
|
|
|
|
export interface Props {
|
2021-02-27 16:33:54 +01:00
|
|
|
queryKey: QueryKeyTimeline
|
2020-12-12 12:49:29 +01:00
|
|
|
}
|
|
|
|
|
2021-02-27 16:33:54 +01:00
|
|
|
const TimelineEmpty = React.memo(
|
|
|
|
({ queryKey }: Props) => {
|
|
|
|
const { status, refetch } = useTimelineQuery({
|
|
|
|
...queryKey[1],
|
|
|
|
options: { notifyOnChangeProps: ['status'] }
|
|
|
|
})
|
2020-12-12 12:49:29 +01:00
|
|
|
|
2022-02-12 14:51:01 +01:00
|
|
|
const { colors, theme } = useTheme()
|
2021-02-27 16:33:54 +01:00
|
|
|
const { t, i18n } = useTranslation('componentTimeline')
|
|
|
|
|
|
|
|
const children = useMemo(() => {
|
|
|
|
switch (status) {
|
|
|
|
case 'loading':
|
|
|
|
return (
|
2022-02-12 14:51:01 +01:00
|
|
|
<Circle
|
|
|
|
size={StyleConstants.Font.Size.L}
|
|
|
|
color={colors.secondary}
|
|
|
|
/>
|
2021-02-27 16:33:54 +01:00
|
|
|
)
|
|
|
|
case 'error':
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Icon
|
|
|
|
name='Frown'
|
|
|
|
size={StyleConstants.Font.Size.L}
|
2022-02-12 14:51:01 +01:00
|
|
|
color={colors.primaryDefault}
|
2021-02-27 16:33:54 +01:00
|
|
|
/>
|
2022-02-12 14:51:01 +01:00
|
|
|
<Text style={[styles.error, { color: colors.primaryDefault }]}>
|
2021-02-27 16:33:54 +01:00
|
|
|
{t('empty.error.message')}
|
|
|
|
</Text>
|
|
|
|
<Button
|
|
|
|
type='text'
|
|
|
|
content={t('empty.error.button')}
|
|
|
|
onPress={() => {
|
|
|
|
analytics('timeline_error_press_refetch')
|
|
|
|
refetch()
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
case 'success':
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Icon
|
|
|
|
name='Smartphone'
|
|
|
|
size={StyleConstants.Font.Size.L}
|
2022-02-12 14:51:01 +01:00
|
|
|
color={colors.primaryDefault}
|
2021-02-27 16:33:54 +01:00
|
|
|
/>
|
2022-02-12 14:51:01 +01:00
|
|
|
<Text style={[styles.error, { color: colors.primaryDefault }]}>
|
2021-02-27 16:33:54 +01:00
|
|
|
{t('empty.success.message')}
|
|
|
|
</Text>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
2022-02-12 14:51:01 +01:00
|
|
|
}, [theme, i18n.language, status])
|
2021-02-27 16:33:54 +01:00
|
|
|
return (
|
|
|
|
<View
|
2022-02-12 14:51:01 +01:00
|
|
|
style={[styles.base, { backgroundColor: colors.backgroundDefault }]}
|
2021-02-27 16:33:54 +01:00
|
|
|
children={children}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
() => true
|
|
|
|
)
|
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
|