Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
H
holi-frontends
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
app
holi-frontends
Commits
85815335
Commit
85815335
authored
1 month ago
by
Stephanie Freitag
Browse files
Options
Downloads
Patches
Plain Diff
NOISSUE: remove obsolete platform check in useLink
parent
c418fa1b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/navigation/hooks/__tests__/useLink.test.ts
+2
-8
2 additions, 8 deletions
core/navigation/hooks/__tests__/useLink.test.ts
core/navigation/hooks/useLink.ts
+5
-8
5 additions, 8 deletions
core/navigation/hooks/useLink.ts
with
7 additions
and
16 deletions
core/navigation/hooks/__tests__/useLink.test.ts
+
2
−
8
View file @
85815335
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
})
})
This diff is collapsed.
Click to expand it.
core/navigation/hooks/useLink.ts
+
5
−
8
View file @
85815335
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
]
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment