Skip to content

Commit

Permalink
refactor: Handle SendDb deeplink in its own hook
Browse files Browse the repository at this point in the history
  • Loading branch information
Ldoppea committed Sep 24, 2024
1 parent 5ae1fcf commit 67105a5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import { useGeolocationTracking } from '/app/domain/geolocation/hooks/useGeoloca
import { OsReceiveProvider } from '/app/view/OsReceive/OsReceiveProvider'
import { ErrorProvider } from '/app/view/Error/ErrorProvider'
import { LoadingOverlayProvider } from '/app/view/Loading/LoadingOverlayProvider'
import { useOfflineDebugUniversalLinks } from '/app/domain/offline/hooks/useOfflineDebugUniversalLinks'
import { OsReceiveApi } from '/app/domain/osReceive/services/OsReceiveApi'
import {
useOsReceiveDispatch,
Expand Down Expand Up @@ -101,6 +102,7 @@ const App = ({ setClient }) => {
useNotifications()
useGeolocationTracking()
useCozyEnvironmentOverride()
useOfflineDebugUniversalLinks(client)

const {
LauncherDialog,
Expand Down
24 changes: 24 additions & 0 deletions src/app/domain/offline/hooks/useOfflineDebugUniversalLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useEffect } from 'react'
import { Linking } from 'react-native'

import CozyClient from 'cozy-client'
import Minilog from 'cozy-minilog'

import { handleDbDeepLink } from '/pouchdb/deeplinkHandler'

const log = Minilog('useOfflineDebugUniversalLinks')

export const useOfflineDebugUniversalLinks = (client: CozyClient): void => {
useEffect(() => {
const subscription = Linking.addEventListener('url', ({ url }) => {
log.debug(`🔗 Linking URL is ${url}`)
if (handleDbDeepLink(url, client)) {
return
}
})

return () => {
subscription.remove()
}
}, [client])
}
5 changes: 0 additions & 5 deletions src/hooks/useAppBootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useEffect, useState } from 'react'
import { deconstructCozyWebLinkWithSlug } from 'cozy-client'

import { handleLogsDeepLink } from '/app/domain/logger/deeplinkHandler'
import { handleDbDeepLink } from '/pouchdb/deeplinkHandler'
import { SentryCustomTags, setSentryTag } from '/libs/monitoring/Sentry'
import { manageIconCache } from '/libs/functions/iconTable'
import { getDefaultIconParams } from '/libs/functions/openApp'
Expand Down Expand Up @@ -161,10 +160,6 @@ export const useAppBootstrap = client => {
return
}

if (handleDbDeepLink(url, client)) {
return
}

if (!client) {
const action = parseOnboardLink(url)

Expand Down

0 comments on commit 67105a5

Please sign in to comment.