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

71 lines
1.8 KiB
TypeScript
Raw Normal View History

2020-12-13 01:24:25 +01:00
import React, { useMemo } from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { Chase } from 'react-native-animated-spinkit'
2020-12-13 01:24:25 +01:00
import { QueryStatus } from 'react-query'
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'
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 }) => {
2020-12-12 12:49:29 +01:00
const { theme } = useTheme()
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 }]}>
</Text>
2020-12-26 23:05:17 +01:00
<Button type='text' content='重试' 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 }]}>
</Text>
</>
)
}
}, [status])
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: {
fontSize: StyleConstants.Font.Size.M,
marginTop: StyleConstants.Spacing.S,
marginBottom: StyleConstants.Spacing.L
}
})
export default TimelineEmpty