about summary refs log tree commit diff
path: root/src/lib/hooks/useIntentHandler.ts
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-09-07 11:54:39 -0700
committerGitHub <noreply@github.com>2024-09-07 11:54:39 -0700
commit2842f661db8aeb0154dd362a6b61b3edb808bef9 (patch)
tree6de50442adac91debfba0fd89dcbef44488dd43a /src/lib/hooks/useIntentHandler.ts
parent45a719b256173f98b20457cc80b4288e84f1c33f (diff)
downloadvoidsky-2842f661db8aeb0154dd362a6b61b3edb808bef9.tar.zst
Add intent for verifying email (#5120)
Diffstat (limited to 'src/lib/hooks/useIntentHandler.ts')
-rw-r--r--src/lib/hooks/useIntentHandler.ts34
1 files changed, 32 insertions, 2 deletions
diff --git a/src/lib/hooks/useIntentHandler.ts b/src/lib/hooks/useIntentHandler.ts
index 460df3753..8cccda48f 100644
--- a/src/lib/hooks/useIntentHandler.ts
+++ b/src/lib/hooks/useIntentHandler.ts
@@ -6,15 +6,17 @@ import {isNative} from 'platform/detection'
 import {useSession} from 'state/session'
 import {useComposerControls} from 'state/shell'
 import {useCloseAllActiveElements} from 'state/util'
+import {useIntentDialogs} from '#/components/intents/IntentDialogs'
 import {Referrer} from '../../../modules/expo-bluesky-swiss-army'
 
-type IntentType = 'compose'
+type IntentType = 'compose' | 'verify-email'
 
 const VALID_IMAGE_REGEX = /^[\w.:\-_/]+\|\d+(\.\d+)?\|\d+(\.\d+)?$/
 
 export function useIntentHandler() {
   const incomingUrl = Linking.useURL()
   const composeIntent = useComposeIntent()
+  const verifyEmailIntent = useVerifyEmailIntent()
 
   React.useEffect(() => {
     const handleIncomingURL = (url: string) => {
@@ -51,12 +53,22 @@ export function useIntentHandler() {
             text: params.get('text'),
             imageUrisStr: params.get('imageUris'),
           })
+          return
+        }
+        case 'verify-email': {
+          const code = params.get('code')
+          if (!code) return
+          verifyEmailIntent(code)
+          return
+        }
+        default: {
+          return
         }
       }
     }
 
     if (incomingUrl) handleIncomingURL(incomingUrl)
-  }, [incomingUrl, composeIntent])
+  }, [incomingUrl, composeIntent, verifyEmailIntent])
 }
 
 function useComposeIntent() {
@@ -103,3 +115,21 @@ function useComposeIntent() {
     [hasSession, closeAllActiveElements, openComposer],
   )
 }
+
+function useVerifyEmailIntent() {
+  const closeAllActiveElements = useCloseAllActiveElements()
+  const {verifyEmailDialogControl: control, setVerifyEmailState: setState} =
+    useIntentDialogs()
+  return React.useCallback(
+    (code: string) => {
+      closeAllActiveElements()
+      setState({
+        code,
+      })
+      setTimeout(() => {
+        control.open()
+      }, 1000)
+    },
+    [closeAllActiveElements, control, setState],
+  )
+}