From 67105a59c23c18c06da5c8b988abda0dc6d91478 Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Sun, 15 Sep 2024 14:57:33 +0200 Subject: [PATCH] refactor: Handle SendDb deeplink in its own hook --- src/App.js | 2 ++ .../hooks/useOfflineDebugUniversalLinks.ts | 24 +++++++++++++++++++ src/hooks/useAppBootstrap.js | 5 ---- 3 files changed, 26 insertions(+), 5 deletions(-) create mode 100644 src/app/domain/offline/hooks/useOfflineDebugUniversalLinks.ts diff --git a/src/App.js b/src/App.js index 50dbfd30c..2e7e5f410 100644 --- a/src/App.js +++ b/src/App.js @@ -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, @@ -101,6 +102,7 @@ const App = ({ setClient }) => { useNotifications() useGeolocationTracking() useCozyEnvironmentOverride() + useOfflineDebugUniversalLinks(client) const { LauncherDialog, diff --git a/src/app/domain/offline/hooks/useOfflineDebugUniversalLinks.ts b/src/app/domain/offline/hooks/useOfflineDebugUniversalLinks.ts new file mode 100644 index 000000000..34681e9da --- /dev/null +++ b/src/app/domain/offline/hooks/useOfflineDebugUniversalLinks.ts @@ -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]) +} diff --git a/src/hooks/useAppBootstrap.js b/src/hooks/useAppBootstrap.js index f2921b993..c00d813a9 100644 --- a/src/hooks/useAppBootstrap.js +++ b/src/hooks/useAppBootstrap.js @@ -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' @@ -161,10 +160,6 @@ export const useAppBootstrap = client => { return } - if (handleDbDeepLink(url, client)) { - return - } - if (!client) { const action = parseOnboardLink(url)