Skip to content

Commit

Permalink
chore: deep link all pages (#3012)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandipndev authored Jan 19, 2024
1 parent a193109 commit 56b2d72
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
21 changes: 10 additions & 11 deletions app/components/push-notification/push-notification.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { useApolloClient } from "@apollo/client"
import { useIsAuthed } from "@app/graphql/is-authed-context"
import {
PeopleStackParamList,
PrimaryStackParamList,
} from "@app/navigation/stack-param-lists"
import { addDeviceToken, hasNotificationPermission } from "@app/utils/notifications"
import messaging, { FirebaseMessagingTypes } from "@react-native-firebase/messaging"
import { useNavigation } from "@react-navigation/native"
import { StackNavigationProp } from "@react-navigation/stack"
import { useLinkTo } from "@react-navigation/native"
import React, { useEffect } from "react"

const circlesNotificationTypes = [
Expand All @@ -24,8 +19,8 @@ const circlesNotificationTypes = [
export const PushNotificationComponent = (): JSX.Element => {
const client = useApolloClient()
const isAuthed = useIsAuthed()
const primaryNavigation = useNavigation<StackNavigationProp<PrimaryStackParamList>>()
const circlesNavigation = useNavigation<StackNavigationProp<PeopleStackParamList>>()

const linkTo = useLinkTo()

useEffect(() => {
const showNotification = (remoteMessage: FirebaseMessagingTypes.RemoteMessage) => {
Expand All @@ -42,8 +37,12 @@ export const PushNotificationComponent = (): JSX.Element => {
typeof notificationType === "string" &&
circlesNotificationTypes.includes(notificationType)
) {
primaryNavigation.navigate("People")
setTimeout(() => circlesNavigation.navigate("circlesDashboard"), 200)
linkTo("/people/circles")
}

const linkToScreen = remoteMessage.data?.linkTo ?? ""
if (typeof linkToScreen === "string") {
linkTo(linkToScreen)
}
}

Expand All @@ -69,7 +68,7 @@ export const PushNotificationComponent = (): JSX.Element => {
})

return unsubscribe
}, [circlesNavigation, primaryNavigation])
}, [linkTo])

useEffect(() => {
;(async () => {
Expand Down
9 changes: 9 additions & 0 deletions app/navigation/navigation-container-wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,22 @@ export const NavigationContainerWrapper: React.FC<React.PropsWithChildren> = ({
screens: {
Home: "home",
People: {
path: "people",
screens: {
circlesDashboard: "circles",
},
},
Earn: "earn",
Map: "map",
},
},
sendBitcoinDestination: ":payment",
receiveBitcoin: "receive",
conversionDetails: "convert",
scanningQRCode: "scan-qr",
transactionDetail: {
path: "transaction/:txid",
},
},
},
getInitialURL: async () => {
Expand Down

0 comments on commit 56b2d72

Please sign in to comment.