Implement not-found page

This commit is contained in:
Paul Frazee
2023-03-10 14:24:10 -06:00
parent b2300a8381
commit 97c5d4d965
3 changed files with 31 additions and 16 deletions
+1
View File
@@ -4,6 +4,7 @@ import type {NativeStackNavigationProp} from '@react-navigation/native-stack'
export type {NativeStackScreenProps} from '@react-navigation/native-stack' export type {NativeStackScreenProps} from '@react-navigation/native-stack'
export type CommonNavigatorParams = { export type CommonNavigatorParams = {
NotFound: undefined
Settings: undefined Settings: undefined
Profile: {name: string} Profile: {name: string}
ProfileFollowers: {name: string} ProfileFollowers: {name: string}
+3 -1
View File
@@ -20,6 +20,7 @@ import {BottomBar} from './view/shell/BottomBar'
import {HomeScreen} from './view/screens/Home' import {HomeScreen} from './view/screens/Home'
import {SearchScreen} from './view/screens/Search' import {SearchScreen} from './view/screens/Search'
import {NotificationsScreen} from './view/screens/Notifications' import {NotificationsScreen} from './view/screens/Notifications'
import {NotFoundScreen} from './view/screens/NotFound'
import {SettingsScreen} from './view/screens/Settings' import {SettingsScreen} from './view/screens/Settings'
import {ProfileScreen} from './view/screens/Profile' import {ProfileScreen} from './view/screens/Profile'
import {ProfileFollowersScreen} from './view/screens/ProfileFollowers' import {ProfileFollowersScreen} from './view/screens/ProfileFollowers'
@@ -87,7 +88,7 @@ const ROUTES: Record<string, Route> = {
} }
export function matchPath(path: string): {name: string; params: RouteParams} { export function matchPath(path: string): {name: string; params: RouteParams} {
let name = 'Home' // TODO should be not found let name = 'NotFound'
let params: RouteParams = {} let params: RouteParams = {}
for (const [screenName, matcher] of Object.entries(ROUTES)) { for (const [screenName, matcher] of Object.entries(ROUTES)) {
const res = matcher.match(path) const res = matcher.match(path)
@@ -146,6 +147,7 @@ function buildStateObject(stack: string, route: string, params: RouteParams) {
function commonScreens(Stack: typeof HomeTab) { function commonScreens(Stack: typeof HomeTab) {
return ( return (
<> <>
<Stack.Screen name="NotFound" component={NotFoundScreen} />
<Stack.Screen name="Settings" component={SettingsScreen} /> <Stack.Screen name="Settings" component={SettingsScreen} />
<Stack.Screen name="Profile" component={ProfileScreen} /> <Stack.Screen name="Profile" component={ProfileScreen} />
<Stack.Screen <Stack.Screen
+27 -15
View File
@@ -1,25 +1,40 @@
import React from 'react' import React from 'react'
import {Button, StyleSheet, View} from 'react-native' import {StyleSheet, View} from 'react-native'
import {useNavigation} from '@react-navigation/native' import {useNavigation, StackActions} from '@react-navigation/native'
import {ViewHeader} from '../com/util/ViewHeader' import {ViewHeader} from '../com/util/ViewHeader'
import {Text} from '../com/util/text/Text' import {Text} from '../com/util/text/Text'
import {Button} from 'view/com/util/forms/Button'
import {NavigationProp} from 'lib/routes/types' import {NavigationProp} from 'lib/routes/types'
import {usePalette} from 'lib/hooks/usePalette'
import {s} from 'lib/styles'
export const NotFound = () => { export const NotFoundScreen = () => {
const pal = usePalette('default')
const navigation = useNavigation<NavigationProp>() const navigation = useNavigation<NavigationProp>()
const canGoBack = navigation.canGoBack()
const onPressHome = React.useCallback(() => { const onPressHome = React.useCallback(() => {
navigation.navigate('HomeTab') // TODO go fully home if (canGoBack) {
}, [navigation]) navigation.goBack()
} else {
navigation.navigate('HomeTab')
navigation.dispatch(StackActions.popToTop())
}
}, [navigation, canGoBack])
return ( return (
<View testID="notFoundView"> <View testID="notFoundView" style={pal.view}>
<ViewHeader title="Page not found" /> <ViewHeader title="Page not found" />
<View style={styles.container}> <View style={styles.container}>
<Text style={styles.title}>Page not found</Text> <Text type="title-2xl" style={[pal.text, s.mb10]}>
Page not found
</Text>
<Text type="md" style={[pal.text, s.mb10]}>
We're sorry! We can't find the page you were looking for.
</Text>
<Button <Button
testID="navigateHomeButton" type="primary"
title="Home" label={canGoBack ? 'Go back' : 'Go home'}
onPress={onPressHome} onPress={onPressHome}
/> />
</View> </View>
@@ -29,12 +44,9 @@ export const NotFound = () => {
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
justifyContent: 'center',
alignItems: 'center',
paddingTop: 100, paddingTop: 100,
}, paddingHorizontal: 20,
title: { alignItems: 'center',
fontSize: 40, height: '100%',
fontWeight: 'bold',
}, },
}) })