-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
327 lines (294 loc) · 13.3 KB
/
App.js
File metadata and controls
327 lines (294 loc) · 13.3 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
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
import "react-native-gesture-handler"
import { StyleSheet, Text, View, ActivityIndicator, LogBox } from "react-native";
import React, { useEffect, useState } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from "@react-navigation/stack";
import { createMaterialTopTabNavigator } from '@react-navigation/material-top-tabs';
import { MaterialCommunityIcons } from '@expo/vector-icons';
import ChatsScreen from './Screens/ChatsScreen';
import SettingsScreen from "./Screens/SettingsScreen";
import ChatRoomScreen from './Screens/ChatRoomScreen';
import AssignUserScreen from "./Screens/AssignUserScreen"
import StudentContactsScreen from "./Screens/StudentContactsScreen";
import TeacherContactsScreen from "./Screens/TeacherContactsScreen";
import ChatRoomSettingsScreen from "./Screens/ChatRoomSettingsScreen";
import LoginScreen from './Screens/LoginScreen';
import SignUpScreen from "./Screens/SignUpScreen";
import ConfirmSignUp from "./Screens/ConfirmSignUp";
import Amplify, { Auth, API, graphqlOperation } from 'aws-amplify';
import {getUser} from './src/graphql/queries';
import {createUser} from './src/graphql/mutations';
import { withAuthenticator } from 'aws-amplify-react-native'
import { ActionSheetProvider } from "@expo/react-native-action-sheet";
import { SafeAreaProvider } from "react-native-safe-area-context";
import StudentChatRoomSettingsScreen from "./Screens/StudentChatRoomSettingsScreen";
import TeacherAnnouncementScreen from "./Screens/TeacherAnnouncementScreen";
import CreateAnnouncementScreen from "./Screens/CreateAnnouncementScreen";
import UpdateAnnouncementScreen from "./Screens/UpdateAnnouncementScreen";
import GroupRoomHomeScreen from "./Screens/GroupRoomHomeScreen";
import GroupRoomScreen from "./Screens/GroupRoomScreen";
import CreateOrJoinGroupsScreen from "./Screens/CreateOrJoinGroupsScreen";
import JoinGroupScreen from "./Screens/JoinGroupScreen";
import GroupRoomSettingsScreen from "./Screens/GroupRoomSettingsScreen";
import PrivateRoomHomeScreen from "./Screens/PrivateRoomHomeScreen";
import NewPrivateForTeachers from "./Screens/NewPrivateForTeachers";
import NewPrivateForStudents from "./Screens/NewPrivateForStudents";
import PrivateRoomScreen from "./Screens/PrivateRoomScreen";
import CreateGroupScreen from "./Screens/CreateGroupScreen";
import GroupAnnouncementScreen from "./Screens/GroupAnnouncementScreen";
import CreateGroupAnnouncementScreen from "./Screens/CreateGroupAnnouncementScreen";
import UpdateGroupAnnouncementScreen from "./Screens/UpdateGroupAnnouncementScreen";
import ConversationRoom from "./Screens/ConversationRoomScreen";
import GroupRoomConversationRoom from "./Screens/GroupRoomConversationRoomScreen";
import config from './aws-exports'
import DiscoverHomeScreen from "./Screens/DiscoverHomeScreen";
Amplify.configure(config)//ios build doesn't work with configure implemented inside the code because it says aws-exports doens't exist, which is odd. ok nevermind, it was because the file was in gitIgnore and it doesn't send to the build server. Kudos to Kim from the Expo servers for helping me with this!
// Amplify.configure({
// ...awsExports,
// Analytics: {
// disabled: true
// }
// });
// import config from "./aws-exports";
// Amplify.configure(config);
const randomImages = [
"avatardefault_92824.png"
]
LogBox.ignoreAllLogs();
///const Stack = createStackNavigator();
const AuthenticationStack = createStackNavigator();
const AppStack = createStackNavigator();
const GroupAppStack = createStackNavigator();
const PrivateAppStack = createStackNavigator();
const DiscoverAppStack = createStackNavigator();
const Tab = createMaterialTopTabNavigator();
const globalScreenOptions = {
headerStyle: { backgroundColor: "#00BFFF" },
headerTitleStyle: { color: "white" },
headerTintColor: "white",
};
// const AuthenticationNavigator = props => {
// return (
// <AuthenticationStack.Navigator screenOptions={globalScreenOptions}>
// <AuthenticationStack.Screen name="Login">
// {screenProps => (
// <LoginScreen {...screenProps} updateAuthState={props.updateAuthState} />
// )}
// </AuthenticationStack.Screen>
// <AuthenticationStack.Screen name="Sign Up" component={SignUpScreen} />
// <AuthenticationStack.Screen name="Verification" component={ConfirmSignUp}/>
// </AuthenticationStack.Navigator>
// );
// };
// ^^^^^ All login screens when it's ready :)
const AppNavigator = props => {
return (
<AppStack.Navigator screenOptions={globalScreenOptions} >
{/* <AppStack.Screen name="Chats Screen">
{screenProps => (
<ChatsScreen {...screenProps} updateAuthState={props.updateAuthState} />
)}
</AppStack.Screen>
<AppStack.Screen name="Settings">
{screenProps => (
<SettingsScreen {...screenProps} updateAuthState={props.updateAuthState} />
)}
</AppStack.Screen> */}
<AppStack.Screen name='Chats Screen' component={ChatsScreen} />
<AppStack.Screen name='Settings' component={SettingsScreen} />
<AppStack.Screen name='Chat Room' component={ChatRoomScreen} options={({ route }) => ({ title: route.params.name })} />
<AppStack.Screen name='Conversation Room' component={ConversationRoom} options={({ route }) => ({ title: route.params.name })} />
<AppStack.Screen name='Class Settings' component={ChatRoomSettingsScreen}/>
<AppStack.Screen name='Classroom Settings' component={StudentChatRoomSettingsScreen} />
<AppStack.Screen name='Choose Your Role' component={AssignUserScreen} />
<AppStack.Screen name='Join Classes' component={StudentContactsScreen} />
<AppStack.Screen name='Create Classes' component={TeacherContactsScreen} />
<AppStack.Screen name='Announcements' component={TeacherAnnouncementScreen} />
<AppStack.Screen name='Create Announcements' component={CreateAnnouncementScreen} />
<AppStack.Screen name='Update Announcements' component={UpdateAnnouncementScreen} />
</AppStack.Navigator>
);
};
const GroupAppNavigator = props => {
return (
<GroupAppStack.Navigator screenOptions={globalScreenOptions} >
{/* <GroupAppStack.Screen name="Groups Home Screen">
{screenProps => (
<GroupRoomHomeScreen {...screenProps} updateAuthState={props.updateAuthState} />
)}
</GroupAppStack.Screen>
<GroupAppStack.Screen name="Settings">
{screenProps => (
<SettingsScreen {...screenProps} updateAuthState={props.updateAuthState} />
)}
</GroupAppStack.Screen> */}
<GroupAppStack.Screen name="Groups Home Screen" component={GroupRoomHomeScreen} />
{/* <GroupAppStack.Screen name="Settings" component={SettingsScreen} /> */}
<GroupAppStack.Screen name="Group Room" component={GroupRoomScreen} options={({route}) => ({title: route.params.groupRoomName})} />
<GroupAppStack.Screen name="Group Room Conversation Room" component={GroupRoomConversationRoom} options={({route}) => ({title: route.params.groupRoomConversationName})} />
<GroupAppStack.Screen name="Create or Join Groups" component={CreateOrJoinGroupsScreen} />
<GroupAppStack.Screen name="Join a Group" component={JoinGroupScreen} />
<GroupAppStack.Screen name="Create a Group" component={CreateGroupScreen} />
<GroupAppStack.Screen name="Group Settings" component={GroupRoomSettingsScreen} />
<GroupAppStack.Screen name="Group Announcements" component={GroupAnnouncementScreen} />
<GroupAppStack.Screen name="Create Group Announcements" component={CreateGroupAnnouncementScreen} />
<GroupAppStack.Screen name="Update Group Announcements" component={UpdateGroupAnnouncementScreen} />
</GroupAppStack.Navigator>
);
};
const PrivateAppNavigator = props => {
return (
<PrivateAppStack.Navigator screenOptions={globalScreenOptions} >
{/* <PrivateAppStack.Screen name="Private Chat Home Screen">
{screenProps => (
<PrivateRoomHomeScreen {...screenProps} updateAuthState={props.updateAuthState} />
)}
</PrivateAppStack.Screen> */}
<PrivateAppStack.Screen name="Private Chat Home Screen" component={PrivateRoomHomeScreen} />
<PrivateAppStack.Screen name="Teacher Contacts List" component={NewPrivateForTeachers} />
<PrivateAppStack.Screen name="Student Contacts List" component={NewPrivateForStudents} />
<PrivateAppStack.Screen name="Private Chat Room" component={PrivateRoomScreen} options={({route}) => ({title: route.params.name})} />
</PrivateAppStack.Navigator>
)
}
const DiscoverAppNavigator = props => {
return (
<DiscoverAppStack.Navigator screenOptions={globalScreenOptions} >
<DiscoverAppStack.Screen name="Discover Home Screen" component={DiscoverHomeScreen} />
</DiscoverAppStack.Navigator>
)
}
function App() {
// const [isUserLoggedIn, setUserLoggedIn] = useState('initializing');
const getRandomImage = () => {
return randomImages[Math.floor(Math.random() * randomImages.length)]
}
useEffect ( () => {
const fetchUser = async () => {
//get authenticated user from auth
const userInfo = await Auth.currentAuthenticatedUser({bypassCache: true});
if (userInfo) {
// get the user from backend with user SUB from auth; checks if there is an user
const userData = await API.graphql
(graphqlOperation(
getUser,
{ id: userInfo.attributes.sub }
)
)
if (userData.data.getUser) {
console.log("User is registered in my database");
return;
}
const newUser = {
id: userInfo.attributes.sub,
name: userInfo.username,
imageUri: getRandomImage(),
status: 'Online',
role: 'none',
expoPushToken: '',
}
await API.graphql( // using newUser, it makes a new user to the API
graphqlOperation(
createUser,
{input: newUser}
)
)
// if there is no user in DB with the id, then create one
}
}
fetchUser();
}, []); // this fetches user information from the backend
// useEffect(() => {
// checkAuthState();
// }, []);
// async function checkAuthState() {
// try {
// await Auth.currentAuthenticatedUser();
// console.log(' User is signed in');
// setUserLoggedIn('loggedIn');
// } catch (err) {
// console.log(' User is not signed in');
// setUserLoggedIn('loggedOut');
// }
// }
// function updateAuthState(isUserLoggedIn) {
// setUserLoggedIn(isUserLoggedIn);
// }
return (
<ActionSheetProvider>
<NavigationContainer>
{/* {isUserLoggedIn === 'initializing' && <Initializing />} */}
{/* {isUserLoggedIn === 'loggedIn' && (rest of code) */}
<Tab.Navigator
tabBarPosition="bottom"
tabBarOptions={{
inactiveTintColor: "grey",
showIcon: "true",
//showLabel: "false"
style: { backgroundColor: "white", marginBottom: 18 },
activeTintColor: "#00BFFF",
}}
>
<Tab.Screen
name="Chats Screen"
component={AppNavigator}
//updateAuthState={updateAuthState}
options={{
tabBarLabel: "Classes",
tabBarIcon: ({color}) => (
<MaterialCommunityIcons name="google-classroom" color={color} size={24} />
)
}}
/>
<Tab.Screen
name="Groups Home Screen"
component={GroupAppNavigator}
options={{
tabBarLabel: "Groups",
tabBarIcon: ({color}) => (
<MaterialCommunityIcons name="account-group" color={color} size={24} />
)
}}
/>
<Tab.Screen
name="Private Chat Home Screen"
component={PrivateAppNavigator}
options={{
tabBarLabel: "Private",
tabBarIcon: ({color}) => (
<MaterialCommunityIcons name="account" color={color} size={24} />
)
}}
/>
<Tab.Screen
name="Discover Home Screen"
component={DiscoverAppNavigator}
options={{
tabBarLabel: "Discover",
tabBarIcon: ({color}) => (
<MaterialCommunityIcons name="rocket-launch" color={color} size={24} />
)
}}
/>
</Tab.Navigator>
{/* {isUserLoggedIn === 'loggedOut' && (
<AuthenticationNavigator updateAuthState={updateAuthState} />
)} */}
</NavigationContainer>
</ActionSheetProvider>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
});
export default withAuthenticator(App, {
signUpConfig: {
hiddenDefaults: ['phone_number']
}
})
//export default App;