This repository has been archived on 2023-03-26. You can view files and clone it, but cannot push or open issues or pull requests.
Sphere/app/components/routes/home.js

73 lines
1.6 KiB
JavaScript
Raw Normal View History

2016-02-06 12:42:44 +00:00
import React from 'react-native';
2016-02-23 23:12:32 +00:00
import { getProjects, getUserDetails } from '../../api/CircleCI';
2016-02-21 12:05:14 +00:00
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
import ProjectList from '../projects/ProjectList';
import GlobalStyles from '../../settings/styles';
2016-02-06 12:42:44 +00:00
2016-02-23 23:12:32 +00:00
2016-02-06 12:42:44 +00:00
const {
StyleSheet,
View,
BackAndroid,
} = React;
const styles = StyleSheet.create({
container: {
flex: 1,
2016-02-21 12:05:14 +00:00
backgroundColor: GlobalStyles.get('CIRCLE_BG'),
2016-02-06 12:42:44 +00:00
},
});
export default class Home extends React.Component {
2016-02-11 20:45:40 +00:00
constructor() {
super();
this.state = {
2016-02-23 23:12:32 +00:00
projects: '',
userDetails: ''
2016-02-11 20:45:40 +00:00
};
}
2016-02-06 12:42:44 +00:00
componentWillUnmount() {
BackAndroid.removeEventListener('hardwareBackPress', () => true);
}
componentWillMount() {
BackAndroid.addEventListener('hardwareBackPress', () => true);
2016-02-21 12:05:14 +00:00
loaderHandler.showLoader('Fetching Data');
2016-02-06 12:42:44 +00:00
}
2016-02-11 20:45:40 +00:00
componentDidMount() {
2016-02-23 23:12:32 +00:00
this.props.nav.navigationContext.addListener('didfocus', function () {
this.props.nav.immediatelyResetRouteStack([this.props.currentRoute]);
}.bind(this));
2016-02-21 12:05:14 +00:00
getProjects().then(function (data) {
this.setState({
projects: data
});
}.bind(this));
2016-02-23 23:12:32 +00:00
getUserDetails().then(function (userDetails) {
this.setState({userDetails});
}.bind(this));
2016-02-11 20:45:40 +00:00
}
2016-02-06 12:42:44 +00:00
render() {
2016-02-21 12:05:14 +00:00
let list;
if (this.state.projects) {
list = (
2016-02-23 23:12:32 +00:00
<ProjectList data={this.state.projects} userDetails={this.state.userDetails} />
2016-02-21 12:05:14 +00:00
);
loaderHandler.hideLoader();
} else {
list = ( <View /> );
}
2016-02-06 12:42:44 +00:00
return (
<View style={styles.container}>
2016-02-21 12:05:14 +00:00
{ list }
2016-02-06 12:42:44 +00:00
</View>
);
}
};