From 72ff44c7b6e783c5b3bdf4ba35c4db4921c5dc30 Mon Sep 17 00:00:00 2001 From: StarNumber12046 <64470722+StarNumber12046@users.noreply.github.com> Date: Tue, 17 Sep 2024 16:18:11 +0200 Subject: [PATCH] Okay, this time for real --- app/onboarding.tsx | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/app/onboarding.tsx b/app/onboarding.tsx index 09e47a0..8998426 100644 --- a/app/onboarding.tsx +++ b/app/onboarding.tsx @@ -1,12 +1,13 @@ -import { useState, useEffect, useRef } from "react"; +import { useState, useEffect, useRef, useContext } from "react"; import messaging, { firebase, FirebaseMessagingTypes, } from "@react-native-firebase/messaging"; +import { ProfileContext } from "./_layout"; import { Text, View, Pressable, StyleSheet } from "react-native"; -import * as Notifications from "expo-notifications"; import { router } from "expo-router"; import firebaseConfig from "@/creds"; +import { getMyProfile } from "@/sdk"; if (!firebase.apps.length) { firebase.initializeApp(firebaseConfig); @@ -15,15 +16,6 @@ if (!firebase.apps.length) { } // Initialize Firebase only if it's not initialized -Notifications.setNotificationHandler({ - handleNotification: async () => ({ - shouldShowAlert: true, - shouldPlaySound: true, - shouldSetBadge: true, - priority: Notifications.AndroidNotificationPriority.HIGH, - }), -}); - function handleRegistrationError(errorMessage: string) { alert(errorMessage); throw new Error(errorMessage); @@ -94,7 +86,11 @@ export default function Onboarding() { async function onClick() { const pushTokenString = await registerForPushNotificationsAsync(); - const body = { fcmToken: pushTokenString, region: "europe-west" }; + const userContext = useContext(ProfileContext); + const body = { + fcmToken: pushTokenString, + region: (await getMyProfile(userContext)).region, + }; const res = await fetch("https://rebeal-server.vercel.app/register", { body: JSON.stringify(body),