alf error screen (#7135)

This commit is contained in:
Samuel Newman
2024-12-17 00:11:03 +00:00
committed by GitHub
parent 1a160df396
commit be33c626b0
+51 -78
View File
@@ -1,4 +1,4 @@
import {StyleSheet, View} from 'react-native' import {View} from 'react-native'
import { import {
FontAwesomeIcon, FontAwesomeIcon,
FontAwesomeIconStyle, FontAwesomeIconStyle,
@@ -7,12 +7,11 @@ import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react' import {useLingui} from '@lingui/react'
import {usePalette} from '#/lib/hooks/usePalette' import {usePalette} from '#/lib/hooks/usePalette'
import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' import {atoms as a, useTheme} from '#/alf'
import {useTheme} from '#/lib/ThemeContext' import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {ViewHeader} from '#/view/com/util/ViewHeader' import {ArrowRotateCounterClockwise_Stroke2_Corner0_Rounded as ArrowRotateCounterClockwiseIcon} from '#/components/icons/ArrowRotateCounterClockwise'
import {Button} from '../forms/Button' import * as Layout from '#/components/Layout'
import {Text} from '../text/Text' import {Text} from '#/components/Typography'
import {CenteredView} from '../Views'
export function ErrorScreen({ export function ErrorScreen({
title, title,
@@ -29,22 +28,32 @@ export function ErrorScreen({
testID?: string testID?: string
showHeader?: boolean showHeader?: boolean
}) { }) {
const theme = useTheme() const t = useTheme()
const {isMobile} = useWebMediaQueries()
const pal = usePalette('default') const pal = usePalette('default')
const {_} = useLingui() const {_} = useLingui()
return ( return (
<> <Layout.Center testID={testID}>
{showHeader && isMobile && ( {showHeader && (
<ViewHeader title={_(msg`Error`)} showBorder /> <Layout.Header.Outer>
<Layout.Header.BackButton />
<Layout.Header.Content>
<Layout.Header.TitleText>
<Trans>Error</Trans>
</Layout.Header.TitleText>
</Layout.Header.Content>
<Layout.Header.Slot />
</Layout.Header.Outer>
)} )}
<CenteredView testID={testID} style={[styles.outer, pal.view]}> <View style={[a.px_xl, a.py_2xl]}>
<View style={styles.errorIconContainer}> <View style={[a.mb_md, a.align_center]}>
<View <View
style={[ style={[
styles.errorIcon, a.rounded_full,
{backgroundColor: theme.palette.inverted.background}, {width: 50, height: 50},
a.align_center,
a.justify_center,
{backgroundColor: t.palette.contrast_950},
]}> ]}>
<FontAwesomeIcon <FontAwesomeIcon
icon="exclamation" icon="exclamation"
@@ -53,86 +62,50 @@ export function ErrorScreen({
/> />
</View> </View>
</View> </View>
<Text type="title-lg" style={[styles.title, pal.text]}> <Text style={[a.text_center, a.font_heavy, a.text_2xl, a.mb_md]}>
{title} {title}
</Text> </Text>
<Text style={[styles.message, pal.text]}>{message}</Text> <Text style={[a.text_center, a.text_md, a.mb_xl]}>{message}</Text>
{details && ( {details && (
<View
style={[
a.w_full,
a.border,
t.atoms.border_contrast_medium,
t.atoms.bg_contrast_25,
a.mb_xl,
a.py_sm,
a.px_lg,
a.rounded_xs,
a.overflow_hidden,
]}>
<Text <Text
testID={`${testID}-details`} testID={`${testID}-details`}
style={[styles.details, pal.text, pal.viewLight]}> style={[a.text_center, a.text_md, t.atoms.text_contrast_high]}>
{details} {details}
</Text> </Text>
</View>
)} )}
{onPressTryAgain && ( {onPressTryAgain && (
<View style={styles.btnContainer}> <View style={[a.align_center]}>
<Button <Button
testID="errorScreenTryAgainButton" testID="errorScreenTryAgainButton"
type="default"
style={[styles.btn]}
onPress={onPressTryAgain} onPress={onPressTryAgain}
accessibilityLabel={_(msg`Retry`)} variant="solid"
color="secondary_inverted"
size="small"
label={_(msg`Retry`)}
accessibilityHint={_( accessibilityHint={_(
msg`Retries the last action, which errored out`, msg`Retries the last action, which errored out`,
)}> )}>
<FontAwesomeIcon <ButtonIcon icon={ArrowRotateCounterClockwiseIcon} />
icon="arrows-rotate" <ButtonText>
style={pal.link as FontAwesomeIconStyle}
size={16}
/>
<Text type="button" style={[styles.btnText, pal.link]}>
<Trans context="action">Try again</Trans> <Trans context="action">Try again</Trans>
</Text> </ButtonText>
</Button> </Button>
</View> </View>
)} )}
</CenteredView> </View>
</> </Layout.Center>
) )
} }
const styles = StyleSheet.create({
outer: {
flex: 1,
paddingVertical: 30,
paddingHorizontal: 14,
},
title: {
textAlign: 'center',
marginBottom: 10,
},
message: {
textAlign: 'center',
marginBottom: 20,
},
details: {
textAlign: 'center',
paddingVertical: 10,
paddingHorizontal: 14,
overflow: 'hidden',
marginBottom: 20,
},
btnContainer: {
alignItems: 'center',
},
btn: {
flexDirection: 'row',
alignItems: 'center',
paddingHorizontal: 16,
paddingVertical: 10,
},
btnText: {
marginLeft: 5,
},
errorIconContainer: {
alignItems: 'center',
marginBottom: 10,
},
errorIcon: {
borderRadius: 25,
width: 50,
height: 50,
alignItems: 'center',
justifyContent: 'center',
},
})