-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
279 lines (260 loc) · 10.3 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
import * as React from "react";
import {
NavigationContainer,
NavigationContainerRefContext,
} from "@react-navigation/native";
import { createNativeStackNavigator } from "@react-navigation/native-stack";
import Signup from "./Screens/Signup";
import Login from "./Screens/Login";
import MyInformation from "./Screens/MyInformation";
import MyGoals from "./Screens/MyGoals";
import WorkoutInProgress from "./Screens/WorkoutInProgress";
import WorkoutFinished1 from "./Screens/WorkoutFinished1";
import WorkoutFinished2 from "./Screens/WorkoutFinished2";
import WorkoutShare from "./Screens/WorkoutShare";
import InputUserInfoStack from "./Stacks/InputUserInfoStack";
import UpdateUserInfoStack from "./Stacks/UpdateUserInfoStack";
import AddRoutineStack from "./Stacks/AddRoutineStack";
import EditRoutine from "./Screens/EditRoutine";
import EditExercise from "./Screens/EditExercise";
import EditCardioExercise from "./Screens/EditCardioExercise";
import AddLift from "./Screens/AddLift";
import DaysList from "./Screens/DaysList";
import MainTabs from "./Stacks/MainTabs";
import AccountSettings from "./Screens/AccountSettings";
import NotificationSettings from "./Screens/NotificationSettings";
import PersonalInfoSettings from "./Screens/PersonalInfoSettings";
import DeleteAccount from "./Screens/DeleteAccount";
import MyStats from "./Screens/MyStats";
import MyStatsWeb from "./Screens/MyStatsWeb";
import ProgressGraphs from "./Screens/ProgressGraphs";
import ProgressGraphsWeb from "./Screens/ProgressGraphsWeb";
import OneRepMaxList from "./Screens/OneRepMaxList";
import EditOneRepMax from "./Screens/EditOneRepMax";
import SharedRoutine from "./Screens/SharedRoutine";
import SharedProfile from "./Screens/SharedProfile";
import SharedProfileStats from "./Screens/SharedProfileStats";
import Tutorial from "./Screens/Tutorial";
import { useState, useEffect } from "react";
import { FIREBASE_AUTH } from "./firebaseConfig";
import { parse, addEventListener } from "expo-linking";
import { AppContextProvider } from "./context/AppContext";
import { InitialScreensProvider } from "./context/InitialScreensContext";
import { CreateRoutineProvider } from "./context/CreateRoutineContext";
import { EditRoutineProvider } from "./context/EditRoutineContext";
const Stack = createNativeStackNavigator();
export default function App() {
const [user, setUser] = useState(null);
const navigationRef = React.useRef();
const isNavigationReady = React.useContext(NavigationContainerRefContext);
useEffect(() => {
if (isNavigationReady) {
navigationRef.current = isNavigationReady.getCurrentNavigationContainer();
}
}, [isNavigationReady]);
useEffect(() => {
FIREBASE_AUTH.onAuthStateChanged((user) => {
if (user) {
setUser(user);
} else {
setUser(null);
}
});
}, []);
useEffect(() => {
addEventListener("url", handleDeepLink);
return () => {};
}, []);
const handleDeepLink = (event) => {
const { queryParams } = parse(event.url);
if (!navigationRef.current || !navigationRef.current.navigate) {
console.log("navigationRef not ready");
return;
}
if (queryParams.resource === "routine" && queryParams.id) {
navigationRef.current.navigate("Shared Routine", {
routineId: queryParams.id,
});
} else if (queryParams.resource === "profile" && queryParams.id) {
navigationRef.current.navigate("Shared Profile", {
profileId: queryParams.id,
});
}
};
return (
<AppContextProvider>
<InitialScreensProvider>
<CreateRoutineProvider>
<EditRoutineProvider>
<NavigationContainer ref={navigationRef}>
<Stack.Navigator>
{user ? (
<Stack.Group>
<Stack.Screen
name="Main Tabs"
component={MainTabs}
options={{ headerShown: false }}
/>
<Stack.Screen
name="User Information"
component={MyInformation}
options={{ headerShown: false }}
/>
<Stack.Screen
name="User Goals"
component={MyGoals}
options={{ headerShown: false }}
/>
<Stack.Screen
name="User Input"
component={InputUserInfoStack}
options={{ headerShown: false }}
/>
<Stack.Screen
name="User Update"
component={UpdateUserInfoStack}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Days List"
component={DaysList}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Add Routine"
component={AddRoutineStack}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Workout In Progress"
component={WorkoutInProgress}
options={{ headerShown: false, gestureEnabled: false }}
/>
<Stack.Screen
name="Workout Finished 1"
component={WorkoutFinished1}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Workout Finished 2"
component={WorkoutFinished2}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Share Workout"
component={WorkoutShare}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Edit Routine"
component={EditRoutine}
options={{ headerShown: false, gestureEnabled: false }}
/>
<Stack.Screen
name="Edit Exercise"
component={EditExercise}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Edit Cardio Exercise"
component={EditCardioExercise}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Add Lift"
component={AddLift}
options={{ headerShown: false }}
/>
<Stack.Screen
name="My Stats"
component={MyStats}
options={{ headerShown: false }}
/>
<Stack.Screen
name="My Stats Web"
component={MyStatsWeb}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Progress Graphs"
component={ProgressGraphs}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Progress Graphs Web"
component={ProgressGraphsWeb}
options={{ headerShown: false }}
/>
<Stack.Screen
name="One Rep Max List"
component={OneRepMaxList}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Edit One Rep Max"
component={EditOneRepMax}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Account Settings"
component={AccountSettings}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Notification Settings"
component={NotificationSettings}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Personal Info Settings"
component={PersonalInfoSettings}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Delete Account"
component={DeleteAccount}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Shared Routine"
component={SharedRoutine}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Shared Profile"
component={SharedProfile}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Shared Profile Stats"
component={SharedProfileStats}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Tutorial"
component={Tutorial}
options={{ headerShown: false }}
/>
</Stack.Group>
) : (
<Stack.Group>
<Stack.Screen
name="Login"
component={Login}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Signup"
component={Signup}
options={{ headerShown: false }}
/>
</Stack.Group>
)}
</Stack.Navigator>
</NavigationContainer>
</EditRoutineProvider>
</CreateRoutineProvider>
</InitialScreensProvider>
</AppContextProvider>
);
}