-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathApp.tsx
163 lines (145 loc) · 4.59 KB
/
App.tsx
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
import React from "react";
import Ionicons from "@expo/vector-icons/Ionicons";
import { NavigationContainer } from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import { createBottomTabNavigator } from "@react-navigation/bottom-tabs";
import { NativeBaseProvider, extendTheme } from "native-base";
import { SSRProvider } from "react-aria";
import { getAuth } from "firebase/auth";
import { doc, getDoc, getDocs, collection } from "firebase/firestore";
import SignInScreen from "./screens/auth/signInScreen";
import #Screen from "./screens/auth/#Screen";
import HomeScreen from "./screens/home";
import SettingsScreen from "./screens/settings";
import PersonalInformationScreen from "./screens/settings/personalInformation";
import CreatePostsScreen from "./screens/home/createPosts";
import useAppStore from "./store/useAppStore";
import { db } from "./firebase/firebaseConfig";
import { IPost, IUser } from "./utils/interfaces";
const Stack = createNativeStackNavigator();
const Tab = createBottomTabNavigator();
const theme = extendTheme({
fontConfig: {
Inter: {
100: {
normal: "Inter_100Thin",
},
200: {
normal: "Inter_200ExtraLight",
},
300: {
normal: "Inter_300Light",
},
400: {
normal: "Inter_400Regular",
},
500: {
normal: "Inter_500Medium",
},
600: {
normal: "Inter_600SemiBold",
},
700: {
normal: "Inter_700Bold",
},
800: {
normal: "Inter_800ExtraBold",
},
900: {
normal: "Inter_900Black",
},
},
fonts: {
heading: "Inter",
body: "Inter",
mono: "Inter",
},
},
});
export function SettingsStackNavigator() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="SettingsScreen" component={SettingsScreen} />
<Stack.Screen
name="PersonalInformationScreen"
component={PersonalInformationScreen}
/>
</Stack.Navigator>
);
}
export function AuthStackNavigator() {
return (
<Stack.Navigator screenOptions={{ headerShown: false }}>
<Stack.Screen name="SignInScreen" component={SignInScreen} />
<Stack.Screen name="#Sceen" component={#Screen} />
</Stack.Navigator>
);
}
export function TabNavigator() {
return (
<Tab.Navigator
screenOptions={({ route }) => ({
tabBarIcon: ({ focused, color, size }) => {
let iconName;
if (route.name === "HomeScreen") {
iconName = focused ? "home" : "home-outline";
} else if (route.name === "SettingsStackNavigator") {
iconName = focused ? "person" : "person-outline";
} else if (route.name === "CreatePostsScreen") {
iconName = focused ? "add-circle" : "add-circle-outline";
}
// You can return any component that you like here!
return <Ionicons name={iconName} size={size} color={color} />;
},
headerShown: false,
tabBarActiveTintColor: "maroon",
tabBarInactiveTintColor: "gray",
tabBarShowLabel: false,
})}
>
<Tab.Screen name="HomeScreen" component={HomeScreen} />
<Tab.Screen name="CreatePostsScreen" component={CreatePostsScreen} />
<Tab.Screen
name="SettingsStackNavigator"
component={SettingsStackNavigator}
/>
</Tab.Navigator>
);
}
export default function App() {
const userIsSignedIn = useAppStore((state) => state.userIsSignedIn);
const setUserIsSignedIn = useAppStore((state) => state.setUserIsSignedIn);
const setCurrentUser = useAppStore((state) => state.setCurrentUser);
const setPosts = useAppStore((state) => state.setPosts);
const auth = getAuth();
auth.onAuthStateChanged(async (user) => {
if (user) {
const userRef = doc(db, "users", user.uid);
const userData = (await getDoc(userRef).then((res) =>
res.data()
)) as IUser;
getDocs(collection(db, "posts")).then((res) => {
const data = res.docs.map((doc) => doc.data());
setPosts(data as IPost[]);
});
setCurrentUser({ ...userData });
setUserIsSignedIn(true);
return;
}
setUserIsSignedIn(false);
});
return (
<SSRProvider>
<NativeBaseProvider theme={theme}>
<NavigationContainer>
{!userIsSignedIn ? (
// No token found, user isn't signed in
<AuthStackNavigator />
) : (
<TabNavigator />
)}
</NavigationContainer>
</NativeBaseProvider>
</SSRProvider>
);
}