91 lines
2.8 KiB
TypeScript
91 lines
2.8 KiB
TypeScript
import { Stack, useRouter } from 'expo-router';
|
|
import { DatabaseProvider } from '@/hooks/useDatabase';
|
|
import { SettingsProvider } from '@/theme';
|
|
import { FriendsProvider } from '@/hooks/useFriends';
|
|
import { GestureHandlerRootView } from 'react-native-gesture-handler';
|
|
import { StatusBar } from 'expo-status-bar';
|
|
import { UpdateNotifier } from '@/components/UpdateNotifier';
|
|
import { Linking } from 'react-native';
|
|
import { useEffect } from 'react';
|
|
import { requestQuickAddFocus } from '@/utils/quickAddFocus';
|
|
import { registerForPushNotificationsAsync, setupNotificationChannels, addNotificationResponseReceivedListener, removeNotificationSubscription } from '@/services/pushNotifications';
|
|
import * as Notifications from 'expo-notifications';
|
|
import { Platform } from 'react-native';
|
|
|
|
Notifications.setNotificationHandler({
|
|
handleNotification: async () => ({
|
|
shouldShowAlert: true,
|
|
shouldPlaySound: true,
|
|
shouldSetBadge: true,
|
|
shouldShowBanner: true,
|
|
shouldShowList: true,
|
|
}),
|
|
});
|
|
|
|
function RootNavigator() {
|
|
const router = useRouter();
|
|
|
|
useEffect(() => {
|
|
setupNotificationChannels();
|
|
registerForPushNotificationsAsync().catch(() => {});
|
|
|
|
const responseListener = addNotificationResponseReceivedListener((response) => {
|
|
const data = response.notification.request.content.data as Record<string, any> | undefined;
|
|
if (!data) return;
|
|
|
|
switch (data.type) {
|
|
case 'task_reminder':
|
|
case 'task_assignment':
|
|
if (data.taskId) {
|
|
router.push({ pathname: '/task-detail', params: { id: data.taskId } });
|
|
}
|
|
break;
|
|
case 'friend_request':
|
|
if (data.friendshipId) {
|
|
router.push({ pathname: '/(tabs)/settings' });
|
|
}
|
|
break;
|
|
}
|
|
});
|
|
|
|
const handleUrl = (url: string | null) => {
|
|
if (!url || !url.includes('://quick-add')) return;
|
|
router.replace('/(tabs)');
|
|
requestQuickAddFocus();
|
|
};
|
|
|
|
Linking.getInitialURL().then(handleUrl).catch(() => {});
|
|
const subscription = Linking.addEventListener('url', ({ url }) => handleUrl(url));
|
|
|
|
return () => {
|
|
subscription.remove();
|
|
removeNotificationSubscription(responseListener);
|
|
};
|
|
}, [router]);
|
|
|
|
return (
|
|
<GestureHandlerRootView style={{ flex: 1 }}>
|
|
<StatusBar style="light" />
|
|
<Stack screenOptions={{ headerShown: false }}>
|
|
<Stack.Screen name="(tabs)" />
|
|
<Stack.Screen name="add-task" />
|
|
<Stack.Screen name="task-detail" />
|
|
<Stack.Screen name="day-view" />
|
|
</Stack>
|
|
</GestureHandlerRootView>
|
|
);
|
|
}
|
|
|
|
export default function RootLayout() {
|
|
return (
|
|
<SettingsProvider>
|
|
<DatabaseProvider>
|
|
<FriendsProvider>
|
|
<UpdateNotifier />
|
|
<RootNavigator />
|
|
</FriendsProvider>
|
|
</DatabaseProvider>
|
|
</SettingsProvider>
|
|
);
|
|
}
|