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/projects/ProjectList.js

78 lines
1.8 KiB
JavaScript
Raw Normal View History

2016-02-21 12:05:14 +00:00
import React from 'react-native';
import GiftedListView from 'react-native-gifted-listview';
2016-02-21 12:05:14 +00:00
import ProjectItem from './ProjectItem';
import { getProjects, getUserDetails } from '../../api/CircleCI';
import loaderHandler from 'react-native-busy-indicator/LoaderHandler';
2016-02-21 12:05:14 +00:00
2016-02-23 23:12:32 +00:00
const {
2016-02-21 12:05:14 +00:00
StyleSheet,
View
2016-02-21 12:05:14 +00:00
} = React;
2016-02-23 23:12:32 +00:00
const styles = StyleSheet.create({
listView: {
2016-02-21 12:05:14 +00:00
flex: 1,
2016-02-23 23:12:32 +00:00
flexDirection: 'column',
alignItems: 'stretch',
2016-02-21 12:05:14 +00:00
justifyContent: 'center',
flexWrap: 'wrap',
2016-02-24 18:00:13 +00:00
paddingHorizontal: 5
2016-02-21 12:05:14 +00:00
},
});
export default class ProjectList extends React.Component {
constructor(props) {
super(props);
this.state = {
userDetails: false,
2016-02-21 12:05:14 +00:00
};
this.renderRow = this.renderRow.bind(this);
this._fetch = this._fetch.bind(this);
}
componentDidMount() {
getUserDetails().then(function(userDetails) {
this.setState({ userDetails });
}.bind(this));
2016-02-21 12:05:14 +00:00
}
2016-02-23 23:12:32 +00:00
_sortByDate(projects) {
return projects.sort(function (a, b) {
const keyA = a.username + '/' + a.reponame;
const keyB = b.reponame + '/' + b.username;
if (keyA < keyB) { return -1; }
if (keyA > keyB) { return 1; }
return 0;
}.bind(this));
}
2016-02-21 12:05:14 +00:00
renderRow(project) {
return <ProjectItem project={project} userDetails={this.state.userDetails} nav={this.props.nav} />;
}
_fetch(page, callback, options) {
getProjects().then(function (projects) {
loaderHandler.hideLoader();
callback(projects);
});
2016-02-21 12:05:14 +00:00
}
render() {
if (!this.state.userDetails) {
return <View />;
}
2016-02-21 12:05:14 +00:00
return (
<View style={styles.listView}>
<GiftedListView
rowView={this.renderRow}
firstLoader={true}
refreshable={true}
pagination={false}
onFetch={this._fetch} />
</View>
2016-02-21 12:05:14 +00:00
);
}
};