forked from GACOSTA1988/Hovrtek-Drone-Services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
68 lines (61 loc) · 1.98 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
import React, { useState, useMemo } from "react";
import { AuthContext } from "./context";
import { SplashScreen } from "expo";
import * as firebase from "firebase";
import {
clientNavigation,
pilotNavigation,
renderLogin,
renderLoading,
} from "./appNavigationUtils";
import { Provider } from "react-redux";
import { createStore, applyMiddleware } from "redux";
import ReduxThunk from "redux-thunk";
import reducers from "./reducers/index";
import { StatusBar, Platform } from "react-native";
import Footer from './components/shared/Footer';
SplashScreen.preventAutoHide();
setTimeout(SplashScreen.hide, 3500);
export default () => {
// REDUX STATE
const state = createStore(reducers, {}, applyMiddleware(ReduxThunk));
console.disableYellowBox = true;
// auth stuff - maybe should be elsewhere?
const auth = firebase.auth();
let [ loggedIn, setLoggedIn ] = useState("loading");
let [ userType, setUserType ] = useState(null);
auth.onAuthStateChanged((user) => {
if (user) {
setLoggedIn("true");
setUserType(user.photoURL);
} else {
setLoggedIn("false");
setUserType(null);
}
});
const authContext = useMemo(() => {
return {
updateUser: () => {
const user = firebase.auth().currentUser;
setLoggedIn(true);
setUserType(user.photoURL);
},
};
}, []);
// to-do change "true" to actual boolean true
const isClientLoggedIn = loggedIn === "true" && userType === "C";
const isPilotLoggedIn = loggedIn === "true" && userType === "P";
const isIOS = Platform.OS === "ios";
return (
<Provider store={state}>
{isIOS && <StatusBar backgroundColor="white" barStyle="light-content" />}
<AuthContext.Provider value={authContext}>
{isClientLoggedIn && clientNavigation}
{isPilotLoggedIn && pilotNavigation}
{loggedIn === "false" && renderLogin()}
{loggedIn === "loading" && renderLoading()}
<Footer />
</AuthContext.Provider>
</Provider>
);
};