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