-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
executable file
·123 lines (107 loc) · 4.15 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
import {View, StyleSheet, StatusBar, LogBox, Modal} from 'react-native'
import {Provider} from 'react-redux'
import store from './src/Redux/store';
import Navigation from './src/navigation/navigation';
import HostingNavigation from './src/navigation/hosting_navigation';
import { useState, useEffect } from 'react';
import AuthNavigation from './src/navigation/Auth_navigation';
import '@azure/core-asynciterator-polyfill';
import { Amplify } from 'aws-amplify';
import amplifyconfig from './src/amplifyconfiguration.json'
Amplify.configure(amplifyconfig);
import AuthContextProvider from './src/Context/hostContext'
import AuthUserContextProvider from './src/Context/userContext';
import { DataStore } from 'aws-amplify/datastore';
import { UserAuth, AppStatus } from './src/models';
import { getCurrentUser } from 'aws-amplify/auth'
import {MaterialIcons} from '@expo/vector-icons'
const App = ()=>{
const [userSignInStatus, setUserSignInStatus] = useState(false)
const [userAuth, setUserAuth] = useState(null)
const [Leasing, setLeasing] = useState(null)
const [isUserAuthenticated, setIsUserAuthenticated] = useState(true)
LogBox.ignoreAllLogs(); // Ignores all log notifications
useEffect(()=>{
(async()=>{
try{
const { userId } = await getCurrentUser();
console.log('the authenticated user', userId)
setUserAuth(userId)
}catch(e){
console.log('Error getting current authenticated user : ', e.message )
setIsUserAuthenticated(false)
}
})()
}, [])
const CheckSignInStatus = async ()=>{
try{
const signedIn = await DataStore.query(UserAuth, (u)=> u.sub.eq(userAuth))
console.log('userAuth Obj : ', signedIn)
const signInStatus = signedIn[0].signInStatus
const appScreen = signedIn[0].userAppType
console.log('signedIn : ', signInStatus, 'signInStatus : ', signInStatus)
setUserSignInStatus(signInStatus)
setLeasing(appScreen)
}catch(e){
console.log('Error checking sign in status: ', e)
}
}
useEffect(()=>{
if(!userAuth){
return
}
CheckSignInStatus()
}, [userAuth])
if(!userSignInStatus && isUserAuthenticated){
return(
<Modal visible={true} onRequestClose={()=>{}} presentationStyle={'overFullScreen'}>
<View style={styles.modalContainer}>
<View style={styles.leotIcon}>
<MaterialIcons name="real-estate-agent" size={100} color="white" />
</View>
</View>
</Modal>
)
}
return (
<View style={{flex : 1, paddingTop: userSignInStatus == 'true'? StatusBar.currentHeight : null}}>
{
userSignInStatus == 'true'? <>
{Leasing == AppStatus.USER?
<Provider store={store}>
<AuthUserContextProvider>
<AuthContextProvider>
<Navigation setLeasing={setLeasing} setUserSignInStatus={setUserSignInStatus}/>
</AuthContextProvider>
</AuthUserContextProvider>
</Provider>
:
<Provider store={store}>
<AuthUserContextProvider>
<AuthContextProvider>
<HostingNavigation setLeasing={setLeasing} setUserSignInStatus={setUserSignInStatus}/>
</AuthContextProvider>
</AuthUserContextProvider>
</Provider>
}
</> :
<AuthNavigation setLeasing={setLeasing} setUserSignInStatus={setUserSignInStatus}/>
}
</View>
);
}
export default App
const styles = StyleSheet.create({
modalContainer : {
flex: 1,
backgroundColor:'white',
justifyContent:'center',
alignItems:'center'
},
leotIcon: {
backgroundColor:'#8B0000',
paddingVertical: 10,
paddingHorizontal: 20,
borderRadius: 20
}
})