Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

inital setup for firebase push notifications #64

Merged
merged 4 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/react-native-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:

# Install Node.js dependencies
- name: Install Node.js dependencies
run: npm install
run: yarn
working-directory: VitalTrackApp

- name: Set up google-services.json
Expand Down Expand Up @@ -62,4 +62,4 @@ jobs:
# Build Android APK
- name: Build Android APK
run: ./gradlew assembleDebug
working-directory: VitalTrackApp/android
working-directory: VitalTrackApp/android
51 changes: 32 additions & 19 deletions VitalTrackApp/App.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { NavigationContainer } from '@react-navigation/native';
import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import messaging from '@react-native-firebase/messaging';
import {NavigationContainer} from '@react-navigation/native';
import {createStackNavigator} from '@react-navigation/stack';
import React, {useEffect} from 'react';
import ProtectedRoute from './src/components/ProtectedRoute';
import { AuthProvider, useAuth } from './src/contexts/AuthContext';
import MyTabs from './src/components/navigationTabs'; // Import MyTabs
import {AuthProvider, useAuth} from './src/contexts/AuthContext';
import AnalyticsScreen from './src/screens/Analytics';
import CalendarScreen from './src/screens/Calendar';
import EntriesScreen from './src/screens/Entries';
import HomeScreen from './src/screens/Home';
import LoginScreen from './src/screens/Login';
import SettingsScreen from './src/screens/Settings';
import SignupScreen from './src/screens/Signup';
import AnalyticsScreen from './src/screens/Analytics';
Comment on lines 10 to 13
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why were these screens deleted?

import CalendarScreen from './src/screens/Calendar';
import MedicationsScreen from './src/screens/Medication';
import MyTabs from './src/components/navigationTabs'; // Import MyTabs

const Stack = createStackNavigator();

function AppNavigator() {
const { currentUser, loading } = useAuth();
const {currentUser, loading} = useAuth();

if (loading) {
return null;
Expand All @@ -26,17 +27,14 @@ function AppNavigator() {
<Stack.Screen
name="Signup"
component={SignupScreen}
options={{ headerShown: false }}
options={{headerShown: false}}
/>
<Stack.Screen
name="Login"
component={LoginScreen}
options={{ headerShown: false }}
options={{headerShown: false}}
/>
<Stack.Screen
name="Home"
options={{ headerShown: false }}
>
<Stack.Screen name="Home" options={{headerShown: false}}>
{() => (
<ProtectedRoute>
<MyTabs />
Expand All @@ -47,22 +45,22 @@ function AppNavigator() {
<Stack.Screen
name="Settings"
component={SettingsScreen}
options={{ headerShown: false, tabBarStyle: { display: 'none' } }} // Hide tab bar
options={{headerShown: false, tabBarStyle: {display: 'none'}}} // Hide tab bar
/>
<Stack.Screen
name="Entries"
component={EntriesScreen}
options={{ headerShown: false }}
options={{headerShown: false}}
/>
<Stack.Screen
name="Calendar"
component={CalendarScreen}
options={{ headerShown: false }}
options={{headerShown: false}}
/>
<Stack.Screen
name="Analytics"
component={AnalyticsScreen}
options={{ headerShown: false }}
options={{headerShown: false}}
/>
<Stack.Screen
name="Medication"
Expand All @@ -74,6 +72,21 @@ function AppNavigator() {
}

export default function App() {
async function requestUserPermission() {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;

if (enabled) {
console.log('Authorization status:', authStatus);
}
}

useEffect(() => {
requestUserPermission();
}, []);

return (
<AuthProvider>
<NavigationContainer>
Expand Down
5 changes: 5 additions & 0 deletions VitalTrackApp/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,10 @@ import {AppRegistry} from 'react-native';
import './gesture-handler';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

messaging().setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', remoteMessage);
});

AppRegistry.registerComponent(appName, () => App);
Loading
Loading