-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
136 lines (124 loc) · 3.93 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
import React, { useState, useEffect } from 'react';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import ProfileScreen from './screens/ProfileScreen';
import MapScreen from './screens/MapScreen';
import AddFriendsScreen from './screens/AddFriendsScreen';
import WelcomeScreen from './screens/welcome';
import SignupScreen from './screens/signup';
import LoginScreen from './screens/login';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { db, auth } from './firebaseConfig';
import { doc, getDoc } from "firebase/firestore";
import Icon from 'react-native-vector-icons/Ionicons';
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
function MyTabs( {route, navigation} ) {
const [isAvailable, setIsAvailable] = useState(false);
const tagsData = [
{ key: 'studying', label: 'Studying', active: false },
{ key: 'eating', label: 'Eating', active: false},
{ key: 'workingOut', label:'Working Out', active: false}
];
const [tags, setTags] = useState(tagsData);
const handleTagToggle = (tagKey) => {
setTags((prevTags) =>
prevTags.map((tag) =>
tag.key === tagKey ? {...tag, active: !tag.active } : tag));
}
const setIsAvailableInTabs = (value) => {
setIsAvailable(value);
};
return (
<Tab.Navigator>
<Tab.Screen
name="Profile"
options= {{
tabBarIcon: ({ color, size }) => (
<Icon name ="person" color={color} size = {size} />
),
}}
>
{props => (
<ProfileScreen
{...props}
isAvailable={isAvailable}
setIsAvailableInTabs={setIsAvailableInTabs}
tags={tags}
setTags={setTags}
handleTagToggle={handleTagToggle}
/>
)}
</Tab.Screen>
<Tab.Screen
name="Map"
options= {{
tabBarIcon: ({ color, size }) => (
<Icon name ="map" color={color} size = {size} />
),
}}
>
{props => (
<MapScreen
{...props}
isAvailable={isAvailable}
setIsAvailableInTabs={setIsAvailableInTabs}
tags={tags}
setTags={setTags}
handleTagToggle={handleTagToggle}
/>
)}
</Tab.Screen>
<Tab.Screen
name="Friends"
options= {{
tabBarIcon: ({ color, size }) => (
<Icon name ="people" color={color} size = {size} />
),
}}
>
{props => (
<AddFriendsScreen/>
)}
</Tab.Screen>
</Tab.Navigator>
);
}
export default function App() {
const [isLoggedIn, setIsLoggedIn] = useState(false);
const [isAvailable, setIsAvailable] = useState(false);
const [name, setName] = useState('');
useEffect(() => {
const fetchUserName = async () => {
const user = auth.currentUser;
if (user) {
const userDocRef = doc(db, "users", user.uid);
const userDocSnap = await getDoc(userDocRef);
if (userDocSnap.data() != undefined) {
const userData = userDocSnap.data();
setName(userData.name);
} else {
console.log("No such document!");
}
}
}
fetchUserName();
});
return (
<NavigationContainer>
<Stack.Navigator>
{!isLoggedIn ? (
<>
<Stack.Screen name="Welcome" component={WelcomeScreen} />
<Stack.Screen name="Signup" component={SignupScreen} />
<Stack.Screen name="Login">
{props => <LoginScreen {...props} onLogin={() => setIsLoggedIn(true)} />}
</Stack.Screen>
</>
) : (
<Stack.Screen name="MyTabs" component={MyTabs} options={{ headerShown: false }} />
)}
</Stack.Navigator>
</NavigationContainer>
);
}