-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
104 lines (90 loc) 路 2.71 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
import React from 'react'
import { Text, View } from 'react-native'
import { Container, Drawer, Header, Left, Body, Right, Button, Icon, Title } from 'native-base'
import { Font, AppLoading } from 'expo'
import { Navigator } from 'react-navigation'
import firebase from 'firebase'
import { Provider } from 'react-redux'
import { createStore, applyMiddleware } from 'redux'
import Thunk from 'redux-thunk'
import SideBar from './components/SideBar'
import Login from './components/Login'
import Navigation from './components/Navigation'
import Loader from './components/Loader'
import reducers from './reducers/PrescriptionsReducer'
const config = {
apiKey: "AIzaSyDq-SroilBDUM4dZbvz7UqXC-lK6z-95Zo",
authDomain: "my-pills-app.firebaseapp.com",
databaseURL: "https://my-pills-app.firebaseio.com",
projectId: "my-pills-app",
storageBucket: "my-pills-app.appspot.com",
messagingSenderId: "606105974383"
}
const store = createStore(reducers, applyMiddleware(Thunk));
export default class App extends React.Component {
state = {
loggedIn: null,
fontsAreLoaded: false
};
async componentWillMount() {
firebase.initializeApp(config);
await Font.loadAsync({
'Ionicons': require('native-base/Fonts/Ionicons.ttf'),
});
firebase.auth().onAuthStateChanged((user) => {
if (user) {
this.setState({loggedIn: true, fontsAreLoaded: true})
} else {
this.setState({loggedIn: false, fontsAreLoaded: true})
}
})
}
closeDrawer = () => {
this.drawer._root.close()
}
openDrawer = () => {
this.drawer._root.open()
}
renderInitialView() {
switch (this.state.loggedIn && this.state.fontsAreLoaded) {
case true:
return <Navigation />
case false:
return <Login />
default:
return <Loader size="large" />
}
}
render() {
if (!this.state.fontsAreLoaded) {
return <AppLoading />;
}
return (
<Provider store={store}>
<Drawer
ref={(ref) => this.drawer = ref }
type="displace"
content={<SideBar />}
onClose={this.closeDrawer.bind(this)}
onOpen={this.openDrawer.bind(this)}
openDrawerOffset={0.2}>
<Container>
<Header>
<Left>
<Button onPress={() => this.openDrawer()} transparent>
<Icon style={{color: '#8e44ad'}} name='menu' />
</Button>
</Left>
<Body>
<Title style={{color: '#8e44ad'}}>My Pills</Title>
</Body>
<Right>
</Right>
</Header>
{this.renderInitialView()}
</Container>
</Drawer>
</Provider>
);
}
}