Skip to content

Commit

Permalink
refactor(app): enable expo-router typed routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert27 committed Nov 28, 2024
1 parent c907232 commit 651ee32
Show file tree
Hide file tree
Showing 44 changed files with 94 additions and 78 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@
eas.json
credentials.json
credentials/

# @generated expo-cli sync-2b81b286409207a5da26e14c78851eb30d8ccbdb
# The following patterns were generated by expo-cli

expo-env.d.ts
# @end expo-cli
3 changes: 2 additions & 1 deletion app.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
},
"sdkVersion": "52.0.0",
"experiments": {
"tsconfigPaths": true
"tsconfigPaths": true,
"typedRoutes": true
},
"plugins": [
["react-native-edge-to-edge"],
Expand Down
2 changes: 1 addition & 1 deletion src/app/(flow)/onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export default function OnboardingScreen(): JSX.Element {
flow.setUpdated(true)
flow.setAnalyticsAllowed(true)
router.navigate({
pathname: '(screens)/login',
pathname: '/login',
params: { fromOnboarding: 'true' },
})
}}
Expand Down
4 changes: 2 additions & 2 deletions src/app/(flow)/whatsnew.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function WhatsNewScreen(): JSX.Element {
Application.nativeApplicationVersion ?? '0.0.0'
)
if (changelog.version[version] === undefined) {
router.navigate('(tabs)/(index)')
router.navigate('/(tabs)/(index)')
}
const totalItems = Object.keys(changelog.version[version] ?? []).flatMap(
(key) => changelog.version[key]
Expand Down Expand Up @@ -173,7 +173,7 @@ export default function WhatsNewScreen(): JSX.Element {
style={styles.button}
onPress={() => {
flow.setUpdated(true)
router.navigate('(tabs)/(index)')
router.navigate('/(tabs)/(index)')
}}
>
<Text style={styles.buttonText}>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(screens)/about.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export default function About(): JSX.Element {
title: 'Changelog',
icon: chevronIcon,
onPress: () => {
router.navigate('changelog')
router.navigate('/changelog')
},
},
{
Expand Down Expand Up @@ -124,7 +124,7 @@ export default function About(): JSX.Element {
title: t('about.formlist.legal.button'),
icon: chevronIcon,
onPress: () => {
router.navigate('legal')
router.navigate('/legal')
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/calendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export default function CalendarPage(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24, // 24 hours
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.push(' login')
router.push('/login')
return false
}
return failureCount < 2
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ export default function DashboardEdit(): JSX.Element {
<Pressable
style={[styles.card, styles.noteContainer]}
onPress={() => {
router.navigate('login')
router.navigate('/login')
}}
>
<View style={styles.noteTextContainer}>
Expand Down
4 changes: 2 additions & 2 deletions src/app/(screens)/foodPreferences.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ export default function FoodPreferences(): JSX.Element {
title: t('preferences.formlist.allergens'),
icon: chevronIcon,
onPress: () => {
router.push('foodAllergens')
router.push('/foodAllergens')
},
},
{
title: t('preferences.formlist.flags'),
icon: chevronIcon,
onPress: () => {
router.push('foodFlags')
router.push('/foodFlags')
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/grades.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default function GradesSCreen(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 7, // 1 week
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
}
return false
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/(screens)/lecture.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default function TimetableDetails(): JSX.Element {
icon: chevronIcon,
onPress: () => {
router.push({
pathname: 'webView',
pathname: '/webView',
params: {
title: t(titleKey),
html,
Expand Down Expand Up @@ -251,7 +251,7 @@ export default function TimetableDetails(): JSX.Element {
onPress={() => {
router.dismissTo({
pathname:
'(tabs)/map',
'/(tabs)/map',
params: {
room,
},
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/lecturer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function LecturerDetail(): JSX.Element {
textColor: theme.colors.primary,
onPress: () => {
router.dismissTo({
pathname: '(tabs)/map',
pathname: '/(tabs)/map',
params: { room: lecturer?.room_short ?? '' },
})
},
Expand Down
4 changes: 2 additions & 2 deletions src/app/(screens)/lecturers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default function LecturersCard(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 7, // 7 days
retry(failureCount: number, error: any) {
if (error instanceof NoSessionError) {
router.push('login')
router.push('/login')
return false
}
return failureCount < 2
Expand All @@ -107,7 +107,7 @@ export default function LecturersCard(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 7, // 7 days
retry(failureCount: number, error: any) {
if (error instanceof NoSessionError) {
router.navigate('login')
router.navigate('/login')
return false
}
return failureCount < 2
Expand Down
6 changes: 3 additions & 3 deletions src/app/(screens)/library.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default function LibrarySreen(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24, // 24 hours,
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 2
Expand All @@ -116,7 +116,7 @@ export default function LibrarySreen(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24, // 24 hours,
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 2
Expand Down Expand Up @@ -179,7 +179,7 @@ export default function LibrarySreen(): JSX.Element {
},
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 1
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/licenses.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function Licenses(): JSX.Element {
icon: chevronIcon,
onPress: () => {
router.navigate({
pathname: 'license',
pathname: '/license',
params: {
license: value.licenses,
version: version != null ? version[0] : '',
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function Login(): JSX.Element {
const navigateHome = (): void => {
if (fromOnboarding === 'true') {
router.dismissAll()
router.replace('(tabs)/(index)')
router.replace('/(tabs)/(index)')
return
}
router.dismissAll()
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/meal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ export default function FoodDetail(): JSX.Element {

if (restaurant != null && location !== undefined) {
router.dismissTo({
pathname: '(tabs)/map',
pathname: '/(tabs)/map',
params: { room: location },
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function Profile(): JSX.Element {
enabled: userKind === USER_STUDENT,
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 2
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/roomSearch.ios.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export default function AdvancedSearch(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 4, // 4 days
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 2
Expand Down
2 changes: 1 addition & 1 deletion src/app/(screens)/roomSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export default function AdvancedSearch(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 4, // 4 days
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
}
return failureCount < 2
Expand Down
18 changes: 9 additions & 9 deletions src/app/(screens)/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export default function Settings(): JSX.Element {
gcTime: 1000 * 60 * 60 * 24 * 60,
retry(failureCount, error) {
if (error instanceof NoSessionError) {
router.replace('login')
router.replace('/login')
return false
} else if (userKind !== 'student') {
return false
Expand Down Expand Up @@ -224,7 +224,7 @@ export default function Settings(): JSX.Element {
},

onPress: () => {
router.navigate('dashboard')
router.navigate('/dashboard')
},
},
{
Expand All @@ -234,7 +234,7 @@ export default function Settings(): JSX.Element {
ios: 'fork.knife',
},
onPress: () => {
router.navigate('foodPreferences')
router.navigate('/foodPreferences')
},
},
{
Expand Down Expand Up @@ -268,7 +268,7 @@ export default function Settings(): JSX.Element {
android: 'palette',
},
onPress: () => {
router.navigate('accent')
router.navigate('/accent')
},
},
{
Expand All @@ -278,7 +278,7 @@ export default function Settings(): JSX.Element {
android: 'routine',
},
onPress: () => {
router.navigate('theme')
router.navigate('/theme')
},
},
...(Platform.OS === 'ios' &&
Expand All @@ -291,7 +291,7 @@ export default function Settings(): JSX.Element {
android: '' as MaterialIcon,
},
onPress: () => {
router.navigate('appIcon')
router.navigate('/appIcon')
},
},
]
Expand All @@ -308,7 +308,7 @@ export default function Settings(): JSX.Element {
android: 'chevron_right',
},
onPress: () => {
router.navigate('about')
router.navigate('/about')
},
},

Expand Down Expand Up @@ -382,9 +382,9 @@ export default function Settings(): JSX.Element {
logoutAlert()
} else {
if (userKind === 'student') {
router.navigate('profile')
router.navigate('/profile')
} else if (userKind === 'guest') {
router.navigate('login')
router.navigate('/login')
}
}
}}
Expand Down
2 changes: 1 addition & 1 deletion src/app/(tabs)/(index)/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function HomeScreen(): JSX.Element {
}}
buttonText={t('dashboard.noShownButton', { ns: 'settings' })}
onButtonPress={() => {
router.navigate('dashboard')
router.navigate('/dashboard')
}}
isCritical={false}
/>
Expand Down
8 changes: 4 additions & 4 deletions src/app/(tabs)/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { USER_GUEST } from '@/data/constants'
import { convertToMajorMinorPatch } from '@/utils/app-utils'
import Aptabase from '@aptabase/react-native'
import * as Application from 'expo-application'
import { Redirect, useRouter } from 'expo-router'
import { Redirect, type RelativePathString, useRouter } from 'expo-router'
import React, { useContext, useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { Platform } from 'react-native'
Expand Down Expand Up @@ -101,7 +101,7 @@ export default function HomeLayout(): JSX.Element {
]
function processShortcut(item: ShortcutItem): void {
router.navigate({
pathname: item.data.path as string,
pathname: item.data.path as RelativePathString,
params: { fromAppShortcut: 'true' },
})
}
Expand Down Expand Up @@ -144,7 +144,7 @@ export default function HomeLayout(): JSX.Element {
}, [appIcon])

if (isOnboarded !== true) {
return <Redirect href={'(flow)/onboarding'} />
return <Redirect href={'/onboarding'} />
}

const version = Application.nativeApplicationVersion
Expand All @@ -160,7 +160,7 @@ export default function HomeLayout(): JSX.Element {
isChangelogAvailable &&
flow.isOnboarded === true
) {
return <Redirect href={'(flow)/whatsnew'} />
return <Redirect href={'/whatsnew'} />
}

return Platform.OS === 'android' ? <MaterialTabs /> : <DefaultTabs />
Expand Down
2 changes: 1 addition & 1 deletion src/app/[...unmachted].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function Unmatched(): JSX.Element {
if (router.canGoBack()) {
router.back()
} else {
router.replace('(tabs)/(index)')
router.replace('/(tabs)/(index)')
}
}}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function RootLayout(): JSX.Element {
headerRight: () => (
<Pressable
onPress={() => {
router.push('(screens)/libraryCode')
router.push('/libraryCode')
}}
accessibilityLabel={t('button.libraryBarcode', {
ns: 'accessibility',
Expand Down
2 changes: 1 addition & 1 deletion src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default function App(): JSX.Element {
<meta property="expo:handoff" content="true" />
<meta property="expo:spotlight" content="true" />
</Head>
<Redirect href={'(tabs)/(index)'} />
<Redirect href={'/(tabs)/(index)'} />
<View style={{ ...styles.page, backgroundColor }} />
</>
)
Expand Down
Loading

0 comments on commit 651ee32

Please sign in to comment.