-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·54 lines (48 loc) · 1.52 KB
/
index.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
/**
* @format
*/
disableYellowBox = true
import React, { Component } from 'react'
import { AppRegistry, SafeAreaView, StyleSheet, AsyncStorage } from 'react-native'
import { name as appName } from './app.json'
import { Provider } from 'react-redux'
import NavigatorContainer from './src/navigation/index'
import store from './src/store'
import {
fetchDogNameFromAsyncStorage,
saveArrOfDogsInStore,
fetchArrOfDogsFromDBToAsyncStorage
} from './src/actions/authActions'
import { fetchDogEventsFromDB, fetchCurrentDayDataFromDB } from './src/actions/dbActions'
const styles = StyleSheet.create({
safeAreaStyle: {
flex: 1,
backgroundColor: '#15cda8'
}
})
class Application extends Component {
async componentDidMount() {
const email = await AsyncStorage.getItem('email')
const dogName = await AsyncStorage.getItem('dogName')
let arrOfDogs = await AsyncStorage.getItem('arrOfDogs')
arrOfDogs = JSON.parse(arrOfDogs)
if (email) {
store.dispatch(fetchDogNameFromAsyncStorage())
store.dispatch(fetchDogEventsFromDB(dogName))
store.dispatch(fetchCurrentDayDataFromDB(dogName))
if (arrOfDogs) store.dispatch(saveArrOfDogsInStore(arrOfDogs))
} else if (!arrOfDogs) {
store.dispatch(fetchArrOfDogsFromDBToAsyncStorage(email))
}
}
render() {
return (
<Provider store={store}>
<SafeAreaView style={styles.safeAreaStyle}>
<NavigatorContainer />
</SafeAreaView>
</Provider>
)
}
}
AppRegistry.registerComponent(appName, () => Application)