Repository navigation
Expand file tree
/
Copy pathApp.js
More file actions
281 lines (262 loc) · 10.1 KB
/
Copy pathApp.js
File metadata and controls
281 lines (262 loc) · 10.1 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
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
import { StatusBar } from "expo-status-bar";
import { Text, View } from "react-native";
import "react-native-gesture-handler";
//Navigation
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { createDrawerNavigator } from "@react-navigation/drawer";
import {
DefaultTheme,
NavigationContainer,
useNavigation,
} from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import Ionicons from "react-native-vector-icons/Ionicons";
import LogOut from "./components/UI/LogOut";
import ProfileCircleSmall from "./components/UI/ProfileCircleSmall";
import LoginScreen from "./screens/AuthScreens/LoginScreen";
import SignupScreen from "./screens/AuthScreens/SignupScreen";
import WelcomeScreen from "./screens/AuthScreens/WelcomeScreen";
import HomeScreen from "./screens/MainScreens/HomeScreen";
import MapScreen from "./screens/MainScreens/MapScreen";
import ProfileScreen from "./screens/MainScreens/ProfileScreen";
import SearchScreen from "./screens/MainScreens/SearchScreen";
import EditProfileScreen from "./screens/SettingsScreens/EditProfileScreen";
// Global Context
import { useContext, useEffect, useLayoutEffect, useState } from "react";
import AuthContextProvider, { AuthContext } from "./store/auth-context";
// Firebase auth
import { getAuth, onAuthStateChanged, signOut } from "firebase/auth";
import MapModal from "./components/EventCreation/MapModal";
import FirstTimeUserScreen from "./screens/AuthScreens/FirstTimeUserScreen";
import EventCreation from "./screens/MainScreens/EventCreation";
import { auth } from "./store/firebase";
// Notification
import registerNNPushToken from "native-notify";
// Async Storage for tracking if we have a first time user
import AsyncStorage from "@react-native-async-storage/async-storage";
import SearchFilter from "./components/Search/SearchFilter";
import MainEventScreen from "./components/UI/HomeScreen/MainEventScreen";
import ParticipantsList from "./components/UI/ParticipantsList";
import EventChat from "./screens/ChatScreens/EventChat";
import ChatScreen from "./screens/MainScreens/ChatScreen";
import UserProfileScreen from "./screens/MainScreens/UserProfileScreen";
import AdminDashboard from "./screens/SettingsScreens/AdminDashboard";
import ManageEventDetails from "./screens/SettingsScreens/AdminScreens/ManageEventDetails";
import ManageEvents from "./screens/SettingsScreens/AdminScreens/ManageEvents";
import ManagePush from "./screens/SettingsScreens/AdminScreens/ManagePush";
import ManagePushAll from "./screens/SettingsScreens/AdminScreens/ManagePushAll";
import ManagePushIndi from "./screens/SettingsScreens/AdminScreens/ManagePushIndi";
import ManageUserDetails from "./screens/SettingsScreens/AdminScreens/ManageUserDetails";
import ManageUsers from "./screens/SettingsScreens/AdminScreens/ManageUsers";
import UserSettings from "./screens/SettingsScreens/UserSettings";
// ----------------------------------------------------------------
// Create React Navigation Navigators
const Stack = createNativeStackNavigator();
const BottomTab = createBottomTabNavigator();
const Drawer = createDrawerNavigator();
// Drawer Navigator for HomeScreen
function DrawerNavigator() {
const user = auth.currentUser;
return (
<Drawer.Navigator
screenOptions={{
headerStyle: {
backgroundColor: "transparent",
borderBottomWidth: 1,
},
headerTitle: "",
drawerActiveTintColor: "#FAA353",
}}
>
<Drawer.Screen
name="Home"
component={HomeScreen}
options={({ navigation }) => ({
headerLeft: (props) => (
<ProfileCircleSmall
{...props}
onPress={() => {
navigation.openDrawer();
}}
/>
),
headerTitle: `Willkommen, ${user.displayName?.split(" ")[0]}!`,
// drawerItemStyle: { height: 0 }, // Hide a Drawer Item from showing inside Drawer
})}
/>
<Drawer.Screen
name="Profil"
component={ProfileScreen}
options={({ route }) => ({
headerRight: (props) => <Text {...props}></Text>,
})}
/>
<Drawer.Screen name="Einstellungen" component={UserSettings} />
{user.email === "admin@admin.com" && (
<Drawer.Screen name="Admin Dashboard" component={AdminDashboard} />
)}
<Drawer.Screen name="Log Out" component={LogOut} />
</Drawer.Navigator>
);
}
// Bottom Navigator Tabs
function BottomTabNavigator() {
return (
<BottomTab.Navigator
screenOptions={({ route }) => ({
headerShown: false,
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === "Home-Drawer") {
iconName = focused ? "home" : "home-outline";
} else if (route.name === "Suche") {
iconName = focused ? "search" : "search-outline";
} else if (route.name === "Karte") {
iconName = focused ? "map" : "map-outline";
} else if (route.name === "Chats") {
iconName = focused
? "chatbubble-ellipses"
: "chatbubble-ellipses-outline";
}
// You can return any component that you like here!
return <Ionicons name={iconName} size={size} color={color} />;
},
tabBarActiveTintColor: "#FAA353",
tabBarInactiveTintColor: "gray",
tabBarStyle: {
borderWidth: 0.5,
borderBottomWidth: 1,
backgroundColor: "white",
borderTopLeftRadius: 30,
borderTopRightRadius: 30,
borderColor: "transparent",
overflow: "hidden",
position: "absolute",
zIndex: 8,
},
})}
>
<BottomTab.Screen
name="Home-Drawer"
component={DrawerNavigator}
options={{ tabBarLabel: "Home" }} // TODO: Connect to something relevant?
/>
<BottomTab.Screen name="Suche" component={SearchScreen} />
<BottomTab.Screen name="Karte" component={MapScreen} />
<BottomTab.Screen
name="Chats"
component={ChatScreen}
options={{ tabBarBadge: 2 }}
/>
</BottomTab.Navigator>
);
}
// Registration & Login Screens
function AuthenticationProcess() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="welcome" component={WelcomeScreen} />
<Stack.Screen name="signup" component={SignupScreen} />
<Stack.Screen name="login" component={LoginScreen} />
</Stack.Navigator>
);
}
// Screens after being authenticated by Firebase
function AuthenticatedStack() {
const navigation = useNavigation();
// Initially the user is NOT a first time user. We set the AsyncStorage Variable to "1", when creating a user (Check SignupScreen.js)
// Check if the data in the AsyncStorage under the key "@first_time_user" is not null, then we have a first time User
async function getFirstimeUser() {
try {
const value = await AsyncStorage.getItem("@first_time_user");
if (value !== null && value !== "0") {
navigation.navigate("firstTimeUser");
}
} catch (error) {
console.log(error);
}
}
// When ever starting the app for the first time, we check if the user is a first time user.
// We store the value we check in a async storage, so it persists after restarting the app (local storage)
useEffect(() => {
getFirstimeUser();
}, []);
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="bottomTabs" component={BottomTabNavigator} />
<Stack.Screen name="firstTimeUser" component={FirstTimeUserScreen} />
<Stack.Screen name="mainEventScreen" component={MainEventScreen} />
<Stack.Screen name="editProfileScreen" component={EditProfileScreen} />
<Stack.Screen name="userProfileScreen" component={UserProfileScreen} />
<Stack.Screen name="manageUsers" component={ManageUsers} />
<Stack.Screen name="manageUserDetails" component={ManageUserDetails} />
<Stack.Screen name="manageEvents" component={ManageEvents} />
<Stack.Screen name="manageEventDetails" component={ManageEventDetails} />
<Stack.Screen name="managePush" component={ManagePush} />
<Stack.Screen name="managePushAll" component={ManagePushAll} />
<Stack.Screen name="managePushIndi" component={ManagePushIndi} />
<Stack.Screen name="eventChat" component={EventChat} />
<Stack.Group screenOptions={{ presentation: "modal" }}>
<Stack.Screen name="eventCreation" component={EventCreation} />
<Stack.Screen name="eventCreationMap" component={MapModal} />
<Stack.Screen name="participants" component={ParticipantsList} />
<Stack.Screen
name="searchFilter"
component={SearchFilter}
options={{
gestureEnabled: false,
fullScreenGestureEnabled: false,
gestureResponseDistance: 0,
gestureDirection: "horizontal",
}}
/>
</Stack.Group>
</Stack.Navigator>
);
}
// Switch between AuthenticationProcess & AuthenticatedStack, if the User is authenticated. This makes it impossible to get to main screens without
// beeing registered.
// Theme Config for Global Background Color
const MyTheme = {
...DefaultTheme,
colors: {
...DefaultTheme.colors,
background: "white",
},
};
function Navigation() {
const authCtx = useContext(AuthContext);
// Authentication
const [user, setUser] = useState(null);
useLayoutEffect(() => {
onAuthStateChanged(auth, (currentUser) => {
if (currentUser) {
setUser(currentUser);
if (currentUser.email === "admin@admin.com") {
authCtx.setAdmin();
}
} else {
// User is signed out
setUser(null);
}
});
}, [auth]);
return (
<NavigationContainer theme={MyTheme}>
{!user && <AuthenticationProcess />}
{user && <AuthenticatedStack />}
</NavigationContainer>
);
}
// Main Execution of the App
export default function App() {
registerNNPushToken(3719, "xT0Bt22NitQhc3dS8WidSr");
return (
<>
<StatusBar style="auto" />
<AuthContextProvider>
<Navigation />
</AuthContextProvider>
</>
);
}