[V1.0] Working application, added notifications.

Ready to upload to store.
This commit is contained in:
c-d-p
2025-04-27 00:39:52 +02:00
parent 04d9136b96
commit 62d6b8bdfd
86 changed files with 2250 additions and 240 deletions

View File

@@ -1,5 +1,5 @@
// App.tsx
import React, { useCallback } from 'react'; // Removed useEffect, useState as they are implicitly used by useFonts
import React, { useCallback, useEffect } from 'react'; // Add useEffect
import { Platform, View } from 'react-native';
import { Provider as PaperProvider } from 'react-native-paper';
import { NavigationContainer, DarkTheme as NavigationDarkTheme } from '@react-navigation/native'; // Import NavigationDarkTheme
@@ -8,10 +8,14 @@ import { StatusBar } from 'expo-status-bar';
import * as SplashScreen from 'expo-splash-screen';
import { useFonts } from 'expo-font';
import { AuthProvider } from './src/contexts/AuthContext';
import { AuthProvider, useAuth } from './src/contexts/AuthContext'; // Import useAuth
import RootNavigator from './src/navigation/RootNavigator';
import theme from './src/constants/theme'; // This is the Paper theme
// Removed CombinedDarkTheme import as we'll use NavigationDarkTheme directly for NavigationContainer
import theme from './src/constants/theme';
import {
registerForPushNotificationsAsync,
sendPushTokenToBackend,
setupNotificationHandlers
} from './src/services/notificationService'; // Import notification functions
// Keep the splash screen visible while we fetch resourcesDone, please go ahead with the changes.
SplashScreen.preventAutoHideAsync();
@@ -30,6 +34,43 @@ const navigationTheme = {
},
};
// Wrapper component to handle notification logic after auth state is known
function AppContent() {
const { user } = useAuth(); // Get user state
useEffect(() => {
// Setup notification handlers (listeners)
const cleanupNotificationHandlers = setupNotificationHandlers();
// Register for push notifications only if user is logged in
const registerAndSendToken = async () => {
if (user) { // Only register if logged in
console.log('[App] User logged in, attempting to register for push notifications...');
const token = await registerForPushNotificationsAsync();
if (token) {
console.log('[App] Push token obtained, sending to backend...');
await sendPushTokenToBackend(token);
} else {
console.log('[App] Could not get push token.');
}
} else {
console.log('[App] User not logged in, skipping push notification registration.');
// Optionally: If you need to clear the token on the backend when logged out,
// you might need a separate API call here or handle it server-side based on user activity.
}
};
registerAndSendToken();
// Cleanup listeners on component unmount
return () => {
cleanupNotificationHandlers();
};
}, [user]); // Re-run when user logs in or out
return <RootNavigator />;
}
export default function App() {
const [fontsLoaded, fontError] = useFonts({
'Inter-Regular': require('./src/assets/fonts/Inter-Regular.ttf'),
@@ -63,7 +104,8 @@ export default function App() {
<PaperProvider theme={theme}>
{/* NavigationContainer uses the simplified navigationTheme */}
<NavigationContainer theme={navigationTheme}>
<RootNavigator />
{/* Use AppContent which contains RootNavigator and notification logic */}
<AppContent />
</NavigationContainer>
<StatusBar
style="light" // Assuming dark theme