2016-02-21 12:05:14 +00:00
|
|
|
import React from 'react-native';
|
|
|
|
|
|
|
|
import ProjectItem from './ProjectItem';
|
|
|
|
|
2016-02-23 23:12:32 +00:00
|
|
|
const {
|
2016-02-21 12:05:14 +00:00
|
|
|
ListView,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView
|
|
|
|
} = 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);
|
|
|
|
const ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
|
2016-02-23 23:12:32 +00:00
|
|
|
const sortedProjects = this._sortByDate(this.props.data);
|
2016-02-21 12:05:14 +00:00
|
|
|
this.state = {
|
2016-02-23 23:12:32 +00:00
|
|
|
dataSource: ds.cloneWithRows(sortedProjects),
|
2016-02-21 12:05:14 +00:00
|
|
|
};
|
|
|
|
this.renderRow = this.renderRow.bind(this);
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-03-11 11:53:55 +00:00
|
|
|
return <ProjectItem project={project} userDetails={this.props.userDetails} nav={this.props.nav} />;
|
2016-02-21 12:05:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<ScrollView>
|
|
|
|
<ListView
|
2016-02-23 23:12:32 +00:00
|
|
|
contentContainerStyle={styles.listView}
|
2016-02-21 12:05:14 +00:00
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={this.renderRow} />
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
};
|