-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
executable file
·66 lines (60 loc) · 2.05 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
/**
* @module
*/
import { StatusBar } from 'expo-status-bar';
import React, { useState, useEffect } from 'react';
import { StyleSheet, Text, View, Button } from 'react-native';
import "./configs/firebase-init";
import SignInScreen from "./Components/Auth/SignInScreen";
import AsyncStorage from '@react-native-community/async-storage';
import * as firebase from 'firebase';
import 'firebase/firestore';
import keys, { data } from "./configs/KEYS"
import GenericLayout from './Components/GenericLayout/GenericLayout';
/**
* Looks for user if present in localstorage then updates the current user value
* When user logs out this item is removed from local storage as well as firebase
* if user returned is null then it implies user hasn't logged in therefore redirected to sign in screen
* When user logs in it's one instance is also created in local storage as well.
* @param {function} setcurrentUser - setter current user
* @returns {void} - Nothing
*/
function UpdateCurrentUser(setcurrentUser) {
AsyncStorage.getItem(keys.storage.USER).then(value => {
if (value != null)
setcurrentUser(JSON.parse(value));
});
}
/**
* Main App function consist of two statesUnauthorized: in that case redirected to authentication screen/ SigninscreenAuthroized: In that case redirected to home screen
* @returns {View} - React Componnent View
*/
export default function App() {
const [currentUser, setcurrentUser] = useState(null);
useEffect(() => {
//firebase.firestore().collection("homepage").doc("data").set(data);
UpdateCurrentUser(setcurrentUser)
}, [])
return (
<View style={styles.container}>
<StatusBar
animated={true}
barStyle="default"
showHideTransition="none"
hidden={false}
/>
{!currentUser ? <SignInScreen currentUser={currentUser} setcurrentUser={setcurrentUser} /> :
<GenericLayout currentUser={currentUser} setcurrentUser={setcurrentUser} />
}
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
marginTop: "7%",
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});