From 5a6ad2f37d1e963b5ab5f0c01652600e6d6ca308 Mon Sep 17 00:00:00 2001 From: thienguen Date: Thu, 11 Apr 2024 00:57:42 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=A6=E2=80=8D=E2=99=82=EF=B8=8Fattempt:?= =?UTF-8?q?=20to=20fixed=20the=20stupid=20warning?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/expo/app.config.ts | 6 +- apps/expo/package.json | 1 + apps/expo/src/app/[...unmatched].tsx | 78 +++++++++++++++---- apps/expo/src/app/_layout.tsx | 2 +- apps/expo/src/app/index.tsx | 7 ++ .../src/components/auth/sign-in-w-google.tsx | 32 ++++---- apps/expo/src/utils/common.ts | 5 +- pnpm-lock.yaml | 11 +++ 8 files changed, 110 insertions(+), 32 deletions(-) create mode 100644 apps/expo/src/app/index.tsx diff --git a/apps/expo/app.config.ts b/apps/expo/app.config.ts index e1a4c295..90bbfe1c 100644 --- a/apps/expo/app.config.ts +++ b/apps/expo/app.config.ts @@ -47,9 +47,9 @@ const defineConfig = (): ExpoConfig => ({ }, extra: { // this is commented out so you don't have to log in to run expo start locally - // eas: { - // projectId: 'a5b98934-bf53-4573-ba91-972c22a6759a', - // }, + eas: { + projectId: 'a5b98934-bf53-4573-ba91-972c22a6759a', + }, clerkPublishableKey: process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY, expoPublicClerkPublishableKey: process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY, }, diff --git a/apps/expo/package.json b/apps/expo/package.json index f3c77144..63166890 100644 --- a/apps/expo/package.json +++ b/apps/expo/package.json @@ -47,6 +47,7 @@ "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.73.6", + "react-native-branch": "^6.2.1", "react-native-dotenv": "^3.4.10", "react-native-gesture-handler": "~2.14.1", "react-native-get-random-values": "^1.8.0", diff --git a/apps/expo/src/app/[...unmatched].tsx b/apps/expo/src/app/[...unmatched].tsx index 7600f375..4015e071 100644 --- a/apps/expo/src/app/[...unmatched].tsx +++ b/apps/expo/src/app/[...unmatched].tsx @@ -1,16 +1,66 @@ -import { Text } from 'react-native' -import { SafeAreaView } from 'react-native-safe-area-context' +// import { Text } from 'react-native' +// import { SafeAreaView } from 'react-native-safe-area-context' -export default function Page() { - return ( - <> - {/* */} - {alert('This page does not exist')} - - - This page does not exist - - - - ) +// export default function Page() { +// return ( +// <> +// {/* */} +// {alert('This page does not exist')} +// +// This page does not exist +// +// +// ) +// } + +import React, { useEffect, useState } from 'react' +import branch from 'react-native-branch' +import { Unmatched, useFocusEffect, useRouter } from 'expo-router' + +export default function CustomUnmatched() { + const [branchLoading, setBranchLoading] = useState(true) + const [goNext, setGoNext] = useState('') + const router = useRouter() + + useFocusEffect(() => { + branch.subscribe({ + onOpenStart: ({ uri, cachedInitialEvent }) => { + if (uri == null) { + setBranchLoading(false) + return + } + }, + onOpenComplete: ({ error, params, uri }) => { + if (error) { + console.error( + 'subscribe onOpenComplete, Error from opening uri: ' + uri + ' error: ' + error, + ) + return + } + if (!params?.['+clicked_branch_link']) { + setBranchLoading(false) + return + } else { + let canonicalIdentifier = params.$canonical_identifier as string + if (canonicalIdentifier) { + setGoNext(canonicalIdentifier) + } + // Route based on Branch link data + setBranchLoading(false) + return + } + }, + }) + + return () => { + // branch.unsubscribe(); + } + }) + useEffect(() => { + if (goNext !== undefined) { + router.push(goNext as any) + } + }, [goNext]) + + return branchLoading ? null : } diff --git a/apps/expo/src/app/_layout.tsx b/apps/expo/src/app/_layout.tsx index c56d6b49..e1a9928d 100644 --- a/apps/expo/src/app/_layout.tsx +++ b/apps/expo/src/app/_layout.tsx @@ -107,7 +107,7 @@ export default function RootLayout() { return ( - {isDevelopment ? ( + {!isDevelopment ? ( ) : ( <> diff --git a/apps/expo/src/app/index.tsx b/apps/expo/src/app/index.tsx new file mode 100644 index 00000000..d13c4a37 --- /dev/null +++ b/apps/expo/src/app/index.tsx @@ -0,0 +1,7 @@ +import { router } from 'expo-router' + +const Default = () => { + router.push('(dashboard)/') +} + +export default Default diff --git a/apps/expo/src/components/auth/sign-in-w-google.tsx b/apps/expo/src/components/auth/sign-in-w-google.tsx index 682ebb10..3d666f14 100644 --- a/apps/expo/src/components/auth/sign-in-w-google.tsx +++ b/apps/expo/src/components/auth/sign-in-w-google.tsx @@ -29,19 +29,25 @@ const SignInWithGoogle = () => { const SignInWithGoogleOAuth = React.useCallback(async () => { try { - const { createdSessionId, setActive } = await startGoogleOAuthFlow() - // console.log('startOAuthFlow') - - if (createdSessionId && setActive) { - await setActive({ session: createdSessionId }) - - // FIXME: WARN The navigation state parsed from the URL contains routes not present in the root navigator. - // This usually means that the linking configuration doesn't match the navigation structure. - // See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration. - // router.push('(dashboard)/') - } else { - // FIXME: Change this to a toast or style this alert - alert('Sign in failed') + if (isEnabled) { + setIsEnabled(false) + const { createdSessionId, setActive } = await startGoogleOAuthFlow() + + // console.log('startOAuthFlow') + + if (createdSessionId && setActive) { + await setActive({ session: createdSessionId }) + + // FIXME: WARN The navigation state parsed from the URL contains routes not present in the root navigator. + // This usually means that the linking configuration doesn't match the navigation structure. + // See https://reactnavigation.org/docs/configuring-links for more details on how to specify a linking configuration. + // router.push('(dashboard)/') + } else { + // FIXME: Change this to a toast or style this alert + alert('Sign in failed') + } + + setIsEnabled(true) } } catch (err: any) { Alert.alert( diff --git a/apps/expo/src/utils/common.ts b/apps/expo/src/utils/common.ts index cacc8d1e..24cd3d92 100644 --- a/apps/expo/src/utils/common.ts +++ b/apps/expo/src/utils/common.ts @@ -5,7 +5,6 @@ export default function getErrorMessage(error: unknown) { else return String(error) } - export function makeChatName(users: any[], userData: any): string { const filteredUsers = users.filter((user) => userData.username.trim() !== user.username.trim()) @@ -21,3 +20,7 @@ export function makeChatName(users: any[], userData: any): string { } return String(filteredUsers[0].username?.trim() + ' and ' + filteredUsers[1].username.trim()) } + +export function log(msg = '') { + return console.log(new Date() + ':> ' + msg) +} diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d52ed951..e43b7616 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -131,6 +131,9 @@ importers: react-native: specifier: 0.73.6 version: 0.73.6(@babel/core@7.23.9)(@babel/preset-env@7.23.9)(react@18.2.0) + react-native-branch: + specifier: ^6.2.1 + version: 6.2.1(react-native@0.73.6) react-native-dotenv: specifier: ^3.4.10 version: 3.4.10(@babel/runtime@7.23.9) @@ -14211,6 +14214,14 @@ packages: prop-types: 15.8.1 dev: false + /react-native-branch@6.2.1(react-native@0.73.6): + resolution: {integrity: sha512-j/qkdYvW8LvVzC3LnLpRaHlUPQFl1K/8+jbOqFMJGMiBYvzy0cjJE9tgDJgY3syTQPgvnPMyrA7+7KjPqPQ1ZQ==} + peerDependencies: + react-native: '>= 0.60' + dependencies: + react-native: 0.73.6(@babel/core@7.23.9)(@babel/preset-env@7.23.9)(react@18.2.0) + dev: false + /react-native-css-interop@0.0.36(@babel/core@7.23.9)(react-native-reanimated@3.6.3)(react-native-safe-area-context@4.8.2)(react-native-svg@14.1.0)(react-native@0.73.6)(react@18.2.0)(tailwindcss@3.3.5): resolution: {integrity: sha512-ZWoKQlq6XrI5DB4BdPk5ABvJQsX7zls1SQYWuYXOQB8u5QE0KH3OfOGAGRZPekTjgkhjqGO4Bf8G2JTSWAYMSg==} engines: {node: '>=18'}