Skip to content
Snippets Groups Projects
Commit 85815335 authored by Stephanie Freitag's avatar Stephanie Freitag
Browse files

NOISSUE: remove obsolete platform check in useLink

parent c418fa1b
No related branches found
No related tags found
No related merge requests found
import useLink from '@holi/core/navigation/hooks/useLink'
import useRouting from '@holi/core/navigation/hooks/useRouting'
import { renderHook, waitFor } from '@testing-library/react-native'
import { Linking, Platform } from 'react-native'
import { Linking } from 'react-native'
const mockUseRouting = jest.mocked(useRouting)
jest.mock('@holi/core/navigation/hooks/useRouting', () => jest.fn())
......@@ -79,17 +79,11 @@ describe('useLink', () => {
expect(mockOpenURL).toHaveBeenCalledWith('/')
})
it('should ignore domain and locale path param on mobile', () => {
const originalPlatform = Platform.OS
Platform.OS = 'android'
it('should ignore domain and locale path param', () => {
const { result } = renderHook(() => useLink({ href: 'https://app.holi.social/en/spaces' }))
result.current(testEvent)
expect(mockNavigate).toHaveBeenCalledWith('/spaces')
// Clean up
Platform.OS = originalPlatform
})
})
import type React from 'react'
import { useCallback } from 'react'
import { type GestureResponderEvent, Linking, Platform } from 'react-native'
import { type GestureResponderEvent, Linking } from 'react-native'
import useRouting from '@holi/core/navigation/hooks/useRouting'
......@@ -11,6 +11,7 @@ export interface UseLinkProps {
external?: boolean
}
// This hook is for mobile only and is used inside HoliLink and HoliTextLink, which have alternative implementations for web.
const useLink = ({ onPress, external, href }: UseLinkProps) => {
const { navigate } = useRouting()
......@@ -27,13 +28,9 @@ const useLink = ({ onPress, external, href }: UseLinkProps) => {
return
}
if (Platform.OS === 'ios' || Platform.OS === 'android') {
// If the platform is mobile and the link domain matches our app's domain, navigate to the route instead of opening the link
const route = '/' + href.replace(/https:\/\/(app\.holi\.social|staging\.dev\.holi\.social)(\/(en|de))?\/?/, '')
navigate(route)
} else {
navigate(href)
}
// If the platform is mobile and the link domain matches our app's domain, navigate to the route instead of opening the link
const route = '/' + href.replace(/https:\/\/(app\.holi\.social|staging\.dev\.holi\.social)(\/(en|de))?\/?/, '')
navigate(route)
},
[external, href, navigate, onPress]
)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment