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

64 lines
1.3 KiB
JavaScript
Raw Normal View History

2016-02-06 12:42:44 +00:00
import React from 'react-native';
2016-02-11 20:45:40 +00:00
import { getProjects } 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
const {
StyleSheet,
Text,
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 = {
projects: ''
};
}
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-21 12:05:14 +00:00
getProjects().then(function (data) {
this.setState({
projects: data
});
}.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 = (
<ProjectList data={this.state.projects} />
);
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>
);
}
};