Skip to content

Commit

Permalink
Turn fullscreen error from screen into component
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfilius committed Sep 11, 2024
1 parent 4e53ea9 commit d3753a9
Show file tree
Hide file tree
Showing 19 changed files with 115 additions and 106 deletions.
3 changes: 1 addition & 2 deletions src/app/UpdateScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {type ReactNode, useEffect} from 'react'
import {ScreenOutsideNavigation} from '@/components/features/screen/ScreenOutsideNavigation'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {UpdateFigure} from '@/components/ui/media/errors/UpdateFigure'
import {useDeviceContext} from '@/hooks/useDeviceContext'
import {useHideSplashScreen} from '@/hooks/useHideSplashScreen'
Expand Down Expand Up @@ -54,7 +54,6 @@ export const UpdateScreen = ({children}: Props) => {
testID="UpdateScreenOpenStoreButton"
text="Om de app te kunnen gebruiken moet u eerst updaten."
title="De versie van de app is verouderd en werkt niet meer."
withTopInset
/>
</ScreenOutsideNavigation>
)
Expand Down
2 changes: 1 addition & 1 deletion src/components/features/NoInternetFullScreenError.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {useFocusEffect} from '@react-navigation/core'
import {useCallback, useEffect} from 'react'
import {Platform, Linking} from 'react-native'
import {Screen} from '@/components/features/screen/Screen'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {NoInternetFigure} from '@/components/ui/media/errors/NoInternetFigure'
import {useDispatch} from '@/hooks/redux/useDispatch'
import {useDeviceContext} from '@/hooks/useDeviceContext'
Expand Down
1 change: 1 addition & 0 deletions src/components/features/screen/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export type ScreenProps = {
bottomSheet?: ReactNode
children: ReactNode
hasStickyAlert?: boolean
isOutsideNavigation?: boolean
keyboardAware?: boolean
scroll?: boolean
stickyFooter?: ReactNode
Expand Down
26 changes: 4 additions & 22 deletions src/components/features/screen/ScreenBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,19 @@ import {StyleSheet} from 'react-native'
import {EdgeInsets, useSafeAreaInsets} from 'react-native-safe-area-context'
import {HideFromAccessibilityWhenBottomSheetIsOpen} from '@/components/features/accessibility/HideFromAccessibilityWhenBottomSheetIsOpen'
import {HideFromAccessibilityWhenOverlayIsOpen} from '@/components/features/accessibility/HideFromAccessibilityWhenOverlayIsOpen'
import {Header} from '@/components/features/header/Header'
import {ScreenProps, WithInsetProps} from '@/components/features/screen/Screen'
import {ScreenHeader} from '@/components/features/screen/ScreenHeader'
import {ScreenInnerWrapper} from '@/components/features/screen/ScreenInnerWrapper'
import {ScreenWrapper} from '@/components/features/screen/ScreenWrapper'
import {AlertTopOfScreen} from '@/components/ui/feedback/alert/AlertTopOfScreen'
import {Gutter} from '@/components/ui/layout/Gutter'
import {useNavigation} from '@/hooks/navigation/useNavigation'
import {useRoute} from '@/hooks/navigation/useRoute'
import {useSelector} from '@/hooks/redux/useSelector'
import {DisableScrollProvider} from '@/providers/disableScroll.provider'
import {selectIsBottomSheetPresentRouteNames} from '@/store/slices/bottomSheet'

export const ScreenBase = ({
bottomSheet,
children,
hasStickyAlert,
isOutsideNavigation = false,
stickyFooter,
stickyHeader,
withBottomInset = true,
Expand All @@ -29,17 +26,10 @@ export const ScreenBase = ({
trackScroll,
...wrapperProps
}: ScreenProps) => {
const {name: routeName} = useRoute()
const isBottomSheetPresentRouteNames = useSelector(
selectIsBottomSheetPresentRouteNames,
)
const isBottomSheetPresent =
isBottomSheetPresentRouteNames.includes(routeName)

const insets = useSafeAreaInsets()

const hasStickyFooter = !!stickyFooter
const hasStickyHeader = !!stickyHeader || !!isBottomSheetPresent
const hasStickyHeader = !!stickyHeader

const styles = useMemo(
() =>
Expand All @@ -61,21 +51,13 @@ export const ScreenBase = ({
withTopInset,
],
)
const navigation = useNavigation()
const route = useRoute()

return (
<DisableScrollProvider>
<HideFromAccessibilityWhenOverlayIsOpen
style={styles.screen}
testID={testID}>
{!!isBottomSheetPresent && (
<Header
back={{}}
navigation={navigation}
route={route}
/>
)}
{!isOutsideNavigation && <ScreenHeader />}
{stickyHeader}
{!!hasStickyAlert && <AlertTopOfScreen />}
<HideFromAccessibilityWhenBottomSheetIsOpen
Expand Down
27 changes: 27 additions & 0 deletions src/components/features/screen/ScreenHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {Header} from '@/components/features/header/Header'
import {useNavigation} from '@/hooks/navigation/useNavigation'
import {useRoute} from '@/hooks/navigation/useRoute'
import {useSelector} from '@/hooks/redux/useSelector'
import {selectIsBottomSheetPresentRouteNames} from '@/store/slices/bottomSheet'

export const ScreenHeader = () => {
const isBottomSheetPresentRouteNames = useSelector(
selectIsBottomSheetPresentRouteNames,
)
const navigation = useNavigation()
const route = useRoute()
const isBottomSheetPresent = isBottomSheetPresentRouteNames.includes(
route.name,
)

return (
!!isBottomSheetPresent &&
!!route && (
<Header
back={{}}
navigation={navigation}
route={route}
/>
)
)
}
7 changes: 6 additions & 1 deletion src/components/features/screen/ScreenOutsideNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,10 @@ export const ScreenOutsideNavigation = ({
}: ScreenOutsideNavigationProps) => {
useTrackScreenOutsideNavigation(name)

return <ScreenBase {...screenProps} />
return (
<ScreenBase
{...screenProps}
isOutsideNavigation
/>
)
}
62 changes: 0 additions & 62 deletions src/components/features/screen/error/FullScreenError.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {useMemo} from 'react'
import {FullScreenErrorHeader} from '@/components/features/screen/error/Header'
import {ImageWithBackground} from '@/components/features/screen/error/ImageWithBackground'
import {FullScreenErrorHeader} from '@/components/ui/feedback/error/Header'
import {ImageWithBackground} from '@/components/ui/feedback/error/ImageWithBackground'
import {
SharedProps,
FullScreenErrorProps,
} from '@/components/features/screen/error/types'
} from '@/components/ui/feedback/error/types'
import {Column} from '@/components/ui/layout/Column'
import {Row} from '@/components/ui/layout/Row'

Expand Down
58 changes: 58 additions & 0 deletions src/components/ui/feedback/error/FullScreenError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import {Button} from '@/components/ui/buttons/Button'
import {Box} from '@/components/ui/containers/Box'
import {FullScreenErrorContent} from '@/components/ui/feedback/error/Content'
import {FullScreenErrorHeader} from '@/components/ui/feedback/error/Header'
import {FullScreenErrorProps} from '@/components/ui/feedback/error/types'
import {Column} from '@/components/ui/layout/Column'
import {useDeviceContext} from '@/hooks/useDeviceContext'

export const FullScreenError = ({
buttonAccessibilityLabel,
buttonLabel,
error,
text,
Image,
onPress,
testID,
title,
TopComponent,
withFacadesBackground = true,
...columnProps
}: FullScreenErrorProps) => {
const {isPortrait} = useDeviceContext()

return (
<Column
grow={1}
{...columnProps}>
{!!isPortrait && (
<FullScreenErrorHeader
error={error}
isPortrait={isPortrait}
testID={testID + 'Header'}
text={text}
title={title}
TopComponent={TopComponent}
/>
)}
<FullScreenErrorContent
error={error}
Image={Image}
isPortrait={isPortrait}
testID={testID + 'Content'}
text={text}
title={title}
TopComponent={TopComponent}
withFacadesBackground={withFacadesBackground}
/>
<Box inset="md">
<Button
accessibilityLabel={buttonAccessibilityLabel}
label={buttonLabel}
onPress={onPress}
testID={testID + 'Button'}
/>
</Box>
</Column>
)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {SharedProps} from '@/components/features/screen/error/types'
import {Box} from '@/components/ui/containers/Box'
import {SharedProps} from '@/components/ui/feedback/error/types'
import {Column} from '@/components/ui/layout/Column'
import {Paragraph} from '@/components/ui/text/Paragraph'
import {Title} from '@/components/ui/text/Title'
Expand All @@ -21,8 +21,7 @@ export const FullScreenErrorHeader = ({
<Column
align="center"
grow={1}
gutter="md"
halign="center">
gutter="md">
{!!TopComponent && TopComponent}
<Title
level="h3"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import {ComponentType} from 'react'
import {StyleSheet, View} from 'react-native'
import {SvgProps} from 'react-native-svg'
import AmsterdamFacadesImage from '@/assets/images/amsterdam-facades.svg'
import {FullScreenErrorProps} from '@/components/features/screen/error/types'
import {Box} from '@/components/ui/containers/Box'
import {FullScreenErrorProps} from '@/components/ui/feedback/error/types'
import {HideOnSmallSize} from '@/components/ui/layout/HideOnSmallSize'
import {Theme} from '@/themes/themes'
import {useThemable} from '@/themes/useThemable'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {SerializedError} from '@reduxjs/toolkit'
import {FetchBaseQueryError} from '@reduxjs/toolkit/query'
import {ComponentType, ReactNode} from 'react'
import {SvgProps} from 'react-native-svg'
import {ScreenProps} from '@/components/features/screen/Screen'
import {ColumnProps} from '@/components/ui/layout/Column'

export type ErrorType = FetchBaseQueryError | SerializedError | undefined

Expand All @@ -13,10 +13,11 @@ export type FullScreenErrorProps = {
buttonLabel: string
error?: ErrorType
onPress: () => void
testID: string
text?: string
title: string
withFacadesBackground?: boolean
} & Omit<ScreenProps, 'children'>
} & Omit<ColumnProps, 'children'>

export type SharedProps = {
TopComponent: FullScreenErrorProps['TopComponent']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {ErrorType} from '@/components/features/screen/error/types'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {ErrorType} from '@/components/ui/feedback/error/types'
import {useSelector} from '@/hooks/redux/useSelector'
import {FullScreenErrorFigure} from '@/modules/city-pass/components/error/FullScreenErrorFigure'
import {selectIsInternetReachable} from '@/store/slices/internetConnection'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {Box} from '@/components/ui/containers/Box'
import {HorizontalSafeArea} from '@/components/ui/containers/HorizontalSafeArea'
import {SingleSelectable} from '@/components/ui/containers/SingleSelectable'
import {PleaseWait} from '@/components/ui/feedback/PleaseWait'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {Column} from '@/components/ui/layout/Column'
import {FigureWithFacadesBackground} from '@/components/ui/media/FigureWithFacadesBackground'
import {LazyImage} from '@/components/ui/media/LazyImage'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {skipToken} from '@reduxjs/toolkit/dist/query'
import {useEffect} from 'react'
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {PleaseWait} from '@/components/ui/feedback/PleaseWait'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {ConstructionWorkDetailFigure} from '@/components/ui/media/errors/ConstructionWorkDetailFigure'
import {useNavigation} from '@/hooks/navigation/useNavigation'
import {useSetScreenTitle} from '@/hooks/navigation/useSetScreenTitle'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import type {ProjectsListItem} from '@/modules/construction-work/types/project'
import type {SerializedError} from '@reduxjs/toolkit'
import type {FetchBaseQueryError} from '@reduxjs/toolkit/query'
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {Box} from '@/components/ui/containers/Box'
import {EmptyMessage} from '@/components/ui/feedback/EmptyMessage'
import {PleaseWait} from '@/components/ui/feedback/PleaseWait'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {ConstructionWorkFigure} from '@/components/ui/media/errors/ConstructionWorkFigure'
import {useNavigation} from '@/hooks/navigation/useNavigation'
import {useSelector} from '@/hooks/redux/useSelector'
Expand Down Expand Up @@ -201,7 +201,6 @@ export const ProjectsList = ({
onPress={() => navigation.goBack()}
testID="ConstructionWorkError"
title="Er zijn geen werkzaamheden beschikbaar"
withBottomInset
/>
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/modules/home/components/ModuleSettings.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {pascalCase} from 'pascal-case'
import {getVersion} from 'react-native-device-info'
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {Box} from '@/components/ui/containers/Box'
import {EmptyMessage} from '@/components/ui/feedback/EmptyMessage'
import {PleaseWait} from '@/components/ui/feedback/PleaseWait'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {Column} from '@/components/ui/layout/Column'
import {ModulesFigure} from '@/components/ui/media/errors/ModulesFigure'
import {Paragraph} from '@/components/ui/text/Paragraph'
Expand Down
2 changes: 1 addition & 1 deletion src/modules/home/screens/Home.screen.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {NoInternetErrorFullScreen} from '@/components/features/NoInternetFullScreenError'
import {Tip} from '@/components/features/product-tour/types'
import {Screen} from '@/components/features/screen/Screen'
import {FullScreenError} from '@/components/features/screen/error/FullScreenError'
import {PleaseWait} from '@/components/ui/feedback/PleaseWait'
import {FullScreenError} from '@/components/ui/feedback/error/FullScreenError'
import {ModulesFigure} from '@/components/ui/media/errors/ModulesFigure'
import {useSelector} from '@/hooks/redux/useSelector'
import {useDeviceContext} from '@/hooks/useDeviceContext'
Expand Down
Loading

0 comments on commit d3753a9

Please sign in to comment.