index.js
2.19 KB
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
import React, { Component } from 'react'
import {
View,
Image
} from 'react-native'
import { connect } from 'react-redux'
import { NavigationActions, StackActions } from 'react-navigation'
import { all, not, identity } from 'ramda'
import { AUTH_TOKEN, CLIENT_SECRET } from '../../constants'
import DefaultIndicator from '../../components/DefaultIndicator'
import { inicializarDatos } from '../../redux/actions/inicio'
import css from './style'
const imgSrc = require('../../assets/logos/jaikuaamina.png')
const allAreFalse = all(not)
const allAreTrue = all(identity)
const goToMain = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'DrawerNavigator' })]
})
const goToUserDetails = StackActions.reset({
index: 0,
actions: [NavigationActions.navigate({ routeName: 'DatosUsuarioNavigator' })]
})
class Splash extends Component {
componentWillMount() {
this.props.inicializarDatos(AUTH_TOKEN, CLIENT_SECRET)
}
render() {
const falsies = [
this.props.formatos.loading,
this.props.soportes.loading,
this.props.tipoRespuestas.loading,
this.props.usuario.loading
]
const truthy = [this.props.auth.authenticated]
const ready = allAreFalse(falsies) && allAreTrue(truthy)
const gotUser = this.props.usuario.guardado
const nextScreen = (ready && gotUser) ? goToMain : goToUserDetails
if (ready) {
setImmediate(() => {
this.props.navigation.dispatch(nextScreen)
})
}
return (
<View style={[css.pane]}>
<View style={[css.imageContainer]}>
<Image
style={css.image}
resizeMode='center'
resizeMethod='resize'
source={imgSrc}
/>
</View>
<DefaultIndicator />
</View>
)
}
}
const mapStateToProps = (state) => ({
auth: state.autenticacion,
token: state.autenticacion.token,
formatos: state.formatos,
soportes: state.soportes,
tipoRespuestas: state.tipoRespuestas,
usuario: state.usuario,
})
const mapDispatchToProps = (dispatch) => ({
inicializarDatos: (token, secret) => dispatch(inicializarDatos(token, secret)),
})
export default connect(mapStateToProps, mapDispatchToProps)(Splash)