Skip to content

Commit

Permalink
chore: Move Link & router code to /navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
codinsonn committed Apr 6, 2024
1 parent f788b66 commit b76bce0
Show file tree
Hide file tree
Showing 12 changed files with 25 additions and 26 deletions.
8 changes: 0 additions & 8 deletions features/app-core/hooks/useUniversalRouteParams.web.ts

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useLocalSearchParams } from 'expo-router'
import type { UniversalRouteScreenProps } from './useUniversalRouteParams.types'
import type { UniversalRouteScreenProps } from './useRouteParams.types'

/** --- useUniversalRouteParams() -------------------------------------------------------------- */
/** --- useRouteParams() -------------------------------------------------------------- */
/** -i- Gets the route search and query params on both web and mobile */
export const useUniversalRouteParams = (routeScreenProps: UniversalRouteScreenProps) => {
export const useRouteParams = (routeScreenProps: UniversalRouteScreenProps) => {
const { params, searchParams } = routeScreenProps
const expoRouterParams = useLocalSearchParams()
return {
Expand Down
8 changes: 8 additions & 0 deletions features/app-core/navigation/useRouteParams.web.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import type { UniversalRouteScreenProps } from './useRouteParams.types'

/** --- useRouteParams() -------------------------------------------------------------- */
/** -i- Gets the route search and query params on both web and mobile */
export const useRouteParams = (routeScreenProps: UniversalRouteScreenProps) => {
const { params, searchParams } = routeScreenProps
return { ...params, ...searchParams }
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { router } from 'expo-router'
import { UniversalRouterMethods } from './useUniversalRouter.types'
import { UniversalRouterMethods } from './useRouter.types'

/* --- useUniversalRouter() -------------------------------------------------------------------- */
/* --- useRouter() ----------------------------------------------------------------------------- */

export const useUniversalRouter = () => {
export const useRouter = () => {
return {
push: router.push,
navigate: router.navigate,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { useRouter } from 'next/navigation'
import { UniversalRouterMethods } from './useUniversalRouter.types'
import { useUniversalRouteParams } from './useUniversalRouteParams'
import { useRouter as useNextRouter } from 'next/navigation'
import { UniversalRouterMethods } from './useRouter.types'

/* --- useUniversalRouter() -------------------------------------------------------------------- */
/* --- useRouter() -------------------------------------------------------------------- */

export const useUniversalRouter = () => {
export const useRouter = () => {
// Hooks
const nextRouter = useRouter()
const nextRouter = useNextRouter()

// -- Helpers --

Expand Down
2 changes: 1 addition & 1 deletion features/app-core/screens/HomeScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { Link } from '../components/Link'
import { Link } from '../navigation/Link'

/* --- <HomeScreen/> --------------------------------------------------------------------------- */

Expand Down
10 changes: 5 additions & 5 deletions features/app-core/screens/SlugScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import React from 'react'
import { StyleSheet, Text, View } from 'react-native'
import { useUniversalRouteParams } from '@app/core/hooks/useUniversalRouteParams'
import { Link } from '../components/Link'
import { useUniversalRouter } from '../hooks/useUniversalRouter'
import { useRouteParams } from '@app/core/navigation/useRouteParams'
import { Link } from '../navigation/Link'
import { useRouter } from '../navigation/useRouter'

/* --- <SlugScreen/> --------------------------------------------------------------------------- */

const SlugScreen = (props) => {
// Routing
const { slug, count = '' } = useUniversalRouteParams(props)
const { canGoBack, back, push, navigate, replace, setParams } = useUniversalRouter()
const { slug, count = '' } = useRouteParams(props)
const { canGoBack, back, push, navigate, replace, setParams } = useRouter()

// Vars
const showBackButton = canGoBack()
Expand Down

0 comments on commit b76bce0

Please sign in to comment.