-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
104 lines (86 loc) · 2.94 KB
/
App.js
File metadata and controls
104 lines (86 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import React, { useEffect } from 'react';
import { StatusBar, Linking, Platform } from 'react-native';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { NavigationContainer } from '@react-navigation/native';
import FlashMessage from 'react-native-flash-message';
import { Provider, useDispatch, useSelector } from 'react-redux';
import StackNavigator from './src/navigation/StackNavigator';
import { store } from './src/redux/store';
import { supabase } from './src/integrations/supabase/client';
import messaging from '@react-native-firebase/messaging';
import notifee, { EventType } from '@notifee/react-native';
import RingtoneService from './src/notifications/RingtoneService';
import {
setupNotificationChannel,
showIncomingWorkNotification,
} from './src/notifications/notificationService';
import IncomingWorkOverlay from './src/components/IncomingWorkOverlay';
import { clearIncomingWork } from './src/redux/workSlice';
function AppContainer() {
const dispatch = useDispatch();
// Redux state for custom notification UI
const incomingWork = useSelector(
state => state.work?.incomingWork
);
/* NOTIFICATION INIT */
useEffect(() => {
const initNotifications = async () => {
if (Platform.OS === 'android') {
await notifee.requestPermission();
}
// FCM Token (future backend)
const token = await messaging().getToken();
console.log('FCM TOKEN:', token);
await setupNotificationChannel();
// Foreground FCM listener (future use)
messaging().onMessage(async remoteMessage => {
if (remoteMessage.data?.type === 'NEW_WORK') {
await showIncomingWorkNotification(remoteMessage.data);
RingtoneService.startRingtone();
}
});
// Notification action handler
notifee.onForegroundEvent(async ({ type, detail }) => {
if (type === EventType.ACTION_PRESS) {
RingtoneService.stopRingtone?.();
const notificationId = detail.notification?.id;
if (notificationId) {
await notifee.cancelNotification(notificationId);
}
}
});
};
initNotifications();
}, []);
/* UI*/
return (
<SafeAreaProvider>
<StatusBar barStyle="light-content" backgroundColor="#4A72FF" />
<NavigationContainer>
<StackNavigator />
</NavigationContainer>
{/* CUSTOM NOTIFICATION */}
{incomingWork && (
<IncomingWorkOverlay
data={incomingWork}
onAccept={() => {
RingtoneService.stopRingtone?.();
dispatch(clearIncomingWork());
}}
onReject={() => {
RingtoneService.stopRingtone?.();
dispatch(clearIncomingWork());
}}
/>
)}
<FlashMessage position="top" statusBarHeight={15} />
</SafeAreaProvider>
);
}
export default function App() {
return (
<Provider store={store}>
<AppContainer />
</Provider>
);
}