about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-10-11 09:30:30 -0700
committerGitHub <noreply@github.com>2024-10-11 09:30:30 -0700
commit7e5c522718108b26d6eddc46aba47a2e086a2fe3 (patch)
treeecf9a76893fcaa58c19aa1a5f5441ad545cc0fbb
parent8c6384175c8343c0cdc14b4fbefd53127f3f1866 (diff)
downloadvoidsky-7e5c522718108b26d6eddc46aba47a2e086a2fe3.tar.zst
Move intent handler to a child of `InnerApp` (#5695)
-rw-r--r--src/App.native.tsx2
-rw-r--r--src/lib/hooks/useIntentHandler.ts11
-rw-r--r--src/view/shell/index.tsx3
3 files changed, 13 insertions, 3 deletions
diff --git a/src/App.native.tsx b/src/App.native.tsx
index 0b9f112ee..668fb91fc 100644
--- a/src/App.native.tsx
+++ b/src/App.native.tsx
@@ -14,7 +14,6 @@ import * as SplashScreen from 'expo-splash-screen'
 import {msg} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
 
-import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
 import {QueryProvider} from '#/lib/react-query'
 import {
   initialize,
@@ -85,7 +84,6 @@ function InnerApp() {
   const theme = useColorModeTheme()
   const {_} = useLingui()
 
-  useIntentHandler()
   const hasCheckedReferrer = useStarterPackEntry()
 
   // init
diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts
index 98ba4ec02..a33aff237 100644
--- a/src/lib/hooks/useIntentHandler.ts
+++ b/src/lib/hooks/useIntentHandler.ts
@@ -13,6 +13,9 @@ type IntentType = 'compose' | 'verify-email'
 
 const VALID_IMAGE_REGEX = /^[\w.:\-_/]+\|\d+(\.\d+)?\|\d+(\.\d+)?$/
 
+// This needs to stay outside of react to persist between account switches
+let previousIntentUrl = ''
+
 export function useIntentHandler() {
   const incomingUrl = Linking.useURL()
   const composeIntent = useComposeIntent()
@@ -68,7 +71,13 @@ export function useIntentHandler() {
       }
     }
 
-    if (incomingUrl) handleIncomingURL(incomingUrl)
+    if (incomingUrl) {
+      if (previousIntentUrl === incomingUrl) {
+        return
+      }
+      handleIncomingURL(incomingUrl)
+      previousIntentUrl = incomingUrl
+    }
   }, [incomingUrl, composeIntent, verifyEmailIntent])
 }
 
diff --git a/src/view/shell/index.tsx b/src/view/shell/index.tsx
index 9f7569beb..79fc1a069 100644
--- a/src/view/shell/index.tsx
+++ b/src/view/shell/index.tsx
@@ -14,6 +14,7 @@ import {StatusBar} from 'expo-status-bar'
 import {useNavigation, useNavigationState} from '@react-navigation/native'
 
 import {useDedupe} from '#/lib/hooks/useDedupe'
+import {useIntentHandler} from '#/lib/hooks/useIntentHandler'
 import {useNotificationsHandler} from '#/lib/hooks/useNotificationHandler'
 import {usePalette} from '#/lib/hooks/usePalette'
 import {useNotificationsRegistration} from '#/lib/notifications/notifications'
@@ -129,6 +130,8 @@ export const Shell: React.FC = function ShellImpl() {
   const {fullyExpandedCount} = useDialogStateControlContext()
   const pal = usePalette('default')
   const theme = useTheme()
+  useIntentHandler()
+
   React.useEffect(() => {
     if (isAndroid) {
       NavigationBar.setBackgroundColorAsync(theme.palette.default.background)