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

58 lines
1.3 KiB
JavaScript
Raw Normal View History

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>
);
}
};