-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
58 lines (51 loc) · 1.48 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
import React, { useEffect, useState } from "react";
import {
NativeBaseProvider,
ScrollView,
Heading,
Center,
Text,
} from "native-base";
import * as WebBrowser from 'expo-web-browser';
import { getAuth, onAuthStateChanged } from 'firebase/auth';
import { firebaseApp } from './firebase';
import { AppBar } from "./components/AppBar";
import { Checkout } from "./components/Checkout";
import { ChargeList } from "./components/ChargeList";
WebBrowser.maybeCompleteAuthSession();
const defaultCurrentUser = {
uid: '',
displayName: '',
email: '',
};
export default function App() {
const [currentUser, setCurrentUser] = useState(defaultCurrentUser);
const auth = getAuth(firebaseApp);
useEffect(() => {
// Listen for auth state changes
onAuthStateChanged(auth, (authUser) => {
if (authUser) {
const { uid, displayName, email } = authUser;
const shapedUser = { uid, displayName, email };
setCurrentUser(shapedUser);
} else {
setCurrentUser(defaultCurrentUser);
}
});
}, []);
return (
<NativeBaseProvider>
<AppBar auth={auth} currentUser={currentUser} />
<Center>
<Heading mt="3">Buy Pineapples</Heading>
<Text fontSize="6xl">🍍</Text>
<Checkout currentUser={currentUser} />
{currentUser.uid && (
<ScrollView width="full">
<ChargeList currentUser={currentUser} />
</ScrollView>
)}
</Center>
</NativeBaseProvider>
);
};