-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
127 lines (111 loc) · 3.84 KB
/
App.js
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { StatusBar } from 'expo-status-bar';
import { Platform, StyleSheet, Text, View } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { Provider, useSelector } from 'react-redux';
import { store, persistor } from './src/store';
import SessionsScreen from './src/scenes/SessionsScreen';
import StartSessionScreen from './src/scenes/session/StartSessionScreen';
import MidSessionScreen from './src/scenes/session/MidSessionScreen';
import { PersistGate } from 'redux-persist/integration/react';
import * as Linking from 'expo-linking';
import * as Notifications from 'expo-notifications';
import { useEffect } from 'react';
import { allowsNotificationsAsync } from './src/util/notify';
import { selectSessions, selectCurrentSession, SessionsState } from './src/store/reducers/sessionsSlice';
import EndSessionScreen from './src/scenes/session/EndSessionScreen';
import HistoryScreen from './src/scenes/history/HistoryScreen';
import PastSessionScreen from './src/scenes/history/PastSessionScreen';
const prefix = Linking.createURL('/');
const SessionStack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const Stack = createNativeStackNavigator();
Notifications.setNotificationHandler({
handleNotification: async () => {
console.log("Notification received")
return {
shouldShowAlert: false,
shouldPlaySound: false,
shouldSetBadge: false,
}},
});
function History() {
return (
<Stack.Navigator>
<Stack.Screen name="Overview" component={HistoryScreen} options={{ headerShown: false }} />
<Stack.Screen name="Past Session" component={PastSessionScreen} options={{ headerShown: false }} />
</Stack.Navigator>
)
}
function SessionScreen() {
var currentSession = useSelector(selectCurrentSession)
if (currentSession) {
if (currentSession.state == SessionsState.Started) {
return (
<MidSessionScreen />
)
} else if (currentSession.state == SessionsState.Ending) {
return (
<EndSessionScreen />
)
}
} else {
return (
<StartSessionScreen />
)
}
}
export default function App() {
const linking = {
prefixes: [prefix],
config: {
screens: {
History: {
path: 'history',
screens: {
"Past Session": 'session/:id',
Overview: 'overview',
}
},
Session: 'session'
},
},
};
useEffect(() => {
const registerNotification = async () => {
if (!await allowsNotificationsAsync()) {
await Notifications.requestPermissionsAsync();
}
if (Platform.OS === 'android') {
await Notifications.setNotificationChannelAsync('default', {
name: 'default',
importance: Notifications.AndroidImportance.MAX,
vibrationPattern: [0, 250, 250, 250],
lightColor: '#FF231F7C',
});
}
Notifications.addNotificationResponseReceivedListener(async (response) => {
console.log(await response.notification.request.content.data);
console.log(await Notifications.getAllScheduledNotificationsAsync());
console.log(await Notifications.getPresentedNotificationsAsync());
Notifications.dismissAllNotificationsAsync();
});
}
registerNotification();
return () => {
}
}, []);
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
<NavigationContainer linking={linking}>
<Tab.Navigator>
<Tab.Screen name="History" component={History} />
<Tab.Screen name="Session" component={SessionScreen} />
</Tab.Navigator>
</NavigationContainer>
</PersistGate>
</Provider>
);
}