mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import {
2 StyleProp,
3 StyleSheet,
4 TouchableOpacity,
5 View,
6 ViewStyle,
7} from 'react-native'
8import {
9 FontAwesomeIcon,
10 FontAwesomeIconStyle,
11} from '@fortawesome/react-native-fontawesome'
12import {msg} from '@lingui/macro'
13import {useLingui} from '@lingui/react'
14
15import {usePalette} from '#/lib/hooks/usePalette'
16import {useTheme} from '#/lib/ThemeContext'
17import * as Layout from '#/components/Layout'
18import {Text} from '../text/Text'
19
20export function ErrorMessage({
21 message,
22 numberOfLines,
23 style,
24 onPressTryAgain,
25}: {
26 message: string
27 numberOfLines?: number
28 style?: StyleProp<ViewStyle>
29 onPressTryAgain?: () => void
30}) {
31 const theme = useTheme()
32 const pal = usePalette('error')
33 const {_} = useLingui()
34 return (
35 <Layout.Center>
36 <View testID="errorMessageView" style={[styles.outer, pal.view, style]}>
37 <View
38 style={[
39 styles.errorIcon,
40 {backgroundColor: theme.palette.error.icon},
41 ]}>
42 <FontAwesomeIcon
43 icon="exclamation"
44 style={pal.text as FontAwesomeIconStyle}
45 size={16}
46 />
47 </View>
48 <Text
49 type="sm-medium"
50 style={[styles.message, pal.text]}
51 numberOfLines={numberOfLines}>
52 {message}
53 </Text>
54 {onPressTryAgain && (
55 <TouchableOpacity
56 testID="errorMessageTryAgainButton"
57 style={styles.btn}
58 onPress={onPressTryAgain}
59 accessibilityRole="button"
60 accessibilityLabel={_(msg`Retry`)}
61 accessibilityHint={_(
62 msg`Retries the last action, which errored out`,
63 )}>
64 <FontAwesomeIcon
65 icon="arrows-rotate"
66 style={{color: theme.palette.error.icon}}
67 size={18}
68 />
69 </TouchableOpacity>
70 )}
71 </View>
72 </Layout.Center>
73 )
74}
75
76const styles = StyleSheet.create({
77 outer: {
78 flexDirection: 'row',
79 alignItems: 'center',
80 paddingVertical: 8,
81 paddingHorizontal: 8,
82 },
83 errorIcon: {
84 borderRadius: 12,
85 width: 24,
86 height: 24,
87 alignItems: 'center',
88 justifyContent: 'center',
89 marginRight: 8,
90 },
91 message: {
92 flex: 1,
93 paddingRight: 10,
94 },
95 btn: {
96 paddingHorizontal: 4,
97 paddingVertical: 4,
98 },
99})