-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
355 lines (323 loc) · 11.5 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
import React, { useEffect, useState, useContext } from 'react';
import firebase from "firebase/compat/app";
import * as Linking from 'expo-linking';
import * as Notifications from 'expo-notifications';
import FlashMessage from 'react-native-flash-message';
import { AppState, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { Ionicons } from '@expo/vector-icons';
import AppLoading from 'expo-app-loading';
import { Settings } from './Profiles/settings';
import 'react-native-gesture-handler';
import HomeScreen from './CoreScreens/home';
import DetailsScreen from './Events/detailsContainer';
import FriendScreen from './Friends/friendSuggestions';
import CreateScreen from './Events/createEvent';
import ChatScreen from './Chats/userChats';
import ChatSettingsScreen from './Chats/chatSettings';
import PreviewScreen from './Events/previewEvent';
import SubmitScreen from './Events/submitEvent';
import MessageScreen from './Chats/chat';
import LoginScreen from './CoreScreens/login';
import RegisterScreen from './CoreScreens/register';
import ProfileScreen from './Profiles/userProfile';
import FriendProfileScreen from './Profiles/friendProfile';
import EventNotifScreen from './CoreScreens/eventNotifications';
import EventStatScreen from './Notifications/eventStats';
import UserNotifScreen from './CoreScreens/userNotifications';
import FriendList from './Components/Lists/friendList';
import EventList from './Components/Lists/eventList';
import SplashScreen from './CoreScreens/splashScreen';
import GlobalState from './Context/globalState';
import {
useFonts,
OpenSans_300Light,
OpenSans_400Regular,
OpenSans_500Medium,
OpenSans_600SemiBold,
OpenSans_700Bold,
OpenSans_800ExtraBold,
OpenSans_300Light_Italic,
OpenSans_400Regular_Italic,
OpenSans_500Medium_Italic,
OpenSans_600SemiBold_Italic,
OpenSans_700Bold_Italic,
OpenSans_800ExtraBold_Italic,
} from '@expo-google-fonts/open-sans';
import firebaseInit from './Context/firebaseInit';
import Context from './Context/context';
const Stack = createStackNavigator();
const Tab = createBottomTabNavigator();
const TopTab = createMaterialTopTabNavigator();
function HomeStack() {
return (
<Stack.Navigator>
<Stack.Screen
name="Explore"
component={HomeScreen}
/>
<Stack.Screen
name="Details"
component={DetailsScreen}
/>
<Stack.Screen
name="Notifications"
component={UserNotifScreen}
/>
</Stack.Navigator>
)
}
function FriendStack() {
return (
<Stack.Navigator
screenOptions={{ headerBackTitleVisible: false }}
>
<Stack.Screen
name="Friend List"
component={FriendScreen}
/>
<Stack.Screen
name="View Profile"
options={{ headerBackTitle: 'friends' }}
component={FriendProfileScreen}
/>
<Stack.Screen
name="View friends"
options={{ headerBackTitle: 'Back' }}
component={FriendList}
/>
<Stack.Screen
name="View events"
options={{ headerBackTitle: 'Back' }}
component={EventList}
/>
</Stack.Navigator>
)
}
function AddTab() {
return (
<TopTab.Navigator
screenOptions={{
tabBarLabelStyle: { fontSize: 10 },
tabBarIndicatorStyle: { backgroundColor: '#ec632f' },
}}
>
<TopTab.Screen
name="Create Event"
component={CreateScreen}
options={{
headerLeft: () => {
return <></>
},
}}
/>
<TopTab.Screen
name="Manage Events"
component={EventNotifScreen}
/>
</TopTab.Navigator>
)
}
function AddStack() {
return (
<Stack.Navigator screenOptions={{ headerBackTitleVisible: false }}>
<Stack.Screen
name="Create & Manage"
component={AddTab}
options={{ headerLeft: () => (<></>) }}
/>
<Stack.Screen
name="Preview Event"
component={PreviewScreen}
/>
<Stack.Screen
name="Submit Event"
component={SubmitScreen}
/>
<Stack.Screen
name="Event Stats"
component={EventStatScreen}
/>
</Stack.Navigator>
)
}
function ProfileStack() {
return (
<Stack.Navigator
screenOptions={{ headerShown: false, headerBackTitleVisible: false, gestureEnabled: false }}>
<Stack.Screen
name="Profile"
options={{ headerBackTitle: 'Back' }}
component={ProfileScreen}
/>
<Stack.Screen
name="View friends"
options={{ headerBackTitle: 'Back' }}
component={FriendList}
/>
<Stack.Screen
name="View events"
options={{ headerBackTitle: 'Back' }}
component={EventList}
/>
</Stack.Navigator>
)
}
function ChatStack() {
return (
<Stack.Navigator
screenOptions={{
headerBackTitleVisible: false
}}
>
<Stack.Screen
name="Chat List"
component={ChatScreen}
options={{
headerLeft: () => {
return <></>
},
}}
/>
<Stack.Screen
name="Messages"
component={MessageScreen}
options={{ headerTitle: props => <Text>{props.headerTitle}</Text> }}
/>
<Stack.Screen
name="Chat Settings"
component={ChatSettingsScreen}
/>
</Stack.Navigator>
)
}
function MainTab({ navigation, setLoggedIn }) {
const context = useContext(Context)
const handleAppState = newState => {
if (newState === "active") {
context.socket.emit("appOpened", context.id)
context.socket.emit("notificationsUpdated", context.id)
}
}
useEffect(() => {
AppState.addEventListener("change", handleAppState)
// Need to use deprecated method for now because of expo RN version
return () => AppState.removeEventListener("change", handleAppState)
}, [])
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused }) => {
let iconName;
if (route.name === 'Events') {
iconName = focused ? 'compass' : 'compass-outline';
} else if (route.name === 'Friends') {
iconName = focused ? 'ios-search-sharp' : 'ios-search-outline';
} else if (route.name === 'Create') {
iconName = focused ? 'add-circle' : 'add-circle-outline';
} else if (route.name === 'Chats') {
iconName = focused ? 'chatbubbles' : 'chatbubbles-outline';
} else if (route.name === 'Profile') {
iconName = focused ? 'person-circle' : 'person-circle-outline';
}
return <Ionicons name={iconName} size={30} color={focused ? '#ec632f' : 'gray'} />;
},
})}
>
<Tab.Screen name="Events" component={HomeStack} options={{ headerShown: false, tabBarShowLabel: false }} />
<Tab.Screen name="Friends" component={FriendStack} options={{ headerShown: false, tabBarShowLabel: false }} />
<Tab.Screen name="Create" component={AddStack} options={{ headerShown: false, tabBarShowLabel: false }} />
<Tab.Screen name="Chats" component={ChatStack} options={{ headerShown: false, tabBarShowLabel: false }} />
<Tab.Screen name="Profile" component={ProfileStack} options={{
tabBarShowLabel: false,
headerRight: () => <Settings setLoggedIn={setLoggedIn} navigation={navigation} />
}} />
</Tab.Navigator>
);
}
function Authentication() {
return (
<Stack.Navigator
screenOptions={{ headerShown: false, headerBackTitleVisible: false, gestureEnabled: false }}
>
<Stack.Screen name="Splash" component={SplashScreen} />
<Stack.Screen name="Login" component={LoginScreen} />
<Stack.Screen name="Register" component={RegisterScreen} />
<Stack.Screen name="App" component={MainTab} />
</Stack.Navigator>
);
}
function DetermineScreen() {
const context = useContext(Context)
const [loggedIn, setLoggedIn] = useState(false);
const [config, setConfig] = useState({ screens: { Events: { initialRouteName: 'Explore', screens: { Details: 'event/:id' } } } });
const linkConfig = {
prefixes: [Linking.createURL(''), Linking.createURL('/'), 'https://yolocornell.com'],
config,
}
// A test for login stuff: context.removeCreds()
useEffect(() => {
(async () => {
let loginStatus = await context.fetchCreds()
setLoggedIn(await loginStatus)
if (!await loginStatus && context.id !== -1)
setConfig({ screens: { App: { screens: { Events: { initialRouteName: 'Explore', screens: { Details: 'event/:id' } } } } } })
})()
}, [context.id])
useEffect(() => {
if (!loggedIn)
setConfig({ screens: { Events: { initialRouteName: 'Explore', screens: { Details: 'event/:id' } } } })
}, [loggedIn])
return (
<NavigationContainer linking={linkConfig}>
{loggedIn ?
<MainTab setLoggedIn={setLoggedIn} /> :
<Authentication />
}
<FlashMessage position="bottom" />
</NavigationContainer>
)
}
Notifications.setNotificationHandler({
handleNotification: async () => ({
shouldShowAlert: true,
shouldPlaySound: true,
shouldSetBadge: true
})
});
export default function App() {
const notifRes = Notifications.useLastNotificationResponse();
useEffect(() => {
if (notifRes) {
Linking.openURL(notifRes.notification.request.content.data.url)
}
}, [notifRes])
if (!firebase.apps.length) {
firebase.initializeApp(firebaseInit.firebaseConfig)
}
let [fontsLoaded] = useFonts({
OpenSans_300Light,
OpenSans_400Regular,
OpenSans_500Medium,
OpenSans_600SemiBold,
OpenSans_700Bold,
OpenSans_800ExtraBold,
OpenSans_300Light_Italic,
OpenSans_400Regular_Italic,
OpenSans_500Medium_Italic,
OpenSans_600SemiBold_Italic,
OpenSans_700Bold_Italic,
OpenSans_800ExtraBold_Italic,
});
if (!fontsLoaded) {
return <AppLoading />
}
return (
<GlobalState>
<DetermineScreen />
</GlobalState>
);
}