ENEI2019-Public/App/app/screens/Home.js

355 lines
9.3 KiB
JavaScript
Raw Normal View History

import React, {Component} from 'react';
2019-02-03 20:54:27 +00:00
2019-02-16 22:16:41 +00:00
import {
Button,
View,
Text,
TouchableOpacity,
FlatList,
ActivityIndicator,
Dimensions,
StyleSheet,
Image,
2019-02-22 23:38:34 +00:00
ImageBackground,
NetInfo
2019-02-16 22:16:41 +00:00
} from 'react-native';
import {Shadow} from 'react-native-shadow'
import Icon from "react-native-vector-icons/Ionicons"
import {
RkButton,
RkTheme
} from 'react-native-ui-kitten';
2019-02-03 20:54:27 +00:00
2019-02-08 18:56:38 +00:00
import {connect} from 'react-redux';
2019-02-03 20:54:27 +00:00
2019-01-31 00:57:24 +00:00
import {bindActionCreators} from 'redux';
2019-01-08 19:09:50 +00:00
2019-02-12 23:07:19 +00:00
import * as Actions from '../store/actions'; //Import your actionss
2019-02-16 22:16:41 +00:00
import ImageOverlay from "react-native-image-overlay";
2019-02-03 20:54:27 +00:00
import {createStore} from 'redux';
2019-02-17 00:46:36 +00:00
import PTRView from 'react-native-pull-to-refresh';
2019-01-30 14:32:25 +00:00
import {Provider} from 'react-redux'
2019-02-16 22:16:41 +00:00
import { ScrollView } from 'react-native-gesture-handler';
const SCREEN_HEIGHT = Dimensions.get("window").height;
const SCREEN_WIDTH = Dimensions.get("window").width;
import {Card, Divider} from 'react-native-elements'
import RNMaterialShadows from 'react-native-material-shadows';
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
class Home extends Component {
2019-02-17 00:46:36 +00:00
_refresh() {
return new Promise((resolve) => {
setTimeout(()=>{resolve()}, 2000)
});
}
_callApi(){
this.props.getUserInfo(this.props.token);
}
2019-01-31 00:46:49 +00:00
constructor(props) {
2019-02-08 14:23:56 +00:00
2019-01-31 00:46:49 +00:00
super(props);
2019-01-30 14:32:25 +00:00
2019-01-31 00:46:49 +00:00
this.state = {
2019-02-08 18:56:38 +00:00
token: {valid: false},
logged: true,
onHold: true,
user: {Name: ''}
2019-01-31 00:46:49 +00:00
};
2019-01-30 14:32:25 +00:00
}
2019-02-22 23:38:34 +00:00
handleConnectivityChange = () => {
console.log("asdasdasdasdasd");
}
2019-01-31 00:46:49 +00:00
componentDidMount() {
2019-02-22 23:38:34 +00:00
NetInfo.isConnected.addEventListener('connectionChange', this.handleConnectivityChange);
2019-01-30 14:32:25 +00:00
2019-02-03 20:54:27 +00:00
this.props.hold();
2019-01-31 00:46:49 +00:00
//this.props.logoutUser();
2019-02-08 14:23:56 +00:00
2019-02-03 20:54:27 +00:00
//console.log(this.props.token);
2019-02-08 18:56:38 +00:00
2019-02-03 20:54:27 +00:00
this.props.getUserInfo(this.props.token);
2019-01-30 14:32:25 +00:00
2019-02-08 18:56:38 +00:00
2019-02-03 20:54:27 +00:00
//console.log('logged:'+this.props.logged);
2019-02-05 15:47:19 +00:00
//console.log(th2is.props)
2019-01-08 19:09:50 +00:00
2019-02-11 19:47:52 +00:00
2019-02-08 18:56:38 +00:00
2019-01-31 00:46:49 +00:00
}
2019-02-22 23:38:34 +00:00
componentWillUnmount() {
NetInfo.isConnected.removeEventListener('connectionChange', this.handleConnectivityChange);
}
2019-01-08 19:09:50 +00:00
2019-02-08 14:23:56 +00:00
bClick() {
//this.props.logoutUser();
2019-02-08 18:56:38 +00:00
let a = {};
// this.setState({ user: this.props.user });
// console.log(this.props.user)
//
2019-02-06 23:24:00 +00:00
2019-01-31 00:46:49 +00:00
//var navigate = this.props.navigation.navigate
}
2019-02-17 00:46:36 +00:00
_update=()=>{
if(this.props.token!= undefined)
this.props.getUserInfo(this.props.token);
}
2019-02-16 22:16:41 +00:00
2019-01-08 19:09:50 +00:00
render() {
2019-01-31 00:46:49 +00:00
2019-02-08 18:56:38 +00:00
const {navigate} = this.props.navigation;
if (this.props.onHold) {
2019-01-31 00:46:49 +00:00
return (
2019-02-03 20:54:27 +00:00
<View>
<Text>lollsss {this.props.onHold}</Text>
2019-02-08 18:56:38 +00:00
<ActivityIndicator size="large" color="#0000ff"/>
2019-02-03 20:54:27 +00:00
</View>
2019-02-08 18:56:38 +00:00
)
2019-02-03 20:54:27 +00:00
}
2019-02-08 18:56:38 +00:00
if (this.props.logged) {
2019-01-31 00:46:49 +00:00
2019-02-03 20:54:27 +00:00
return (
2019-02-17 00:46:36 +00:00
<PTRView onRefresh={this._update} >
2019-02-16 22:16:41 +00:00
<ScrollView style={{backgroundColor:'#eeeeee'}}>
2019-02-08 14:37:45 +00:00
<View>
2019-02-16 22:16:41 +00:00
<ImageBackground
opacity={0.9}
source={require('../assets/img/bg_3.jpg')}
style={{
width: '100%',
// marginTop:150,
backgroundColor: 'rgba(255,255,255,1)' ,
}
}>
2019-02-17 00:46:36 +00:00
2019-02-16 22:16:41 +00:00
<View style={styles.homeHeader}>
<View style={styles.userImageContainer}>
<Image style={styles.userImage} source={{uri: 'https://i.imgur.com/XXJ7LxV.jpg'}}/>
</View>
<Text style={styles.userText}>{this.props.user.Name}</Text>
<Text style={styles.userTextSub}>{this.props.user.Company}</Text>
2019-02-17 00:46:36 +00:00
2019-02-16 22:16:41 +00:00
</View>
</ImageBackground>
2019-02-18 19:55:53 +00:00
<View style={styles.userStats}>
<Text style={styles.userStatsTitle}>O meu saldo:</Text>
<View style={styles.userStatsBox}>
<View style={styles.userBox}>
<Icon name="ios-beer" style={styles.userStatsBoxIcon} size={50}/>
<Text style={styles.userBoxText}>0 Fino(s)</Text>
</View>
<View style={styles.userBox}>
<Icon name="ios-beer" style={styles.userStatsBoxIcon} size={50}/>
<Text style={styles.userBoxText}>0 Fino(s)</Text>
</View>
<View style={styles.userBox}>
<Icon name="ios-beer" style={styles.userStatsBoxIcon} size={50}/>
<Text style={styles.userBoxText}>0 Fino(s)</Text>
</View>
</View>
</View>
2019-02-16 22:16:41 +00:00
<View style={styles.userBio}>
<View style={styles.userBioRow}>
<Icon name="ios-laptop" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioText}>{this.props.user.Job}</Text>
</View>
<Divider style={{ backgroundColor: 'black' }} />
<View style={styles.userBioRow}>
<Icon name="ios-mail" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioText}>{this.props.user.Email}</Text>
</View>
<Divider style={{ backgroundColor: 'black' }} />
<View style={styles.userBioRow}>
<Icon name="ios-phone-portrait" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioText}>{this.props.user.Mobile}</Text>
</View>
<Divider style={{ backgroundColor: 'black' }} />
<View style={styles.userBioRow}>
<Icon name="ios-map" style={styles.userBioLogo} size={25}/>
<Text style={styles.userBioText}>{this.props.user.Address}, {this.props.user.City}</Text>
</View>
<Divider style={{ backgroundColor: 'black' }} />
<View style={styles.userBioRow}>
<Icon name="ios-person" style={styles.userBioLogo} size={25}/>
<TouchableOpacity><Text style={styles.userCurriculum}>O meu Curriculo</Text></TouchableOpacity>
</View>
</View>
2019-02-18 19:55:53 +00:00
2019-02-17 00:46:36 +00:00
2019-02-16 22:16:41 +00:00
2019-01-31 00:46:49 +00:00
</View>
2019-02-16 22:16:41 +00:00
</ScrollView>
2019-02-17 00:46:36 +00:00
</PTRView>
2019-01-31 00:46:49 +00:00
);
}
2019-02-08 14:23:56 +00:00
else {
2019-01-31 00:46:49 +00:00
return (
2019-02-08 14:23:56 +00:00
<View>
<Text>sem permissões para aceder aqui</Text>
2019-01-31 00:46:49 +00:00
</View>
);
}
2019-02-08 14:23:56 +00:00
2019-01-31 00:46:49 +00:00
}
2019-02-08 14:23:56 +00:00
2019-02-16 22:16:41 +00:00
}
2019-02-16 22:16:41 +00:00
const styles = StyleSheet.create({
2019-02-17 00:46:36 +00:00
userBoxText:{
color:'white',
fontWeight:'bold'
},
userStatsBoxIcon:{
color:'white'
},
userStatsBox:{
flex:1,
flexDirection:'row'
},
userBox:{
alignItems:'center',
justifyContent:'center',
width:'33%',
},
2019-02-16 22:16:41 +00:00
userCurriculum:{
paddingTop:5,
color:'red',
fontWeight:'bold',
fontSize:15
},
userBioRow:{
flex:1,
flexDirection:'row',
padding:10,
},
userBioText:{
},
userBioLogo:{
marginLeft: SCREEN_WIDTH*0.05,
width: SCREEN_WIDTH*0.15,
},
userTextSub:{
backgroundColor: 'rgba(0,0,0,0.7)' ,
color:'white',
},
userText:{
backgroundColor: 'rgba(0,0,0,0.7)' ,
color:'white',
fontWeight:'bold',
fontSize:20,
},
homeHeader:{
flex:1,
height: SCREEN_HEIGHT*0.3,
justifyContent: 'center',
alignItems:'center' ,
},
userImage:{
width:110,
height:110,
borderWidth: 1,
borderRadius: 5,
borderWidth:2,
borderColor: 'white',
},
userBio:{
flex:1,
padding:10,
margin:9,
backgroundColor:'white',
// height: SCREEN_HEIGHT*0.20,
color:'black',
borderRadius:5,
},
userStats:{
backgroundColor:'#CC1A17',
height: SCREEN_HEIGHT*0.2,
padding:10,
2019-02-18 19:55:53 +00:00
margin:10,
2019-02-16 22:16:41 +00:00
borderRadius:5,
2019-02-18 19:55:53 +00:00
marginTop:10,
marginBottom:0
2019-02-17 00:46:36 +00:00
},
userStatsTitle:{
color:'white',
fontSize:17,
fontWeight:'bold',
padding:1
2019-02-16 22:16:41 +00:00
},
userImageContainer:{
alignSelf: 'center',
// transform: [{ rotate: '-15deg'}],
2019-01-08 19:09:50 +00:00
}
2019-01-31 00:46:49 +00:00
2019-02-16 22:16:41 +00:00
});
2019-01-31 00:46:49 +00:00
function mapStateToProps(state, props) {
2019-02-08 14:23:56 +00:00
2019-01-31 00:46:49 +00:00
return {
token: state.apiReducer.token,
2019-02-03 20:54:27 +00:00
user: state.apiReducer.user,
2019-02-08 18:56:38 +00:00
logged: state.apiReducer.logged
2019-02-08 14:23:56 +00:00
2019-01-31 00:46:49 +00:00
}
}
function mapDispatchToProps(dispatch) {
return bindActionCreators(Actions, dispatch);
}
export default connect(mapStateToProps, mapDispatchToProps)(Home);